Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reup fix for ticket 2527949 #164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/loader/js/loader.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ Y.Loader = function(o) {
// map of modules with a hash of modules that meet the requirement // map of modules with a hash of modules that meet the requirement
// self.provides = {}; // self.provides = {};


/**
* Specify whether or not to load optional dependencies for
* a specific modules.
* ex. {"history-html5":false, "autocomplete-sources":true}
* Overrides loadOptional.
* @property loadOptionalCfg
* @type {string:boolean}
*/
self.loadOptionalCfg = {};

self.config = o; self.config = o;
self._internal = true; self._internal = true;


Expand Down Expand Up @@ -1377,7 +1387,7 @@ Y.Loader.prototype = {
intl = mod.lang || mod.intl, intl = mod.lang || mod.intl,
info = this.moduleInfo, info = this.moduleInfo,
ftests = Y.Features && Y.Features.tests.load, ftests = Y.Features && Y.Features.tests.load,
hash, reparse; hash, reparse, isLoadOptional;


// console.log(name); // console.log(name);


Expand Down Expand Up @@ -1464,7 +1474,8 @@ Y.Loader.prototype = {
} }
} }


if (o && this.loadOptional) { isLoadOptional = (this.loadOptionalCfg[name] === undefined)? this.loadOptional: this.loadOptionalCfg[name];
if (o && isLoadOptional) {
for (i = 0; i < o.length; i++) { for (i = 0; i < o.length; i++) {
if (!hash[o[i]]) { if (!hash[o[i]]) {
d.push(o[i]); d.push(o[i]);
Expand Down
18 changes: 18 additions & 0 deletions src/loader/tests/loader-tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1144,6 +1144,24 @@ YUI.add('loader-tests', function(Y) {
Assert.isTrue(out.js[0].indexOf('node-base') > 0, 'Failed to load node-base'); Assert.isTrue(out.js[0].indexOf('node-base') > 0, 'Failed to load node-base');


}, },
test_resolve_loadOptional: function() {
var loader = new testY.Loader({
combine: false,
loadOptional: false,
loadOptionalCfg: { "autocomplete-sources": false, "dd-plugin": true},
require:['autocomplete-sources', "dd-plugin"]
});
var out = loader.resolve(true);
var m = {}
for (i in out.js){m[out.js[i].substring(out.js[i].lastIndexOf('/')+1, out.js[i].length)]=i}
Assert.isTrue((m['jsonp-min.js'] === undefined)
&& (m['json-parse-min.js'] === undefined)
&& (m['io-base-min.js'] === undefined)
&& (m['yql-min.js'] === undefined)
&& (m['dd-proxy-min.js'] !== undefined)
&& (m['dd-constrain-min.js'] !== undefined),
'loadoptionalCfg didn\'t work');
},
'test: aliases config option inside group': function() { 'test: aliases config option inside group': function() {
var loader = new Y.Loader({ var loader = new Y.Loader({
ignoreRegistered: true, ignoreRegistered: true,
Expand Down
84 changes: 42 additions & 42 deletions src/yui/js/load-tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ add('load', '0', {
"trigger": "io-base", "trigger": "io-base",
"ua": "nodejs" "ua": "nodejs"
}); });
// history-hash-ie
add('load', '1', {
"name": "history-hash-ie",
"test": function (Y) {
var docMode = Y.config.doc && Y.config.doc.documentMode;

return Y.UA.ie && (!('onhashchange' in Y.config.win) ||
!docMode || docMode < 8);
},
"trigger": "history-hash"
});
// graphics-canvas-default // graphics-canvas-default
add('load', '2', { add('load', '1', {
"name": "graphics-canvas-default", "name": "graphics-canvas-default",
"test": function(Y) { "test": function(Y) {
var DOCUMENT = Y.config.doc, var DOCUMENT = Y.config.doc,
Expand All @@ -30,7 +19,7 @@ add('load', '2', {
"trigger": "graphics" "trigger": "graphics"
}); });
// autocomplete-list-keys // autocomplete-list-keys
add('load', '3', { add('load', '2', {
"name": "autocomplete-list-keys", "name": "autocomplete-list-keys",
"test": function (Y) { "test": function (Y) {
// Only add keyboard support to autocomplete-list if this doesn't appear to // Only add keyboard support to autocomplete-list if this doesn't appear to
Expand All @@ -49,35 +38,35 @@ add('load', '3', {
"trigger": "autocomplete-list" "trigger": "autocomplete-list"
}); });
// dd-gestures // dd-gestures
add('load', '4', { add('load', '3', {
"name": "dd-gestures", "name": "dd-gestures",
"test": function(Y) { "test": function(Y) {
return ((Y.config.win && ("ontouchstart" in Y.config.win)) && !(Y.UA.chrome && Y.UA.chrome < 6)); return ((Y.config.win && ("ontouchstart" in Y.config.win)) && !(Y.UA.chrome && Y.UA.chrome < 6));
}, },
"trigger": "dd-drag" "trigger": "dd-drag"
}); });
// scrollview-base-ie
add('load', '4', {
"name": "scrollview-base-ie",
"trigger": "scrollview-base",
"ua": "ie"
});
// editor-para-ie // editor-para-ie
add('load', '5', { add('load', '5', {
"name": "editor-para-ie", "name": "editor-para-ie",
"trigger": "editor-para", "trigger": "editor-para",
"ua": "ie", "ua": "ie",
"when": "instead" "when": "instead"
}); });
// transition-timer // graphics-vml-default
add('load', '6', { add('load', '6', {
"name": "transition-timer", "name": "graphics-vml-default",
"test": function (Y) { "test": function(Y) {
var DOCUMENT = Y.config.doc, var DOCUMENT = Y.config.doc,
node = (DOCUMENT) ? DOCUMENT.documentElement: null, canvas = DOCUMENT && DOCUMENT.createElement("canvas");
ret = true; return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));

if (node && node.style) {
ret = !('MozTransition' in node.style || 'WebkitTransition' in node.style);
}

return ret;
}, },
"trigger": "transition" "trigger": "graphics"
}); });
// graphics-svg-default // graphics-svg-default
add('load', '7', { add('load', '7', {
Expand All @@ -92,17 +81,32 @@ add('load', '7', {
}, },
"trigger": "graphics" "trigger": "graphics"
}); });
// scrollview-base-ie // history-hash-ie
add('load', '8', { add('load', '8', {
"name": "scrollview-base-ie", "name": "history-hash-ie",
"trigger": "scrollview-base", "test": function (Y) {
"ua": "ie" var docMode = Y.config.doc && Y.config.doc.documentMode;

return Y.UA.ie && (!('onhashchange' in Y.config.win) ||
!docMode || docMode < 8);
},
"trigger": "history-hash"
}); });
// widget-base-ie // transition-timer
add('load', '9', { add('load', '9', {
"name": "widget-base-ie", "name": "transition-timer",
"trigger": "widget-base", "test": function (Y) {
"ua": "ie" var DOCUMENT = Y.config.doc,
node = (DOCUMENT) ? DOCUMENT.documentElement: null,
ret = true;

if (node && node.style) {
ret = !('MozTransition' in node.style || 'WebkitTransition' in node.style);
}

return ret;
},
"trigger": "transition"
}); });
// dom-style-ie // dom-style-ie
add('load', '10', { add('load', '10', {
Expand Down Expand Up @@ -168,15 +172,11 @@ add('load', '13', {
}, },
"trigger": "graphics" "trigger": "graphics"
}); });
// graphics-vml-default // widget-base-ie
add('load', '14', { add('load', '14', {
"name": "graphics-vml-default", "name": "widget-base-ie",
"test": function(Y) { "trigger": "widget-base",
var DOCUMENT = Y.config.doc, "ua": "ie"
canvas = DOCUMENT && DOCUMENT.createElement("canvas");
return (DOCUMENT && !DOCUMENT.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") && (!canvas || !canvas.getContext || !canvas.getContext("2d")));
},
"trigger": "graphics"
}); });
// app-transitions-native // app-transitions-native
add('load', '15', { add('load', '15', {
Expand Down