Tech Note: JQuery 1.3 Released
Gifts for geeks! A major update for the indispensable Javascript library jQuery has been released into the wild: jQuery 1.3 and the jQuery Foundation. They’re claiming some big speed improvements and other nice enhancements; full details are in the release notes. And they’ve also unveiled a great Ajax-based API browser, setting a new standard for API documentation. Kudos to the jQuery team for some excellent work.
We’ve installed the new version at LGF and had only one problem so far, which is a bit amazing considering that the LGF Blog Engine contains quite a lot of jQuery-based Javascript code and uses half a dozen plugins.
The problem occurred in both Internet Explorer and Firefox 3 (but strangely, not in Safari), and was tracked down to the following code, which refreshes any currently visible “spinoff links” after a successful login:
$('div.related:not(:hidden) input[name=relatedentry]').each(function (i) {
doRelated($(this).val(), 'show');
});
The first expression was causing script timeouts in IE and Firefox. The Firebug debugger revealed that jQuery was entering an infinite loop when trying to process the expression, even with no visible spinoff links.
After more experimentation, we concluded that jQuery 1.3 has some bugs lurking in the new implementation of the “:not” selector. In this case there’s a simple fix that doesn’t affect functionality: use the “:visible” selector instead.
$('div.related:visible input[name=relatedentry]').each(function (i) {
doRelated($(this).val(), 'show');
});
But in other sections where we really needed the NOT functionality, we had to change the code to use jQuery’s “not” method instead of the selector. For example, this:
$('div.postfooter div.rating a.ratebutton:not(.igray)').click(RateEntry);
…had to be changed to this:
$('div.postfooter div.rating a.ratebutton').not('.igray').click(RateEntry);
After these changes, everything seems groovy in all the major browsers on both Mac and PC. But please let us know if you discover anything that isn’t working right.