]> git.mjollnir.org Git - moodle.git/commitdiff
javascript MDL-16673 Removed all removeable uses of CFG->javascript
authorsamhemelryk <samhemelryk>
Tue, 7 Jul 2009 09:09:16 +0000 (09:09 +0000)
committersamhemelryk <samhemelryk>
Tue, 7 Jul 2009 09:09:16 +0000 (09:09 +0000)
In doing this I was able to eliminate the need for javascript.php files, now removed.
I will also be filing several subtasks to clean up the linked to JS files in OUTPUT as well
as all instance of the old style of focusing.

admin/xmldb/index.php
admin/xmldb/javascript.php [deleted file]
lib/javascript-static.js
lib/javascript.php [deleted file]
lib/outputlib.php
lib/setup.php
mod/resource/type/ims/ims.js [new file with mode: 0644]
mod/resource/type/ims/javascript.php [deleted file]
mod/resource/type/ims/preview.php
mod/resource/type/ims/resource.class.php

index 7fea36d80417c0846fb305fde3b84b7f21f1aa10..ffad1bdac45d0ae93d74baa59b5082c5ff22ecf4 100644 (file)
             /// Based on getDoesGenerate()
                 switch ($xmldb_action->getDoesGenerate()) {
                     case ACTION_GENERATE_HTML:
-                    /// Define $CFG->javascript to use our custom javascripts.
-                    /// Save the original one to add it from ours. Global too! :-(
-                        global $standard_javascript;
-                        $standard_javascript = $CFG->javascript;  // Save original javascript file
-                        $CFG->javascript = $CFG->dirroot.'/'.$CFG->admin.'/xmldb/javascript.php';  //Use our custom javascript code
+
+                        $action = optional_param('action', '', PARAM_ALPHAEXT);
+                        $postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
+                    /// If the js exists, load it
+                        if ($action) {
+                            $script = $CFG->admin . '/xmldb/actions/' . $action . '/' . $action . '.js';
+                            $file = $CFG->dirroot . '/' . $script;
+                            if (file_exists($file) && is_readable($file)) {
+                                $PAGE->requires->js($script);
+                            } else if ($postaction) {
+                            /// Try to load the postaction javascript if exists
+                                $script = $CFG->admin . '/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
+                                $file = $CFG->dirroot . '/' . $script;
+                                if (file_exists($file) && is_readable($file)) {
+                                    $PAGE->requires->js($script);
+                                }
+                            }
+                        }
+
                     /// Go with standard admin header
                         admin_externalpage_print_header();
                         print_heading($xmldb_action->getTitle());
diff --git a/admin/xmldb/javascript.php b/admin/xmldb/javascript.php
deleted file mode 100644 (file)
index 483eec1..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php  /// $Id $
-
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// Load XMLDB required Javascript libraries, adding them
-/// before the standard one ($standard_javascript)
-
-    if (!defined('MOODLE_INTERNAL')) {
-        die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
-    }
-
-/// We use this globals to be able to generate the proper JavaScripts
-    global $standard_javascript, $PAGE;
-
-/// Load XMLDB javascript needed to handle some forms
-    $action = optional_param('action', '', PARAM_ALPHAEXT);
-    $postaction = optional_param('postaction', '', PARAM_ALPHAEXT);
-/// If the js exists, load it
-    if ($action) {
-        $script = $CFG->admin . '/xmldb/actions/' . $action . '/' . $action . '.js';
-        $file = $CFG->dirroot . '/' . $script;
-        if (file_exists($file) && is_readable($file)) {
-            $PAGE->requires->js($script);
-        } else if ($postaction) {
-        /// Try to load the postaction javascript if exists
-            $script = $CFG->admin . '/xmldb/actions/' . $postaction . '/' . $postaction . '.js';
-            $file = $CFG->dirroot . '/' . $script;
-            if (file_exists($file) && is_readable($file)) {
-                $PAGE->requires->js($script);
-            }
-        }
-    }
-
-/// Load standard JavaScript
-    include($standard_javascript);
-?>
index dc131488ff1467aef708cec11f989c7d9249cecc..2460edf6a75263b49c583fffdfc7a8f8575e6e54 100644 (file)
@@ -1044,6 +1044,16 @@ function focuscontrol(controlid) {
     }
 }
 
+/**
+ * Transfers keyboard focus to an HTML element based on the old style style of focus
+ * This function should be removed as soon as it is no longer used
+ */
+function old_onload_focus(parentname, controlname) {
+    if (window[parentname]) {
+        window[parentname][controlname].focus();
+    }
+}
+
 function scroll_to_end() {
     window.scrollTo(0, 5000000);
 }
diff --git a/lib/javascript.php b/lib/javascript.php
deleted file mode 100644 (file)
index 5b09887..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Load up any required Javascript libraries
- *
- * @package   moodlecore
- * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
-}
-?>
-
-<!--<style type="text/css">/*<![CDATA[*/ body{behavior:url(<?php echo $CFG->httpswwwroot ?>/lib/csshover.htc);} /*]]>*/</style>-->
-
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/javascript-static.js"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/javascript-mod.php"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/overlib/overlib.js"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/overlib/overlib_cssstyle.js"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/cookies.js"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/ufo.js"></script>
-<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/dropdown.js"></script>
-
-<script type="text/javascript" defer="defer">
-//<![CDATA[
-setTimeout('fix_column_widths()', 20);
-//]]>
-</script>
-<script type="text/javascript">
-//<![CDATA[
-<?php
-if (!empty($focus)) {
-    if(($pos = strpos($focus, '.')) !== false) {
-        //old style focus using form name - no allowed inXHTML Strict
-        $topelement = substr($focus, 0, $pos);
-        echo "addonload(function() { if(document.$topelement) document.$focus.focus(); });\n";
-    } else {
-        //focus element with given id
-        echo "addonload(function() { if(el = document.getElementById('$focus')) el.focus(); });\n";
-    }
-    $focus = false; // Prevent themes from adding it to body tag which breaks addonload(), MDL-10249
-}
-?>
-//]]>
-</script>
index 62db77ab9874f206162913ff9f645626e9b2d2a3..3d4ff1deadbee5813f593f00d50ae0377eb3b5ae 100644 (file)
@@ -1561,16 +1561,30 @@ class moodle_core_renderer extends moodle_renderer_base {
         // Check if a periodic refresh delay has been set and make sure we arn't
         // already meta refreshing
         if ($this->metarefreshtag=='' && $this->page->periodicrefreshdelay!==null) {
-            $metarefesh = '<meta http-equiv="refresh" content="%d;url=%s" />';
-            $output .= sprintf($metarefesh, $this->page->periodicrefreshdelay, $this->page->url->out());
+            $output .= '<meta http-equiv="refresh" content="'.$this->page->periodicrefreshdelay.';url='.$this->page->url->out().'" />';
         }
 
-        // TODO get rid of $CFG->javascript. We should be able to do everything
-        // with $PAGE->requires.
-        ob_start();
-        include($CFG->javascript);
-        $output .= ob_get_contents();
-        ob_end_clean();
+        $this->page->requires->js('lib/javascript-static.js')->in_head();
+        $this->page->requires->js('lib/javascript-mod.php')->in_head();
+        $this->page->requires->js('lib/overlib/overlib.js')->in_head();
+        $this->page->requires->js('lib/overlib/overlib_cssstyle.js')->in_head();
+        $this->page->requires->js('lib/cookies.js')->in_head();
+        $this->page->requires->js('lib/ufo.js')->in_head();
+        $this->page->requires->js('lib/dropdown.js')->in_head();
+        $this->page->requires->js_function_call('setTimeout', Array('fix_column_widths()', 20));
+
+        $focus = $this->page->focuscontrol;
+        if (!empty($focus)) {
+            $pos = strpos($focus, '.');
+            if($pos !== false) {
+                // Old style of focus, bad way to do it
+                debugging('This code is using the old style focus event, Please update this code to focus on an element id', DEBUG_DEVELOPER);
+                $this->page->requires->js_function_call('old_onload_focus', Array(substr($focus, 0, $pos), substr($focus, $pos)));
+            } else {
+                // Focus element with given id
+                $this->page->requires->js_function_call('focuscontrol', Array($focus));
+            }
+        }
 
         // Add the meta tags from the themes if any were requested.
         $output .= $this->page->theme->get_meta_tags($this->page);
index 7230c99853a3721aedae62d8ff71e899f8684147..74905e26d7774e0f33f360bfab6cc8aa86310581 100644 (file)
@@ -464,7 +464,6 @@ global $SCRIPT;
 
 /// Location of standard files
     $CFG->wordlist    = $CFG->libdir .'/wordlist.txt';
-    $CFG->javascript  = $CFG->libdir .'/javascript.php';
     $CFG->moddata     = 'moddata';
 
 /// Create the $PAGE global.
diff --git a/mod/resource/type/ims/ims.js b/mod/resource/type/ims/ims.js
new file mode 100644 (file)
index 0000000..f667361
--- /dev/null
@@ -0,0 +1,20 @@
+window.onresize = function() {
+    resizeiframe(imsdata.jsarg, imsdata.customcorners);
+};
+window.name='ims-cp-page';
+
+// Set Interval until ims-containerdiv and (ims-contentframe or ims-contentframe-no-nav) is available
+function waiting() {
+    var cd   = document.getElementById('ims-containerdiv');
+    var cf   = document.getElementById('ims-contentframe');
+    var cfnv = document.getElementById('ims-contentframe-no-nav');
+
+    if (cd && (cf || cfnv)) {
+        resizeiframe(imsdata.jsarg, imsdata.customcorners);
+        clearInterval(ourInterval);
+        return true;
+    }
+    return false;
+}
+
+var ourInterval = setInterval('waiting()', 100);
\ No newline at end of file
diff --git a/mod/resource/type/ims/javascript.php b/mod/resource/type/ims/javascript.php
deleted file mode 100644 (file)
index dd31b6a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php  /// $Id $
-       /// Load IMS required Javascript libraries, adding them
-       /// before the standard one ($standard_javascript)
-
-    if (!defined('MOODLE_INTERNAL')) {
-        die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
-    }
-
-/// We use this globals to be able to generate the proper JavaScripts
-    global $jsarg, $standard_javascript;
-
-/// Let's know if we are using a customcorners theme. It implies new calculations
-/// within the resizeiframe function.
-// TODO this will no longer work. We have the more general mechanism using renderers/renderer_factories
-// to determine what HTML is output. If this JavaScript is really still necessary, then we will have
-// to find another way to handle this.
-    if (!empty($THEME->customcorners)) {
-        $customcorners = 'true';
-    } else {
-        $customcorners = 'false';
-    }
-
-/// Load IMS needed JavaScript
-/// The dummy LMS API hack to stop some SCORM packages giving errors.
-    echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/mod/resource/type/ims/dummyapi.js\"></script>\n";
-/// The resize iframe script
-    echo "    <script type=\"text/javascript\" src=\"$CFG->wwwroot/mod/resource/type/ims/resize.js\"></script>\n";
-    echo "    <script type=\"text/javascript\">
-        window.onresize = function() {
-            resizeiframe($jsarg, $customcorners);
-        };
-        window.name='ims-cp-page';
-
-        // Set Interval until ims-containerdiv and (ims-contentframe or ims-contentframe-no-nav) is available
-        function waiting() {
-            var cd   = document.getElementById('ims-containerdiv');
-            var cf   = document.getElementById('ims-contentframe');
-            var cfnv = document.getElementById('ims-contentframe-no-nav');
-
-            if (cd && (cf || cfnv)) {
-                resizeiframe($jsarg, $customcorners);
-                clearInterval(ourInterval);
-                return true;
-            }
-            return false;
-        }
-
-        var ourInterval = setInterval('waiting()', 100);
-    </script>\n";
-
-/// Load standard JavaScript
-    include("$standard_javascript");
-?>
index 9840a3af5e2d287364c1d7550838e13c88e78ede..2294df6271c9a3c077514d8d4fdf5ed2a3fe116b 100644 (file)
         $direction = ' dir="ltr"';
     }
 
-/// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-(
-    global $jsarg;
     $jsarg = 'true';
-/// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-(
-    global $standard_javascript;
-    $standard_javascript = $CFG->javascript;  // Save original javascript file
-    $CFG->javascript = $CFG->dirroot.'/mod/resource/type/ims/javascript.php';  //Use our custom IMS javascript code
+    if (!empty($THEME->customcorners)) {
+        $customcorners = 'true';
+    } else {
+        $customcorners = 'false';
+    }
+    $PAGE->requires->data_for_js('imsdata', Array('customcorners'=>$customcorners, 'jsarg'=>$jsarg));
+    $PAGE->requires->js('mod/resource/type/ims/dummyapi.js')->in_head();
+    $PAGE->requires->js('mod/resource/type/ims/resize.js')->in_head();
+    $PAGE->requires->js('mod/resource/type/ims/ims.js')->in_head();
 
 /// The output here
 
index a62f96dd4eb5ce9ffd77f671244f795c611d3632..748eb8486525c951664e23e981983426d0b71dc6 100644 (file)
@@ -315,7 +315,7 @@ class resource_ims extends resource_base {
      * @param    CFG     global object
      */
     function display() {
-        global $CFG, $THEME, $USER;
+        global $CFG, $THEME, $USER, $PAGE;
 
         require_once($CFG->libdir.'/filelib.php');
 
@@ -456,15 +456,20 @@ class resource_ims extends resource_base {
         if (empty($frameset) || $frameset=='ims') {
 
         /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-(
-            global $jsarg;
             $jsarg = 'false';
             if (!empty($this->parameters->navigationmenu)) {
                 $jsarg = 'true';
             }
-        /// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-(
-            global $standard_javascript;
-            $standard_javascript = $CFG->javascript;  // Save original javascript file
-            $CFG->javascript = $CFG->dirroot.'/mod/resource/type/ims/javascript.php';  //Use our custom IMS javascript code
+
+            if (!empty($THEME->customcorners)) {
+                $customcorners = 'true';
+            } else {
+                $customcorners = 'false';
+            }
+            $PAGE->requires->data_for_js('imsdata', Array('customcorners'=>$customcorners, 'jsarg'=>$jsarg));
+            $PAGE->requires->js('mod/resource/type/ims/dummyapi.js')->in_head();
+            $PAGE->requires->js('mod/resource/type/ims/resize.js')->in_head();
+            $PAGE->requires->js('mod/resource/type/ims/ims.js')->in_head();
 
         /// moodle header
             if ($resource->popup) {