Created
January 9, 2011 15:21
-
-
Save KrofDrakula/771747 to your computer and use it in GitHub Desktop.
A quick-n-dirty jQuery loader for plugins
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 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