views:

1810

answers:

4

Hi,

I use jquery for a module. My joomla template have an integrated jquery menu. So they conflict with each other.

Is there a way to solve this problem. Following the script code of the module

<script type="text/javascript" charset="utf-8">
    window.onload = function () {
        var container = jQuery('div.sliderGallery');
         var ul = jQuery('ul', container);

         var itemsWidth = ul.innerWidth() - container.outerWidth();

         jQuery('.slider', container).slider({
             min: 0,
             max: itemsWidth,
             handle: '.handle',
             stop: function (event, ui) {
                 ul.animate({'left' : ui.value * -1},340);
             },
             slide: function (event, ui) {
                 ul.css('left', ui.value * -1);
             }
         });
     };
</script>
A: 

try

var J = jQuery.noConflict();

after that use J variable instead of $ or jQuery for your custom code

mkoryak
This answer isn't good enough. you have to specify what library you want to re-map to use "J". writing this in the wrong place can result different outcomes.
vsync
i have no idea why you mean. explain.
mkoryak
A: 

try

jQuery.noConflict();

e.g

<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        var container = jQuery('div.sliderGallery');
         var ul = jQuery('ul', container);

         var itemsWidth = ul.innerWidth() - container.outerWidth();
         jQuery.noConflict();
         jQuery('.slider', container).slider({
             min: 0,
             max: itemsWidth,
             handle: '.handle',
             stop: function (event, ui) {
                 ul.animate({'left' : ui.value * -1},340);
             },
             slide: function (event, ui) {
                 ul.css('left', ui.value * -1);
             }
         });
     });
</script>

I have updated your code to use jQuery to check for document loaded. Details for using the noConflict function is here.

AutomatedTester
I copy your code and paste it to my file but it dont change anything. Do I have to do something else?
+2  A: 

What you need to do to fix your problem is un-alias the jQuery function and assign it to another variable name (remember: variables can be functions). You need to use the jQuery.noConflict() function to un-alias the $() function. Here one one to do it:

// ...after all of Joomla's JS is done executing...

// before loading your version of jQuery var jquery = {}; // aka new Object()
jquery.joomla = jQuery.noConflict(); // moves jQuery into another namespace

// load your version

Now, when you load your version, it will take over the jQuery and $ namespaces, but you'll still have the other reference to Joomla's jQuery function if you need it. To re-iterate, the basic flow is:

  1. Load Joomla's jQuery
  2. Run Joomla's jQuery-dependent code
  3. Move Joomla jQuery into another namespace
  4. Load your jQuery
  5. Execute your code using $()
daveslab
"Move Joomla jQuery into another namespace" - not such a good idea, because it might run somewhere later and look for the older namepace, instead, your should rename your new jQuery instead to j$.
vsync
A: 

did you mean that your joomla loaded 2 kind of jquery at the same time ? 1st your menu load jquery and then your module load jquery ?

here is the solutions: In joomla templates, we can overriding the module or component views (I assume you must be using joomla 1.5.x right?)

  1. in your templates create a directory called html/ eg: templates/yourTemplate/html/

  2. copy file from modules/mod_yourMenu/tmpl/.* into your your template html (templates/yourTemplate/html/mod_yourMenu/) --> * you don't need to add tmpl/ *

  3. edit the php files inside and delete all tag that load jquery

  4. do the step 1-3 for modules that using jquery.

  5. edit your template, put tag to load latest version of jquery.

it should work now :)

nightingale2k1
hm - it might work but what if you want to use this module on many sites. I have to do this steps every time. Do you know an other solution?