Markus Bopp

Preventing jQuery and MooTools conflicts in Joomla! on component level

Jquery and mootools are nice tools and Joomla! developers often like to use both. The drawback is that mootools must be loaded before jquery in order to make sure there won't be conflicts. So far not a big deal, but without forcing mootools to be loaded first there is a good chance that your jquery code will conflict in certain situations.

To prevent that, just put this line at the top of your component entry point file (compname.php):

JHTML::_('behavior.mootools'); // this will make sure mootools loads first

Now in your jQuery app, return the jquery handle:

var jq = jQuery.noConflict(); // and use jq instead of $

or just

jQuery.noConflict();
// keep using $

Hope that helps and works for anyone out there looking for a simple and clear solution.

Views: 2942

Tags: Joomla, components, extensions, jquery, mootools

Mustaq Sheikh Comment by Mustaq Sheikh on February 26, 2010 at 1:10am
Has always been and will always be a big challenge ( proof if this are the signs of my approaching baldness )
Martin Rasser Comment by Martin Rasser on February 26, 2010 at 8:31am
This plugin helps dealing with MooTools/jQuery conflicts without any template tricks. It manipulates the order the scripts are loaded in the header in a quite clean way. jQuery will be available as $jquery, MooTools as $.

http://www.elovaris.at/en/downloads/jquery-includer
Anthony Olsen Comment by Anthony Olsen on February 26, 2010 at 4:36pm
I use this plugin too: http://www.joomlabamboo.com/joomla-extensions/free-joomla-extension...

What I'd love to see is a parameter for switching off jQuery in components and then if the punter is using multiple modules and components that use jQuery that can control it at a system level rather than a component by component basis.
Marie-Anne Melis Comment by Marie-Anne Melis on April 16, 2011 at 2:58am
wow, this plugin really works well and cured my template problems.

Comment

You need to be a member of All Together, As A Whole to add comments!

Join All Together, As A Whole

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service