OK, here is a patch that implements a page_requirements_manager class, with unit tests and plenty of inline documentation.
I have not yet rewritten require_js and friends to use it, and then deprecated them. Nor have I changed print_header and friends to get the data from the class. I first want to know that the way I have made this class and its API is sensible.
Draft commit comment:
ajaxlib: MDL-16695 New page_requirements_manager class, soon to replace require_js
This new class does the work that require_js used to do, and more.
It can track a number of different things that may be required to
be output somewhere on the page, including:
- Links to JS files
- Links to CSS files
- Links to YUI libraries (this class knows about the dependancies between the different libs).
- Skip links that go from the top of <body> to various places in the content.
- Calls to JavaScript functions (for example to initialise things)
- Bits of data from PHP that need to be available to JavaScript
- As a special case of that, an easy way to pass language strings to JS.
The new API looks like
$PAGE->requires->css('mod/mymod/styles.css');
$PAGE->requires->js('mod/mymod/script.js');
$PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head();
$PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready();
$PAGE->requires is the canonical instances of this new class.
The commit also includes unit tests.
OK, here is a patch that implements a page_requirements_manager class, with unit tests and plenty of inline documentation.
I have not yet rewritten require_js and friends to use it, and then deprecated them. Nor have I changed print_header and friends to get the data from the class. I first want to know that the way I have made this class and its API is sensible.
Draft commit comment:
ajaxlib:
MDL-16695New page_requirements_manager class, soon to replace require_jsThis new class does the work that require_js used to do, and more.
It can track a number of different things that may be required to
be output somewhere on the page, including:
The new API looks like
$PAGE->requires->css('mod/mymod/styles.css');
$PAGE->requires->js('mod/mymod/script.js');
$PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head();
$PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready();
$PAGE->requires is the canonical instances of this new class.
The commit also includes unit tests.
MDL-16695New page_requirements_manager class, soon to replace require_js This new class does the work that require_js used to do, and more. It can track a number of different things that may be required to be output somewhere on the page, including:- Links to JS files
- Links to CSS files
- Links to YUI libraries (this class knows about the dependancies between the different libs).
- Skip links that go from the top of <body> to various places in the content.
- Calls to JavaScript functions (for example to initialise things)
- Bits of data from PHP that need to be available to JavaScript
- As a special case of that, an easy way to pass language strings to JS.
The new API looks like $PAGE->requires->css('mod/mymod/styles.css'); $PAGE->requires->js('mod/mymod/script.js'); $PAGE->requires->js('mod/mymod/small_but_urgent.js')->in_head(); $PAGE->requires->js_function_call('init_mymod', array($data))->on_dom_ready(); $PAGE->requires is the canonical instances of this new class. The commit also includes unit tests.