Skip to content

Instantly share code, notes, and snippets.

@KrofDrakula
Created January 9, 2011 15:21
Show Gist options
  • Save KrofDrakula/771747 to your computer and use it in GitHub Desktop.
Save KrofDrakula/771747 to your computer and use it in GitHub Desktop.
A quick-n-dirty jQuery loader for plugins
(function($) {
var Initialize = function($) {
alert("Loaded jQuery v." + $.fn.jquery);
// your plugin code here
};
// loader function for jQuery in case jQuery isn't found on the page
var LoadDependencies = function() {
var scr = document.createElement('script');
scr.type = "text/javascript";
scr.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js";
scr.onreadystatechange = function() {
if(this.readyState == 'complete') {
Initialize(jQuery);
}
};
scr.onload = function() {
Initialize(jQuery);
};
document.getElementsByTagName('head')[0].appendChild(scr);
}
if($ == null) {
// no jQuery detected, so load up jQuery
LoadDependencies();
} else {
console.debug("jQuery already present");
Initialize($);
}
})(window.jQuery || null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment