From f320e8d00f9144ce410a0b5b44afe1dd5fcb5d2a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 3 Jul 2013 12:14:53 +0100 Subject: [PATCH] MDL-40478 JavaScript: Support loading of YUI submodules in the yui-loader --- lib/yui/config/moodle.js | 33 +++++++++++++++++++-------------- theme/yui_combo.php | 9 +++++++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/yui/config/moodle.js b/lib/yui/config/moodle.js index f1532cbb1a5..355bd53e55b 100644 --- a/lib/yui/config/moodle.js +++ b/lib/yui/config/moodle.js @@ -14,24 +14,29 @@ // along with Moodle. If not, see . // A module name should be composed of: -// moodle--[-skin] -var path = me.path, - parts = me.name.replace(/^moodle-/,'').split('-', 3), - modulename = parts.pop(); +// moodle--[-][-skin] +var parts = me.name.replace(/^moodle-/,'').split('-'), + component = parts.shift(), + module = parts[0], + min = '-min'; -if (/(skin|core)/.test(modulename)) { +if (/-(skin|core)$/.test(me.name)) { // For these types, we need to remove the final word and set the type. - modulename = parts.pop(); + parts.pop(); me.type = 'css'; + + // CSS is not minified - clear the min option. + min = ''; } -// Build the first part of the filename. -me.path = parts.join('-') + '/' + modulename + '/' + modulename; +if (module) { + // Determine the filename based on the remaining parts. + var filename = parts.join('-'); -// CSS is not minified, but all other types are. -if (me.type !== 'css') { - me.path = me.path + '-min'; + // Build the first part of the filename. + me.path = component + '/' + module + '/' + filename + min + '.' + me.type; +} else { + // This is a hangup from the old ways of writing Modules. + // We will start to warn about this once we have removed all core components of this form. + me.path = component + '/' + component + '.' + me.type; } - -// Add the file extension. -me.path = me.path + '.' + me.type; diff --git a/theme/yui_combo.php b/theme/yui_combo.php index 8d27525b396..4665b822f11 100644 --- a/theme/yui_combo.php +++ b/theme/yui_combo.php @@ -107,17 +107,22 @@ foreach ($parts as $part) { $frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename)); $frankenstylefilename = preg_replace('/' . $modulename . '/', $frankenstylemodulename, $filename); + // Submodules are stored in a directory with the full submodule name. + // We need to remove the -debug.js, -min.js, and .js from the file name to calculate that directory name. + $frankenstyledirectoryname = str_replace(array('-min.js', '-debug.js', '.js'), '', $frankenstylefilename); + // By default, try and use the /yui/build directory. + $contentfile = $dir . '/yui/build/' . $frankenstyledirectoryname; if ($mimetype == 'text/css') { // CSS assets are in a slightly different place to the JS. - $contentfile = $dir . '/yui/build/' . $frankenstylemodulename . '/assets/skins/sam/' . $frankenstylefilename; + $contentfile = $contentfile . '/assets/skins/sam/' . $frankenstylefilename; // Add the path to the bits to handle fallback for non-shifted assets. $bits[] = 'assets'; $bits[] = 'skins'; $bits[] = 'sam'; } else { - $contentfile = $dir . '/yui/build/' . $frankenstylemodulename . '/' . $frankenstylefilename; + $contentfile = $contentfile . '/' . $frankenstylefilename; } // If the shifted versions don't exist, fall back to the non-shifted file. -- 2.43.0