From: samhemelryk Date: Tue, 7 Jul 2009 09:09:16 +0000 (+0000) Subject: javascript MDL-16673 Removed all removeable uses of CFG->javascript X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e11a8328b3a41371f8009b5df8e9f0e7ae4d55ea;p=moodle.git javascript MDL-16673 Removed all removeable uses of CFG->javascript 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. --- diff --git a/admin/xmldb/index.php b/admin/xmldb/index.php index 7fea36d804..ffad1bdac4 100644 --- a/admin/xmldb/index.php +++ b/admin/xmldb/index.php @@ -79,11 +79,25 @@ /// 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 index 483eec16e5..0000000000 --- a/admin/xmldb/javascript.php +++ /dev/null @@ -1,58 +0,0 @@ -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); -?> diff --git a/lib/javascript-static.js b/lib/javascript-static.js index dc131488ff..2460edf6a7 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -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 index 5b09887575..0000000000 --- a/lib/javascript.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -/** - * 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 -} -?> - - - - - - - - - - - - - diff --git a/lib/outputlib.php b/lib/outputlib.php index 62db77ab98..3d4ff1dead 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -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 = ''; - $output .= sprintf($metarefesh, $this->page->periodicrefreshdelay, $this->page->url->out()); + $output .= ''; } - // 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); diff --git a/lib/setup.php b/lib/setup.php index 7230c99853..74905e26d7 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -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 index 0000000000..f6673615dc --- /dev/null +++ b/mod/resource/type/ims/ims.js @@ -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 index dd31b6a270..0000000000 --- a/mod/resource/type/ims/javascript.php +++ /dev/null @@ -1,53 +0,0 @@ -customcorners)) { - $customcorners = 'true'; - } else { - $customcorners = 'false'; - } - -/// Load IMS needed JavaScript -/// The dummy LMS API hack to stop some SCORM packages giving errors. - echo "\n"; -/// The resize iframe script - echo " \n"; - echo " \n"; - -/// Load standard JavaScript - include("$standard_javascript"); -?> diff --git a/mod/resource/type/ims/preview.php b/mod/resource/type/ims/preview.php index 9840a3af5e..2294df6271 100644 --- a/mod/resource/type/ims/preview.php +++ b/mod/resource/type/ims/preview.php @@ -44,13 +44,16 @@ $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 diff --git a/mod/resource/type/ims/resource.class.php b/mod/resource/type/ims/resource.class.php index a62f96dd4e..748eb84865 100644 --- a/mod/resource/type/ims/resource.class.php +++ b/mod/resource/type/ims/resource.class.php @@ -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) {