douyu3145 2017-06-21 19:04
浏览 86
已采纳

Javascript Moodle

Hi I am fairly new to moodle. I have been trying to test if my Javascript runs but to no avail. Here is what I have:

In /videojs/amd/src I made a test.js file with a simple command

define(['jquery'], function() {
    return {
        init: function() {
            // Put whatever you like here. $ is available
            // to you as normal.
                alert("It changed!!");
        }
    };
});

Then I grunt the file and everything succeed, and made minified. But when I go to the page it doesn't run. Now I read Moodle's Javascript Doc and I see it says

The idea here is that we will run the 'init' function from our (PHP) code to set things up. This is called from PHP like this...

Where do I call this PHP?

  • 写回答

1条回答 默认 最新

  • doutui6644 2017-06-21 19:45
    关注

    Somewhere in the page you are outputting, you need to add a call like this:

    $PAGE->requires->js_call_amd('PLUGINTYPE_videojs/test', 'init);
    

    It's not entirely clear from your example what sort of plugin you are creating, so whichever type you are creating (https://docs.moodle.org/dev/Plugin_types), you need to put it in the appropriate subdirectory for your site (e.g. /mod/videojs, /local/videojs, etc.), then add some sort of PHP script as the entry point for your plugin and call the js_call_amd function from there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题