test
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Blaine Friend
    #168107

    The 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 Friend
    #410928

    Hi
    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 )

    Blaine Friend
    #410955

    Thanks Joo!
    I want invite any others to also add comments if you feel they will benefit!
    Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

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