Last active
August 29, 2015 13:55
-
-
Save ryanburnette/8731161 to your computer and use it in GitHub Desktop.
Two versions of jQuery in a restrictive situation.
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
<!-- At this point our environmental jQuery should have already loaded, we'll | |
assign it to a separate variable on the window and delete the dollar sign --> | |
<script> | |
window.jQuery142 = window.jQuery; | |
delete window.$; | |
</script> | |
<!-- Next, we'll load our next version of jQuery --> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<!-- Finally, we'll set our newer jQuery into noConflict mode and assign it to | |
an alernative variable, assigning our environmental jQuery back to window.jquery | |
and dollar sign --> | |
<script> | |
window.jQuery1102 = window.jQuery.noConflict(); | |
window.jQuery = window.jQuery142; | |
window.$ = window.jQuery142; | |
</script> | |
<!-- Now I can add scripts to the site which are written for modern jQuery --> | |
<script> | |
jQuery(document).ready(function($) { | |
// our existing environmental jQuery will use the old version | |
// If we use a normal ready statement we'll also use the old version | |
}); | |
window.jQuery1102(document).ready(function($) { | |
// If any of our code references window.jquery we'll cover ourselves by setting | |
// it to the new jQuery for a bit | |
window.jQuery = window.jQuery1102; | |
// All my modern jQuery code goes here | |
// And we'll reset the window jQuery now that we're done | |
window.jQuery = window.jQuery142; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment