Created
October 14, 2010 13:52
-
-
Save collegeman/626196 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // make sure our scripting is isolated | |
| (function() { | |
| // copy reference to existing onload event handler | |
| var onload = window.onload; | |
| // create our own onload event handler | |
| window.onload = function() { | |
| // call the other onload event | |
| if (typeof onload == 'function') { | |
| onload(); | |
| } | |
| // our own, privately scoped copy of jQuery | |
| var jQuery = window.jQuery; | |
| // this is what we're going to do with jQuery: | |
| function doWithJQuery() { | |
| (function($) { | |
| // ******** YOUR CODE GOES HERE ********** | |
| })(jQuery); | |
| } | |
| // load jQuery if it is not defined | |
| if (!jQuery) { | |
| // create a new script element and load jQuery via Google AJAX library hosting | |
| var e = document.createElement('script'); | |
| // I thought setting this to false would make it load synchronously, but it doesn't... | |
| e.async = true; | |
| e.src = document.location.protocol + '//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'; | |
| document.body.appendChild(e); | |
| // start waiting for the script to load | |
| var waitForJQuery = setInterval(function() { | |
| if (window.jQuery) { | |
| // stop waiting for the script to load | |
| clearInterval(waitForJQuery); | |
| // since we loaded it ourselves, let's make sure not to introduce conflicts | |
| jQuery = $.noConflict(); | |
| doWithJQuery(); | |
| } | |
| }, 100); | |
| } | |
| else { | |
| doWithJQuery(); | |
| } | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment