From: vyshane Date: Fri, 2 Feb 2007 06:35:25 +0000 (+0000) Subject: Reworked require_js() so that it will not load libraries more than once. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f72f94a257e44df36f249877ef20ff49be9f8d41;p=moodle.git Reworked require_js() so that it will not load libraries more than once. Related to MDL-7682 and MDL-8374. --- diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index e910176f24..e9eb01055c 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -1,19 +1,72 @@ -\n"; + if ($loadlib == $CFG->wwwroot.'/lib/yui/logger/logger-min.js') { + // Special case, we need the CSS too. + $output .= 'wwwroot}/lib/yui/logger/assets/logger.css\" />\n"; + } + } + return $output; } +} + + +/** + * Get the path to a JavaScript library. + * @param $libname - the name of the library whose path we need. + * @return string + */ +function ajax_get_lib($libname) { + + global $CFG; + $libpath = ''; - //list of shortname to filepath translations $translatelist = array( 'yui_yahoo' => '/lib/yui/yahoo/yahoo-min.js', 'yui_animation' => '/lib/yui/animation/animation-min.js', @@ -36,18 +89,18 @@ function require_js($list) { 'ajaxcourse' => '/lib/ajax/ajaxcourse.js' ); - for ($i=0; $iwwwroot.''.$translatelist[$list[$i]]."'>\n"; - if ($translatelist[$list[$i]] == '/lib/yui/logger/logger-min.js') { - // Special case. We need the css. - $output .= ""; - } - } else { - $output .= "\n"; - } + if (array_key_exists($libname, $translatelist)) { + $libpath = $CFG->wwwroot . $translatelist[$libname]; + } else { + $libpath = $libname; } - return $output; + + $testpath = str_replace($CFG->wwwroot, $CFG->dirroot, $libpath); + if (!file_exists($testpath)) { + error('require_js: '.$libpath.' - file not found.'); + } + + return $libpath; }