Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-37127 JavaScript: Add support for development using YUI Shifter

  • Loading branch information...
commit a45e8fd3da2f59f7d880b112152f9b52801b282a 1 parent cce0d9a
@andrewnicols andrewnicols authored
View
3  config-dist.php
@@ -468,6 +468,9 @@
// Prevent theme caching
// $CFG->themerev = -1; // NOT FOR PRODUCTION SERVERS!
//
+// Prevent JS caching
+// $CFG->jsrev = -1; // NOT FOR PRODUCTION SERVERS!
+//
// Prevent core_string_manager on-disk cache
// $CFG->langstringcache = false; // NOT FOR PRODUCTION SERVERS!
//
View
3  lib/outputrequirementslib.php
@@ -198,7 +198,6 @@ public function __construct() {
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep.'moodle/'.$jsrev.'/',
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep,
'combine' => $this->yui3loader->combine,
- 'filter' => '',
'ext' => false,
'root' => 'moodle/'.$jsrev.'/', // Add the rev to the root path so that we can control caching.
'patterns' => array(
@@ -1062,7 +1061,7 @@ public function get_head_code(moodle_page $page, core_renderer $renderer) {
// Note: in JavaScript just use "YUI().use('overlay', function(Y) { .... });",
// this needs to be done before including any other script.
$js = "var M = {}; M.yui = {};
-var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'.'+me.type;};
+var moodleConfigFn = function(me) {var p = me.path, b = me.name.replace(/^moodle-/,'').split('-', 3), n = b.pop();if (/(skin|core)/.test(n)) {n = b.pop();me.type = 'css';};me.path = b.join('-')+'/'+n+'/'+n+'-min.'+me.type;};
var galleryConfigFn = function(me) {var p = me.path,v=M.yui.galleryversion,f;if(/-(skin|core)/.test(me.name)) {me.type = 'css';p = p.replace(/-(skin|core)/, '').replace(/\.js/, '.css').split('/'), f = p.pop().replace(/(\-(min|debug))/, '');if (/-skin/.test(me.name)) {p.splice(p.length,0,v,'assets','skins','sam', f);} else {p.splice(p.length,0,v,'assets', f);};} else {p = p.split('/'), f = p.pop();p.splice(p.length,0,v, f);};me.path = p.join('/');};
var yui2in3ConfigFn = function(me) {if(/-skin|reset|fonts|grids|base/.test(me.name)){me.type='css';me.path=me.path.replace(/\.js/,'.css');me.path=me.path.replace(/\/yui2-skin/,'/assets/skins/sam/yui2-skin');}};\n";
$js .= js_writer::set_variable('YUI_config', $this->YUI_config, false) . "\n";
View
34 theme/yui_combo.php
@@ -73,6 +73,7 @@
if (empty($part)) {
continue;
}
+ $filecontent = '';
$part = min_clean_param($part, 'SAFEPATH');
$bits = explode('/', $part);
if (count($bits) < 2) {
@@ -95,13 +96,27 @@
}
$frankenstyle = array_shift($bits);
$filename = array_pop($bits);
+ $modulename = $bits[0];
$dir = get_component_directory($frankenstyle);
if ($mimetype == 'text/css') {
$bits[] = 'assets';
$bits[] = 'skins';
$bits[] = 'sam';
}
- $contentfile = $dir.'/yui/'.join('/', $bits).'/'.$filename;
+
+ // For shifted YUI modules, we need the YUI module name in frankenstyle format.
+ $frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename));
+
+ // By default, try and use the /yui/build directory.
+ $frankenstylefilename = preg_replace('/' . $modulename . '/', $frankenstylemodulename, $filename);
+ $contentfile = $dir . '/yui/build/' . $frankenstylemodulename . '/' . $frankenstylefilename;
+
+ // If the shifted versions don't exist, fall back to the non-shifted file.
+ if (!file_exists($contentfile) or !is_file($contentfile)) {
+ // We have to revert to the non-minified and non-debug versions.
+ $filename = preg_replace('/-(min|debug)\./', '.', $filename);
+ $contentfile = $dir . '/yui/' . join('/', $bits) . '/' . $filename;
+ }
} else if ($version === '2in3') {
$contentfile = "$CFG->libdir/yuilib/$part";
@@ -120,7 +135,10 @@
$content .= "\n// Combo resource $part ($location) not found!\n";
continue;
}
- $filecontent = file_get_contents($contentfile);
+
+ if (empty($filecontent)) {
+ $filecontent = file_get_contents($contentfile);
+ }
$fmodified = filemtime($contentfile);
if ($fmodified > $lastmodified) {
$lastmodified = $fmodified;
@@ -131,8 +149,16 @@
if ($mimetype === 'text/css') {
if ($version == 'moodle') {
- $filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php'.$sep.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent);
-
+ // Search for all images in the file and replace with an appropriate link to the yui_image.php script
+ $imagebits = array(
+ $sep . $version,
+ $frankenstyle,
+ $modulename,
+ array_shift($bits),
+ '$1.$2'
+ );
+
+ $filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot . '/theme/yui_image.php' . implode('/', $imagebits), $filecontent);
} else if ($version == '2in3') {
// First we need to remove relative paths to images. These are used by YUI modules to make use of global assets.
// I've added this as a separate regex so it can be easily removed once
View
13 theme/yui_image.php
@@ -41,7 +41,6 @@
$etag = sha1($path);
$parts = explode('/', $path);
$version = array_shift($parts);
-
if ($version == 'moodle' && count($parts) >= 3) {
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
define('ABORT_AFTER_CONFIG_CANCEL', true);
@@ -54,7 +53,17 @@
$image = array_pop($parts);
$subdir = join('/', $parts);
$dir = get_component_directory($frankenstyle);
- $imagepath = $dir.'/yui/'.$module.'/assets/skins/sam/'.$image;
+
+ // For shifted YUI modules, we need the YUI module name in frankenstyle format.
+ $frankenstylemodulename = join('-', array($version, $frankenstyle, $module));
+
+ // By default, try and use the /yui/build directory.
+ $imagepath = $dir . '/yui/build/' . $frankenstylemodulename . '/assets/skins/sam/' . $image;
+
+ // If the shifted versions don't exist, fall back to the non-shifted file.
+ if (!file_exists($imagepath) or !is_file($imagepath)) {
+ $imagepath = $dir . '/yui/' . $module . '/assets/skins/sam/' . $image;
+ }
} else if ($version == 'gallery' && count($parts)==3) {
list($module, $version, $image) = $parts;
$imagepath = "$CFG->dirroot/lib/yui/gallery/$module/$version/assets/skins/sam/$image";
Please sign in to comment.
Something went wrong with that request. Please try again.