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.

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了