Skip to content

Instantly share code, notes, and snippets.

@priithaamer
Created September 9, 2011 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priithaamer/1205633 to your computer and use it in GitHub Desktop.
Save priithaamer/1205633 to your computer and use it in GitHub Desktop.
Loads jQuery if not loaded
(function() {
var $;
if (window.jQuery === undefined || window.jQuery.fn.jquery < '1.5') {
(function(d, t) {
var js = document.createElement(t);
js.src = location.protocol + '//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
js.onload = scriptLoadHandler;
js.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
(d.getElementsByTagName('head')[0] || d.documentElement).appendChild(js);
}(document, 'script'));
} else {
$ = window.jQuery;
foo();
}
var scriptLoadHandler = function() {
$ = window.jQuery.noConflict(true);
foo();
};
var foo = function() {
// jQuery is ready here for your pleasure
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment