Created
September 9, 2011 06:45
-
-
Save priithaamer/1205633 to your computer and use it in GitHub Desktop.
Loads jQuery if not loaded
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 $; | |
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