|
As some of you know, I enjoy photography very much. It is a hobby and passion of mine. By day, I am a software developer and enjoy taking on new challenges. I know this is a photography site but don't be surprised if you see a mix of my software accomplishments as well as my photography work. After all, it's all art in the end right? jQuery - More than one version on the same page.
I'm going to start off by showing you all the coded used, then explain what each block of code means. Feel free to copy the following code and paste it into a html document.
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script>
//Does a jQuery object exist?
if (typeof jQuery !== 'undefined') {
jQuery = jQuery.noConflict(true);
$ = jQuery;
}
</script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
//Reassign the latest loaded jQuery object as $j
$j = jQuery.noConflict(true);
//$ is assigned to jQuery 1.4.3
alert($().jquery);
//$j is assigned to jQuery 1.7.1
alert($j().jquery);
</script>
</head>
<body>
<!-- Page content -->
</body>
</html>
Load in an older version of jQuery, in this case 1.4.3. I do a check to make sure the jQuery object exists by doing a typeof. If exists then I rename the jQuery object to jQuery and $; seems silly but it works. Why did i rename it to the same object names? well if you have plugins that are only compatible with an older version of jQuery, then you do not have to rewrite the plugin, it will use the jQuery object.
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script>
//Does a jQuery object exist?
if (typeof jQuery !== 'undefined') {
jQuery = jQuery.noConflict(true);
$ = jQuery;
}
</script>
Now, later in the code, you can load in a newer version of jQuery, which will not override the previous jQuery or $ object and reassign it to $j using jQuery.noConflict. What this means is you can now address your older jquery with $ or jQuery and the new one with $j. Also, this technique is not limited to 2 versions. <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> //Reassign the latest loaded jQuery object as $j $j = jQuery.noConflict(true); //$ is assigned to jQuery 1.4.3 alert($().jquery); //$j is assigned to jQuery 1.7.1 alert($j().jquery); </script> Conclusion, why would I want this? Well in my day job we inject into the client's DOM after a page has been loaded, meaning the client could already have jQuery loaded and if we dont use this technique then when we load in our jQuery, all of their code/plugins would run on our jQuery version. -Zach Kaitlyn's 1st BirthdaySometimes people ask you to take photos for moments in their life that they don't want to miss. In this case for Kaitlyn's birthday, I showed up with my camera and a flash and captured the moment without them asking. These are all candid shots that I took while watching Kaitlyn get a sugar high from her cake and opening presents. Happy birthday girl! Check out the rest of her birthday here.
These shots were done with a detachable flash bounced off the ceiling, I would always get down to the same level as the subject so you dont get the feeling of being part of the experience.
© Zach Manring Photography
|