Skip to content

Instantly share code, notes, and snippets.

@mrkurt
Created December 30, 2010 21:59
Show Gist options
  • Save mrkurt/760369 to your computer and use it in GitHub Desktop.
Save mrkurt/760369 to your computer and use it in GitHub Desktop.
scripts = [
{
test: ()-> window.jQuery && window.jQuery.fn && window.jQuery.fn.jquery > "1.4.2"
src: 'http://localhost:3000/javascripts/jquery-1.4.2.min.js'
callback : ()->
($ = window.jQuery).noConflict(1)
},
{
test: ()-> window.jQuery && window.jQuery.fn.lightbox_me
src: 'http://localhost:3000/javascripts/jquery.lightbox_me.js'
callback: ()-> lightbox_me_init(window.jQuery)
}
]
scripts.load = (queue, callback) ->
def = queue.pop()
loaded = false
s = document.createElement('script')
s.type = "text/javascript"
s.src = def.src
s.onload = s.onreadystatechanged = ()->
d = this.readyState
if !loaded && (!d || d == 'loaded' || d == 'complete')
loaded = true
def.callback() if def.callback?
if queue.length == 0
callback()
else
scripts.load(queue, callback)
document.documentElement.childNodes[0].appendChild(s)
queue = (s for s in scripts when s? && !s.test()).reverse()
if queue.length == 0
init()
else
scripts.load(queue, init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment