ajaxlib/require_js: MDL-16693 $PAGE->requires->... deprecates require_js etc.

There is a new implementation of require_js in lib/deprecatedlib.php,
based on $PAGE->requires.

There were a few other recently introduced functions in lib/weblib.php,
namely print_js_call, print_delayed_js_call, print_js_config and
standard_js_config. These have been removed, since they were never in
a stable branch, and all the places that used them have been changed
to use the newer $PAGE->requires->... methods.

get_require_js_code is also gone, and the evil places that were calling
it, even though it is an internal function, have been fixed.

Also, I made some minor improvements to the code I committed yesterday
for MDL-16695.

All that remains is to update all the places in core code that are
still using require_js.

(This commit also fixes the problem where the admin tree would not
start with the right categories expanded.)
This commit is contained in:
tjhunt
2009-06-12 12:13:07 +00:00
parent 151165e3d1
commit cf6155226c
36 changed files with 253 additions and 541 deletions
+35
View File
@@ -1684,3 +1684,38 @@ function table_column($table, $oldfield, $field, $type='integer', $size='10',
function use_html_editor($name='', $editorhidebuttons='', $id='') {
error('use_html_editor() not available anymore');
}
/**
* The old method that was used to include JavaScript libraries.
* Please use $PAGE->requires->js() or $PAGE->requires->yui_lib() instead.
*
* @param mixed $lib The library or libraries to load (a string or array of strings)
* There are three way to specify the library:
* 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui_lib('yahoo')->asap();
* 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
* 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
* 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
*/
function require_js($lib) {
global $CFG, $PAGE;
// Add the lib to the list of libs to be loaded, if it isn't already
// in the list.
if (is_array($lib)) {
foreach($lib as $singlelib) {
require_js($singlelib);
}
return;
}
// TODO uncomment this once we have eliminated the remaining calls to require_js from core.
//debugging('Call to deprecated function require_js. Please use $PAGE->requires->js() ' .
// 'or $PAGE->requires->yui_lib() instead.', DEBUG_DEVELOPER);
if (strpos($lib, 'yui_') === 0) {
echo $PAGE->requires->yui_lib(substr($lib, 4))->asap();
} else if (preg_match('/^https?:/', $lib)) {
echo $PAGE->requires->js(str_replace($CFG->wwwroot, '', $lib))->asap();
} else {
echo $PAGE->requires->js($lib)->asap();
}
}