Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load jQuery/jQuery UI dependencies
loadDependencies = (callback) ->
requirements = {jq: '1.6.1', jqui: '1.8.7'}
getScript = (url, next) ->
script = document.createElement('script')
script.src = url
head = document.documentElement.childNodes[0]
script.onload = script.onreadystatechange = onScriptLoad script, next
head.appendChild script
onScriptLoad = (script, next) ->
->
return unless script.onload
if !@readyState or @readyState is 'loaded' or @readyState is 'complete'
next()
script.onload = script.onreadystatechange = null
head.removeChild script
if not ($ = window.jQuery) or requirements.jq > $.fn.jquery
getScript "http://ajax.googleapis.com/ajax/libs/jquery/#{requirements.jq}/jquery.js", ->
getScript "http://ajax.googleapis.com/ajax/libs/jqueryui/#{requirements.jqui}/jquery-ui.js", ->
callback window.jQuery.noConflict(1)
else
if not (jqui_version = window.jQuery.ui.version) or requirements.jqui > jqui_version
getScript "http://ajax.googleapis.com/ajax/libs/jqueryui/#{requirements.jqui}/jquery-ui.js", ->
callback window.jQuery.noConflict(1)
else
callback window.jQuery.noConflict(1)
loadDependencies ($) ->
# Your code goes here:
alert "jq: #{$.fn.jquery}, jqui: #{$.ui.version}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment