Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

How to create a YUI 3 module

From MoodleDocs
Revision as of 15:23, 17 August 2010 by jerome mouneyrac (talk | contribs) (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....)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

  1. Create a module.js file somewhere
  2. The two way Moodle can load this file are:
    1. the file is in core: declare the file into /lib/outputrequirementslib.php/find_module($component)

[code php] //example: case 'core_rating':

                   $module = array('name'     => 'core_rating',
                                   'fullpath' => '/rating/module.js',
                                   'requires' => array('node', 'event', 'overlay', 'io', 'json'));

[/code]

    1. the file is in a local plugin: the first line of your module should be

[code]

M.local_xxx = {

[/code]

xxx being your plugin directory name.
  1. Write a first module

[code] M.local_hub={

   Y : null,
   transaction : [],
   init : function(Y){
       alert('hub module initialisation');
       this.Y = Y;
   },

} [/code]

  1. Call your first modul. It is better if it's in a php renderer script

[code php] $this->page->requires->js_init_call('M.local_hub.init'); //or $PAGE->requires->... if it's in not in a renderer [/code]