JavaScript FAQ
From MoodleDocs
Moodle 2.0
- Why YUI?
- The decision to use Yahoo! User Interface Library was done after a developer poll in 2006. Many core developers and contributors already learned how to use it and it can not be replaced by something else easily. YUI 3 is significantly improved and should help us catch up with other more used frameworks such has JQuery.
- Can I use JQuery in my plugin?
- In theory yes, but you need to integrate it manually with Moodle which may create some unexpected problems.
- Why the global M?
- It is problematic to set up global variables from code loaded through the YUI loader. There were also some function scoping problems.
- Why the strange namespace organisation in M?
- It is easy to tell the namespace from plugin name and vice versa. This allowed us to implement some simple JS module autoloading.
- Why the static init_ methods in JS module?
- It is easy to guess how to use JS code from PHP. This should significantly improve readability of docs generated from the JS code.
- YUI 3 does not implement all YUI2 features
- You can use all YUI 2 modules in Moodle 2.0, simply include it as one of the dependencies in module description or manually via Y.use('yui2-tree', function(Y) { .... });, the prefix yui2- is used to differentiate these from newer modules.
See also