2017-06-21 41 views
0

嗨我是相當新的moodle。我一直在試圖測試我的Javascript是否運行,但無濟於事。以下是我有:Javascript Moodle

在/ videojs/AMD/src目錄我做了一個test.js文件用一個簡單的命令

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

然後我呻吟了文件,一切都獲得成功,並取得了精縮。但是當我進入頁面時,它不會運行。現在我讀Moodle's Javascript Doc,我看到它說

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... 

我在哪裏叫這個PHP?

回答

1

某處在你輸出的頁面,你需要添加一個電話這樣的:

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

這不是從你的例子完全清楚什麼樣的插件,您正在創建的,故取其類型要創建( (例如/ mod/videojs,/ local/videojs等),然後添加一些PHP腳本作爲插件的入口點並調用js_call_amd函數從那裏。

+0

你好! https://docs.moodle.org/dev/Media_players 我加入它在設置功能等故稱(/classes/plugin.php)和 '$ PAGE->所指> js_call_amd('media_videojs /測試','init');' 訣竅。 **謝謝!** –