Created
June 25, 2013 07:27
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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