Skip to content

Commit

Permalink
MDL-21403 hardcoded JS legacy code should not use new $PAGE->requires…
Browse files Browse the repository at this point in the history
…-> api, switching to html_writer instead + improved ufo embedding
  • Loading branch information
skodak committed Jan 26, 2010
1 parent 5668690 commit 10eaeca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
13 changes: 4 additions & 9 deletions filter/mediaplugin/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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].'<span class="mediaplugin mediaplugin_mp3" id="'.$id.'">('.get_string('mp3audio', 'mediaplugin').')</span>'.$jsoutput;

Expand All @@ -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].'<span class="mediaplugin mediaplugin_swf" id="'.$id.'">('.get_string('flashanimation', 'mediaplugin').')</span>'.$jsoutput;

return $output;
Expand All @@ -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].'<span class="mediaplugin mediaplugin_flv" id="'.$id.'">('.get_string('flashvideo', 'mediaplugin').')</span>'.$jsoutput;

Expand Down
7 changes: 4 additions & 3 deletions lib/javascript-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions lib/resourcelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,8 @@ function resourcelib_embed_mp3($fullurl, $title, $clicktoopen) {
</div>
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;
}

Expand Down Expand Up @@ -213,11 +210,8 @@ function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) {
</div>
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;
}

Expand Down
9 changes: 9 additions & 0 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 10eaeca

Please sign in to comment.