Created
July 29, 2010 06:55
-
-
Save curtisharvey/497452 to your computer and use it in GitHub Desktop.
YUI seed loader
This file contains hidden or 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
/** | |
* 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