Note:

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

JavaScript usage guide: Difference between revisions

From MoodleDocs
No edit summary
Line 45: Line 45:


==Deprecated coding style==
==Deprecated coding style==
=Examples=
=Code migration=
=Performance=


=Links=
=Links=
* [[Create_YUI3_Module_For_Moodle]]
* [[Create_YUI3_Module_For_Moodle]]

Revision as of 11:03, 27 January 2010

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

Javascript usage guide
Project state Work in progress
Tracker issue MDL-21240
Discussion n/a, developer chat only
Assignee Petr Škoda (škoďák) + feedback and ideas from Sam and Dongsheng, based on previous work of Nicolas and Tim

Moodle 2.0



Goals

  • standardised usage of Javascript code in Moodle
  • improved performance
  • improve and simplify JS related APIs

API overview

Types of JS code in 1.9:

  • JS scripts linked from page head
  • JS linked and executed from page head
  • inline Javascript
  • global JS variables


Overview of JavaScript usage in 2.0

  • all JS stored in one global M namespace
  • majority of JS logic moved into page footer
  • loading of javascript modules handled by YUI3 loader
  • all plugins support module.js files
  • most JS is initialised through $PAGE->requires->js_init_call()
  • full migration to YUI3, YUI2 modules are loaded on demand only

Sample usage of JavaScript in module

Description of M namespace

Performance improvements

Migration and code upgrade steps

Deprecated coding style

Links