]> git.mjollnir.org Git - moodle.git/commitdiff
mod-resource-file MDL-16706 Removed inline JS and replaced with new PAGE methods
authorsamhemelryk <samhemelryk>
Fri, 26 Jun 2009 05:12:43 +0000 (05:12 +0000)
committersamhemelryk <samhemelryk>
Fri, 26 Jun 2009 05:12:43 +0000 (05:12 +0000)
mod/resource/type/file/file.js [new file with mode: 0644]
mod/resource/type/file/localfile.php
mod/resource/type/file/localpath.php
mod/resource/type/file/resource.class.php

diff --git a/mod/resource/type/file/file.js b/mod/resource/type/file/file.js
new file mode 100644 (file)
index 0000000..44f4015
--- /dev/null
@@ -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('<?php echo $choose ?>').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
index 4bb560c5c605b494436e2e4574b07284516866e9..29741beb3a9484cfa8df9de556740bea895f9c19 100644 (file)
 
     print_simple_box(get_string('localfileinfo', 'resource'), 'center');
 
+    $PAGE->requires->js('mod/resource/type/file/file.js');
     ?>
-    <script type="text/javascript">
-    //<![CDATA[
-    function set_value(txt) {
-        if (txt.indexOf('/') > -1) {
-            path = txt.substring(txt.indexOf('/'),txt.length);
-        } else if (txt.indexOf('\\') > -1) {
-            path = txt.substring(txt.indexOf('\\'),txt.length);
-        } else {
-            window.close();
-        }
-        opener.document.getElementById('<?php echo $choose ?>').value = '<?php p(RESOURCE_LOCALPATH) ?>'+path;
-        window.close();
-    }
-    //]]>
-    </script>
-    
     <br />
     <div class="mdl-align form">
     <form id="myform">
     <fieldset class="invisiblefieldset">
     <input type="file" size="60" name="myfile" /><br />
     <input type="button" value="<?php print_string('localfileselect','resource') ?>" 
-           onClick="return set_value(getElementById('myform').myfile.value)">
+           onClick="return local_file_set_value('<?php echo $choose?>',  '<?php echo p(RESOURCE_LOCALPATH);?>')">
     <input type="button" value="<?php print_string('cancel') ?>" 
            onClick="window.close()">
     </fieldset>
index 31d99455550b263136622b12a526e0445873aad8..37d3705b15f6a47e6dc0ba09caa5e2bc1dfb2cc6 100644 (file)
@@ -9,35 +9,16 @@
         if (confirm_sesskey()) {
             set_user_preference('resource_localpath', $pathname);
         }
-        ?>
-        <script type="text/javascript">
-        //<![CDATA[
-        window.close();
-        //]]>
-        </script>
-        <?php
+        echo $PAGE->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');
 
     ?>
-    <script type="text/javascript">
-    //<![CDATA[
-    function set_value(txt) {
-        if (txt.indexOf('/') > -1) {
-            txt = txt.substring(0,txt.lastIndexOf('/'));
-        } else if (txt.indexOf('\\') > -1) {
-            txt = txt.substring(0,txt.lastIndexOf('\\'));
-        }
-        getElementById('myform').pathname.value = txt;
-        getElementById('myform').submit();
-    }
-    //]]>
-    </script>
-    
     <br />
     <div class="mdl-align form">
     <form id="myform" action="localpath.php" method="post">
@@ -46,7 +27,7 @@
     <input type="hidden" name="pathname" value="" />
     <input type="file" size="60" name="myfile" /><br />
     <input type="button" value="<?php print_string('localfileselect','resource') ?>" 
-           onClick="return set_value(getElementById('myform').myfile.value)">
+           onClick="return local_path_set_value(document.getElementById('myform').myfile.value)">
     <input type="button" value="<?php print_string('cancel') ?>" 
            onClick="window.close()">
     </fieldset>
index 455ff92eed2b6c13cf08b925a1325d25256f1d89..fb65c261c0419eebc0335d9b81cd2efe77c37279 100644 (file)
@@ -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<script type=\"text/javascript\">";
-            echo "\n<!--\n";
-            echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";
-            echo "\n-->\n";
-            echo '</script>';
+            $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 : <a href="' . $fullurl . '">' . $fullurl . '</a>
                           </object></p>';
                 }
-            ///add some javascript in order to fit this object tag into the browser window
-                echo '<script type="text/javascript">
-                         //<![CDATA[
-                         function resizeEmbeddedHtml() {
-                             //calculate new embedded html height size
-                        ';
+
                 if (!empty($resource->intro)) {
-                    echo'    objectheight =  YAHOO.util.Dom.getViewportHeight() - 230;
-                        ';
-                }
-                else {
-                    echo'    objectheight =  YAHOO.util.Dom.getViewportHeight() - 120;
-                        ';
+                    $viewportheight = 230;
+                } else {
+                    $viewportheight = 120;
                 }
-                echo '       //the object tag cannot be smaller than a human readable size
-                             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%");
-                         }
-                         resizeEmbeddedHtml();
-                         YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml);
-                         //]]>
-                      </script>
-                ';
+                ///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 "</body></html>";
+                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 '<div class="resourcecontent resourcemp3">';
 
-                echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'.
-                     '<script type="text/javascript">'."\n".
-                     '//<![CDATA['."\n".
-                       'var FO = { movie:"'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n".
-                         'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n".
-                       'UFO.create(FO, "'.$id.'");'."\n".
-                     '//]]>'."\n".
-                     '</script>'."\n";
+                echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>';
+                $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 '<noscript>';
 
@@ -562,14 +543,19 @@ class resource_file extends resource_base {
 
                 echo '<div class="resourcecontent resourceflv">';
 
-                echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'.
-                     '<script type="text/javascript">'."\n".
-                     '//<![CDATA['."\n".
-                       'var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n".
-                         'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", allowfullscreen:"true", quality: "high" };'."\n".
-                       'UFO.create(FO, "'.$id.'");'."\n".
-                     '//]]>'."\n".
-                     '</script>'."\n";
+                echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>';
+                $args = Array();
+                $args['movie'] = $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl;
+                $args['width'] = 600;
+                $args['height'] = 400;
+                $args['majorversion'] = 6;
+                $args['build'] = 40;
+                $args['allowscriptaccess'] = 'never';
+                $args['allowfullscreen'] = 'true';
+                $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 '<noscript>';