Last active
December 29, 2015 20:22
-
-
Save kputnam/8258ef96b2a9b1a8587f to your computer and use it in GitHub Desktop.
jQuery Bookmarklet
This file contains 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
(function() { | |
var otherLib = (typeof($) == 'function'); | |
if (typeof(jQuery) != 'undefined') { | |
alert('jQuery already defined'); | |
return; | |
} | |
function getScript(url, callback) { | |
var script = document.createElement('script'); | |
script.src = url; | |
var head = document.getElementsByTagName('head')[0], | |
done = false; | |
script.onload = script.onreadystatechange = function() { | |
if ( !done && (!this.readyState | |
|| this.readyState == 'loaded' | |
|| this.readyState == 'complete') ) { | |
done = true; | |
callback(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
getScript('http://code.jquery.com/jquery-latest.min.js', function() { | |
if (typeof jQuery == 'undefined') | |
alert('Unable to load jQuery'); | |
else if (otherLib) | |
alert('No conflict mode, use $jq()'); | |
else | |
alert('jQuery is loaded'); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment