Skip to content

Instantly share code, notes, and snippets.

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'
script.onload = script.onreadystatechange = null
head.removeChild script
if not ($ = window.jQuery) or requirements.jq > $.fn.jquery
getScript "{requirements.jq}/jquery.js", ->
getScript "{requirements.jqui}/jquery-ui.js", ->
callback window.jQuery.noConflict(1)
if not (jqui_version = window.jQuery.ui.version) or requirements.jqui > jqui_version
getScript "{requirements.jqui}/jquery-ui.js", ->
callback window.jQuery.noConflict(1)
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