Skip to content

Instantly share code, notes, and snippets.

@curtisharvey
Created July 29, 2010 06:55
Show Gist options
  • Save curtisharvey/497452 to your computer and use it in GitHub Desktop.
Save curtisharvey/497452 to your computer and use it in GitHub Desktop.
YUI seed loader
/**
* Light-weight YUI-dependend Script Loader
* - loads YUI 3 if not already loaded
* - then loads your script(s)
*
* Useful for dynamically loaded modules, injected scripts, bookmarklets, etc…
*/
(function() {
// YUI to load if unavailable
var YUI_SRC = 'http://yui.yahooapis.com/combo?3.1.1/build/yui/yui-min.js' +
'&3.1.1/build/loader/loader-min.js',
// scripts to load once YUI is available: a url or array of urls
SCRIPTS = ['http://example.com/script1.js', 'http://example.com/script2.js'];
function onYUIAvailable() {
Y.Get.script(SCRIPTS);
}
if (typeof YUI === 'undefined') {
YUI_config = {injected:true};
var node = document.createElement('script'),
head = document.documentElement.firstChild;
node.type = 'text/javascript';
if (node.readyState) {
node.onreadystatechange = function() {
if (node.readyState == 'loaded' || node.readyState == 'complete') {
node.onreadystatechange = null;
onYUIAvailable();
}
};
} else {
node.onload = onYUIAvailable;
}
node.src = YUI_SRC;
head.insertBefore(node, head.firstChild);
} else {
onYUIAvailable();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment