-
AuthorPosts
-
Blaine Friend
Blaine
- Join date:
- August 2007
- Posts:
- 1443
- Downloads:
- 0
- Uploads:
- 25
- Thanks:
- 98
- Thanked:
- 177 times in 154 posts
September 2, 2011 at 2:26 pm #168107The core issue has to do with the way JDocument adds JavaScript to the HTML document. As you call JDocument::addScript(), JDocument makes an internal list of all the JavaScript files it needs to load.
Joomla loads all of your external scripts first, then loads all of your script declarations.
To solve the problem and not worry about MooTools, you need to first create a JavaScript file with the code jQuery.noConflict();. Then you need to load jQuery, then load the file containing the jQuery.noConflict(); code.
Your code in would look like this:
$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:
jQuery.noConflict();
This file would be best to load in your index.php file, directly after the head tag as follows:
<head>
<script src="prototype.js"></script> <script src="jquery.js"></script>See this great post by Phil on how to add in the head code if you can’t find an index.php file in your template.
By doing this,you guarantee that jQuery.noConflict() will get called immediately after jQuery is loaded by the browser.
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 code.
Each Joomla site should be loading either 0 or 1 copy of jQuery.
Having multiple copies of jQuery in a Joomla site puts site administrators in the position of having to manage conflicts. Also, distributing multiple copies of jQuery discourages the use of Google’s JavaScript library.
Realistically, site administrators just want all of their extensions to work. 🙂
jooservices Friendjooservices
- Join date:
- October 2014
- Posts:
- 8556
- Downloads:
- 0
- Uploads:
- 130
- Thanked:
- 1245 times in 1121 posts
September 6, 2011 at 10:01 am #410928Hi
This tip should be nice. I just wanna adding another thing:
– We should not use js compressor in this case or it should make trouble
– Do not include more than 1 instance jQuery on site. ( This one often happend since some exts using jQuery but dont check if jQuery included or not ) -
AuthorPosts
This topic contains 3 replies, has 2 voices, and was last updated by Blaine 13 years, 4 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum