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.
This commit is contained in:
samhemelryk 2009-07-07 09:09:16 +00:00
parent e4e7044acd
commit e11a8328b3
10 changed files with 91 additions and 199 deletions

View File

@ -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());

View File

@ -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);
?>

View 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);
}

View File

@ -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>

View 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);

View 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.

View File

@ -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);

View File

@ -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");
?>

View File

@ -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

View 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) {