How to create a YUI 3 module: Difference between revisions
From MoodleDocs
No edit summary |
|||
Line 39: | Line 39: | ||
$this->page->requires->js_init_call('M.local_hub.init'); //or $PAGE->requires->... if it's in not in a renderer | $this->page->requires->js_init_call('M.local_hub.init'); //or $PAGE->requires->... if it's in not in a renderer | ||
You should now have loaded and called your first YUI 3 module in Moodle. | You should now have loaded and called your first YUI 3 module in Moodle. | ||
5. Now to load it with some other YUI modules | |||
$commentjsmodule = array( | |||
'name' => 'local_hub', | |||
'fullpath' => '/local/hub/module.js', | |||
'requires' => array("overlay", "anim", "plugin")); | |||
$this->page->requires->js_init_call('M.local_hub.init', | |||
null, false, $commentjsmodule); |
Revision as of 18:40, 17 August 2010
This document explains how to create a YUI 3 module in Moodle.
The two ways to write a YUI 3 module
- create a static module like /rating/module.js. It is the easiest and quickest way. You choose this way because...
- create a flexible and extendable module like /mod/glossary/yui/autolinker/autolinker.js. It is the hard way. You choose this way because...
The static module
1. Create a module.js file somewhere
2. The two way Moodle can load this file are:
a- the file is in core: declare the file into /lib/outputrequirementslib.php/find_module($component)
//example: case 'core_rating': $module = array('name' => 'core_rating', 'fullpath' => '/rating/module.js', 'requires' => array('node', 'event', 'overlay', 'io', 'json'));
b- the file is in a local plugin: the first line of your module should be
M.local_xxx = {
xxx being your plugin directory name.
3. Write a first module
M.local_hub={ Y : null, transaction : [], init : function(Y){ alert('hub module initialisation'); this.Y = Y; }, }
4. Call this module. It is better if it's in a php renderer script
$this->page->requires->js_init_call('M.local_hub.init'); //or $PAGE->requires->... if it's in not in a renderer
You should now have loaded and called your first YUI 3 module in Moodle.
5. Now to load it with some other YUI modules
$commentjsmodule = array( 'name' => 'local_hub', 'fullpath' => '/local/hub/module.js', 'requires' => array("overlay", "anim", "plugin")); $this->page->requires->js_init_call('M.local_hub.init', null, false, $commentjsmodule);