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/1.6.1/jquery.js', -> | |
getScript 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js', -> | |
callback window.jQuery.noConflict(1) | |
else | |
if not (jqui_version = windows.jQuery.ui.version) or requirements['jqui'] > jqui_version | |
getScript 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/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
This comment has been minimized.
Based on http://stackoverflow.com/questions/6535641/using-jquery-ui-in-a-bookmarklet/6551580#6551580