Skip to content

Instantly share code, notes, and snippets.

@op1ekun
Created June 25, 2013 07:27
Show Gist options
  • Save op1ekun/5856627 to your computer and use it in GitHub Desktop.
Save op1ekun/5856627 to your computer and use it in GitHub Desktop.
Using YUI Loader's onProgress callback to load 3rd party libraries as custom modules. Still needs a little bit of tweaking...
var module = {
exports : {}
};
var exports = {};
YUI({
modules : {
'jquery' : {
fullpath : 'http://code.jquery.com/jquery-1.10.1.min.js'
},
'lodash' : {
fullpath : 'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js'
}
},
onProgress : function(e) {
console.log('onProgress', e, module.exports);
// create dynamic, 3rd-party modules
switch(e.name) {
case 'jquery' :
(function() {
var clone;
YUI.add('jquery', function(Y) {
// create a clone ONLY once
if (!clone) {
clone = Y.clone(module.exports, true);
module.exports = {};
}
Y.namespace('3rd_party')
.jQuery = clone;
}, '1.10.1');
})();
break;
case 'lodash' :
(function() {
var clone;
YUI.add('lodash', function(Y) {
// create a clone ONLY once
if (!clone) {
clone = Y.clone(exports, true);
exports = {};
}
Y.namespace('3rd_party')
.lodash = clone;
}, '1.3.1');
})();
break;
}
}
}).use('jquery', 'lodash',
function(Y) {
var $, _;
$ = Y['3rd_party'].jQuery;
_ = Y['3rd_party'].lodash._;
$('<h1>jQuery ' + $.prototype.jquery + ' in YUI! It works!</h1>')
.appendTo('body');
$('<h1>Lo-Dash ' + _.VERSION + ' in YUI! It works!</h1>')
.appendTo('body');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment