How to create a YUI 3 module: Difference between revisions
From MoodleDocs
(New page: This document explain 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....) |
|||
Line 10: | Line 10: | ||
## the file is in core: declare the file into /lib/outputrequirementslib.php/find_module($component) | ## the file is in core: declare the file into /lib/outputrequirementslib.php/find_module($component) | ||
//example: | //example: | ||
case 'core_rating': | case 'core_rating': | ||
$module = array('name' => 'core_rating', | $module = array('name' => 'core_rating', | ||
'fullpath' => '/rating/module.js', | 'fullpath' => '/rating/module.js', | ||
'requires' => array('node', 'event', 'overlay', 'io', 'json')); | 'requires' => array('node', 'event', 'overlay', 'io', 'json')); | ||
## the file is in a local plugin: the first line of your module should be | ## the file is in a local plugin: the first line of your module should be | ||
M.local_xxx = { | M.local_xxx = { | ||
xxx being your plugin directory name. | xxx being your plugin directory name. | ||
# Write a first module | # Write a first module | ||
M.local_hub={ | M.local_hub={ | ||
Y : null, | Y : null, | ||
Line 34: | Line 34: | ||
this.Y = Y; | this.Y = Y; | ||
}, | }, | ||
} | } | ||
# Call your first modul. It is better if it's in a php renderer script | # Call your first modul. 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 | $this->page->requires->js_init_call('M.local_hub.init'); //or $PAGE->requires->... if it's in not in a renderer | ||
Revision as of 15:24, 17 August 2010
This document explain 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
- Create a module.js file somewhere
- The two way Moodle can load this file are:
- 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'));
- the file is in a local plugin: the first line of your module should be
M.local_xxx = {
xxx being your plugin directory name.
- Write a first module
M.local_hub={
Y : null, transaction : [],
init : function(Y){ alert('hub module initialisation'); this.Y = Y; }, }
- Call your first modul. 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