From 10eaeca808f6baccae67665ee0cdaaad517eae0a Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 26 Jan 2010 10:35:13 +0000 Subject: [PATCH] MDL-21403 hardcoded JS legacy code should not use new $PAGE->requires-> api, switching to html_writer instead + improved ufo embedding --- filter/mediaplugin/filter.php | 13 ++++--------- lib/javascript-static.js | 7 ++++--- lib/resourcelib.php | 14 ++++---------- lib/weblib.php | 9 +++++++++ 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php index ade18ad60e86c..de0af5b27fccc 100644 --- a/filter/mediaplugin/filter.php +++ b/filter/mediaplugin/filter.php @@ -148,9 +148,7 @@ function mediaplugin_filter_mp3_callback($link) { $args['flashvars'] = $c; $args['quality'] = 'high'; - $jsoutput = $PAGE->requires->js('/lib/ufo.js')->asap(); - $jsoutput .= $PAGE->requires->data_for_js('FO', $args)->asap(); - $jsoutput .= $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap(); + $jsoutput = create_ufo_inline($id, $args); $output = $link[0].'('.get_string('mp3audio', 'mediaplugin').')'.$jsoutput; @@ -175,10 +173,9 @@ function mediaplugin_filter_swf_callback($link) { $args['build'] = 40; $args['allowscriptaccess'] = 'never'; $args['quality'] = 'high'; - $jsoutput = $PAGE->requires->js('/lib/ufo.js')->asap(); - $jsoutput .= $PAGE->requires->data_for_js('FO', $args)->asap(); - $jsoutput .= $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap(); + $jsoutput = create_ufo_inline($id, $args); + $output = $link[0].'('.get_string('flashanimation', 'mediaplugin').')'.$jsoutput; return $output; @@ -204,9 +201,7 @@ function mediaplugin_filter_flv_callback($link) { $args['allowscriptaccess'] = 'never'; $args['quality'] = 'high'; $args['allowfullscreen'] = 'true'; - $jsoutput = $PAGE->requires->js('/lib/ufo.js')->asap(); - $jsoutput .= $PAGE->requires->data_for_js('FO', $args)->asap(); - $jsoutput .= $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap(); + $jsoutput = create_ufo_inline($id, $args); $output = $link[0].'('.get_string('flashvideo', 'mediaplugin').')'.$jsoutput; diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 31f453db18c61..d3ad4c7396a56 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -33,6 +33,10 @@ M.util.image_url = function(imagename, component) { return url; }; +M.util.create_UFO_object = function (eid, FO) { + UFO.create(FO, eid); +} + /** * Init a collapsible region, see print_collapsible_region in weblib.php * @param Object YUI3 instance with all libraries loaded @@ -1218,9 +1222,6 @@ function old_onload_focus(formid, controlname) { } } -function create_UFO_object(eid) { - UFO.create(FO, eid); -} function build_querystring(obj) { if (typeof obj !== 'object') { return null; diff --git a/lib/resourcelib.php b/lib/resourcelib.php index 032264a634e97..ac3f4f31649f4 100644 --- a/lib/resourcelib.php +++ b/lib/resourcelib.php @@ -167,11 +167,8 @@ function resourcelib_embed_mp3($fullurl, $title, $clicktoopen) { OET; - $PAGE->requires->yui2_lib('dom'); - $PAGE->requires->js('/lib/ufo.js')->in_head(); - $PAGE->requires->js('/lib/resourcelib.js')->in_head(); - $code .= $PAGE->requires->data_for_js('FO', $ufoargs)->asap(); - $code .= $PAGE->requires->js_function_call('resourcelib_create_UFO_object', array($id))->asap(); + $PAGE->requires->js('/lib/ufo.js'); + $code .= $PAGE->requires->js_function_call('M.util.create_UFO_object', array($id, $ufoargs)); return $code; } @@ -213,11 +210,8 @@ function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) { EOT; - $PAGE->requires->yui2_lib('dom'); - $PAGE->requires->js('/lib/ufo.js')->in_head(); - $PAGE->requires->js('/lib/resourcelib.js')->in_head(); - $code .= $PAGE->requires->data_for_js('FO', $ufoargs)->asap(); - $code .= $PAGE->requires->js_function_call('resourcelib_create_UFO_object', array($id))->asap(); + $PAGE->requires->js('/lib/ufo.js'); + $code .= $PAGE->requires->js_function_call('M.util.create_UFO_object', array($id, $ufoargs)); return $code; } diff --git a/lib/weblib.php b/lib/weblib.php index 03570f5462f32..4cfb708adac49 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3411,3 +3411,12 @@ function print_password_policy() { } return $message; } + +function create_ufo_inline($id, $args) { + global $CFG; + // must not use $PAGE, $THEME, $COURSE etc. because the result is cached! + + $jsoutput = html_writer::script('', $CFG->wwwroot.'/lib/ufo.js'); + $jsoutput .= html_writer::script(js_writer::function_call('M.util.create_UFO_object', array($id, $args))); + return $jsoutput; +} \ No newline at end of file