From cafe98f394b6d5f0ad8c90eb45cbef6c86f61f1a Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Fri, 26 Jun 2009 05:12:43 +0000 Subject: [PATCH] mod-resource-file MDL-16706 Removed inline JS and replaced with new PAGE methods --- mod/resource/type/file/file.js | 44 ++++++++++++ mod/resource/type/file/localfile.php | 19 +----- mod/resource/type/file/localpath.php | 25 +------ mod/resource/type/file/resource.class.php | 82 ++++++++++------------- 4 files changed, 83 insertions(+), 87 deletions(-) create mode 100644 mod/resource/type/file/file.js diff --git a/mod/resource/type/file/file.js b/mod/resource/type/file/file.js new file mode 100644 index 00000000000..44f40151f1f --- /dev/null +++ b/mod/resource/type/file/file.js @@ -0,0 +1,44 @@ +function local_file_set_value(choose, localpath) { + var txt = document.getElementById('myform').myfile.value; + if (txt.indexOf('/') > -1) { + var mpath = txt.substring(txt.indexOf('/'),txt.length); + } else if (txt.indexOf('\\') > -1) { + var mpath = txt.substring(txt.indexOf('\\'),txt.length); + } else { + window.close(); + return; + } + opener.document.getElementById('').value = localpath+mpath; + window.close(); +} + +function local_path_set_value(txt) { + if (txt.indexOf('/') > -1) { + txt = txt.substring(0,txt.lastIndexOf('/')); + } else if (txt.indexOf('\\') > -1) { + txt = txt.substring(0,txt.lastIndexOf('\\')); + } + document.getElementById('myform').pathname.value = txt; + document.getElementById('myform').submit(); +} + +function resizeEmbeddedHtml(viewportheight) { + //calculate new embedded html height size + objectheight = YAHOO.util.Dom.getViewportHeight() - viewportheight; + + if (objectheight < 200) { + objectheight = 200; + } + //resize the embedded html object + YAHOO.util.Dom.setStyle("embeddedhtml", "height", objectheight+"px"); + YAHOO.util.Dom.setStyle("embeddedhtml", "width", "100%"); +} + +function file_resource_init(viewportheight) { + resizeEmbeddedHtml(); + YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml); +} + +function create_UFO_object(id) { + UFO.create(FO, id); +} \ No newline at end of file diff --git a/mod/resource/type/file/localfile.php b/mod/resource/type/file/localfile.php index 4bb560c5c60..29741beb3a9 100644 --- a/mod/resource/type/file/localfile.php +++ b/mod/resource/type/file/localfile.php @@ -15,30 +15,15 @@ print_simple_box(get_string('localfileinfo', 'resource'), 'center'); + $PAGE->requires->js('mod/resource/type/file/file.js'); ?> - -

+ onClick="return local_file_set_value('', '')">
diff --git a/mod/resource/type/file/localpath.php b/mod/resource/type/file/localpath.php index 31d99455550..37d3705b15f 100644 --- a/mod/resource/type/file/localpath.php +++ b/mod/resource/type/file/localpath.php @@ -9,35 +9,16 @@ if (confirm_sesskey()) { set_user_preference('resource_localpath', $pathname); } - ?> - - requires->js_function_call('window.close')->asap(); exit; } print_header(get_string('localfilechoose', 'resource')); print_simple_box(get_string('localfilepath', 'resource', $CFG->wwwroot.'/user/edit.php?course='.SITEID), 'center'); + $PAGE->requires->js('mod/resource/type/file/file.js'); ?> - -
@@ -46,7 +27,7 @@
+ onClick="return local_path_set_value(document.getElementById('myform').myfile.value)"> diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index 455ff92eed2..fb65c261c04 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -357,11 +357,7 @@ class resource_file extends resource_base { print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); - echo "\n'; + $PAGE->requires->js_function_call('openpopup', Array("/mod/resource/view.php?inpopup=true&id={$cm->id}","resource{$resource->id}",$resource->popup)); if (trim(strip_tags($resource->intro))) { print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); @@ -415,39 +411,21 @@ class resource_file extends resource_base { alt : ' . $fullurl . '

'; } - ///add some javascript in order to fit this object tag into the browser window - echo ' - '; + ///add some javascript in order to fit this object tag into the browser window + $PAGE->requires->js('mod/resource/type/file/file.js'); + $PAGE->requires->js_function_call('file_resource_init', Array($viewportheight)); ///print the intro if (!empty($resource->intro)) { print_simple_box(format_module_intro('resource', $resource, $cm->id), "center"); } - echo ""; + print_footer(); exit; } else { /// display the resource into a frame tag @@ -522,7 +500,6 @@ class resource_file extends resource_base { 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes'; } $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); - $c = htmlentities($c); $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache $cleanurl = addslashes_js($fullurl); @@ -531,14 +508,18 @@ class resource_file extends resource_base { echo '
'; - echo ''. - ''."\n"; + echo ''; + $args = Array(); + $args['movie'] = $CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl; + $args['width'] = 600; + $args['height'] = 70; + $args['majorversion'] = 6; + $args['build'] = 40; + $args['flashvars'] = $c; + $args['quality'] = 'high'; + echo $PAGE->requires->js('mod/resource/type/file/file.js')->asap(); + echo $PAGE->requires->data_for_js('FO', $args)->asap(); + echo $PAGE->requires->js_function_call('create_UFO_object', Array($id))->asap(); echo '