Posts Tagged ‘jquery’
So I’d like to explain why I came to this conclusion in the first place, the correct way of avoiding the problem, and a call to solve this centrally so that people don’t have six copies of jQuery loading on their websites.
The real issue
$document = JFactory::getDocument(); $document->addScript('path/to/jquery.js'); $document->addScriptDeclaration('jQuery.noConflict()');
This sometimes works. However, if (for instance) your module used jQuery and the next one used MooTools, you’d run into a conflict even though you had $document->addScriptDeclaration(‘jQuery.noConflict()’) in your code. The advice passed around by myself and the Joomla community was to do this in your code:
JHTML::_('behavior.mootools'); $document = JFactory::getDocument(); $document->addScript('path/to/jquery.js'); $document->addScriptDeclaration('jQuery.noConflict()');
This ensured that MooTools got loaded first and that the conflict would not happen. This also forced MooTools onto the page regardless of whether or not it was being used. It turns out this approach doesn’t really address the real problem: Joomla loads all of your external scripts first, then loads all of your script declarations. So for instance, the following code snippets result in the same script ordering as the previous sample:
$document = JFactory::getDocument(); $document->addScriptDeclaration('jQuery.noConflict()'); JHTML::_('behavior.mootools'); $document->addScript('path/to/jquery.js'); $document = JFactory::getDocument(); JHTML::_('behavior.mootools'); $document->addScriptDeclaration('jQuery.noConflict()'); $document->addScript('path/to/jquery.js');
$document = JFactory::getDocument(); $document->addScript('path/to/jquery.js'); $document->addScript('path/to/jquery.noconflict.js');
In this example, jquery.noconflict.js contains the following code:
By doing this, it’s guaranteed that jQuery.noConflict() will get called immediately after jQuery is loaded by the browser. To recap, the ordering of MooTools and jQuery does not matter if you make sure jQuery.noConflict() is called immediately after jQuery is loaded. After you send jQuery into noConflict mode, you still must either use jQuery() instead of $(), or use one of the referencing methods described here in your jQuery-powered code.
But wait, I still have a thousand extensions all loading jQuery!
Fortunately, there’s an effort underway to standardize and document the use of jQuery in Joomla. If you’re willing to help out, join our Joomla People Group jump into the discussion. We should be able to document a way for extension developers to bundle a jQuery plugin with their extensions, as well as avoid version conflicts. Ultimately, a copy of jQuery should be installed and updated as necessary without the intervention of site administrators.
In January, my New Year’s resolution was to make more resolutions today: Chinese New Year. Solely because Chinese New Year is more than a month later.
So here goes:
- Go electronic/automatic with as much of my record keeping and business handling as possible. There are a lot of things I could be doing electronically but have still been doing on paper or through the mail. Also, I need to come up with a better system for handling recurring tasks and scheduling. If it comes down to it, I may end up with one of these or these. (sigh)
- Rewrite the Daily Message tutorials, Podcast Suite, iWebCal, and my book to catch up with Joomla! updates. The latter should come out first.
- Validate all of the markup on jlleblanc.com. Last year, I finally got on the whole semantic web bandwagon and haven’t fallen off yet. What was the catalyst for all of this? jQuery. When I saw how it was all CSS selector-based, DOM programming and the benefits of validated markup simultaneously made sense. The pursuit of validation is also helping me maintain Section 508 compliance at work.
- Blog more and worry less about writing essays. When I started blogging, I actually wanted to start a site where I would keep a repository of opinions on specific topics, refined over time. This doesn’t really seem to work as people are much more familiar with off-the-cuff blog posts.
- Launch a major web-based service. Oh, so you’d like to know what’s cooking at Chez LeBlanc? You’ll just have to wait and see
Flot – Want to build dynamic graphs without using Flash? Flot is ready. It’s lightweight and pretty quick to pick up. I’m using it for a project where people can add and remove as many data series as they wish. Throw in some JSON calls and the results are pretty impressive. Although I can’t show off that project here, take a look at some of the posted examples. It’s based on jQuery and produced by a Danish firm.
MacFUSE and SSHFS – One of the biggest problems I’ve run into with using Macs is that Finder cannot mount FTP and SFTP sites as writable volumes. While you can get clients like CyberDuck that will allow you to do transfers, editing the files for an entire website this way can be tedious. Using MacFUSE and SSHFS together can get around this limitation. SSHFS is still in a very early release and I did run into some stability issues when mounted all day long, but the core functionality is there.