News:

Looking for documentation? Take a look on our wiki

Main Menu

custom jquery code in vm2

Started by dimikere, February 14, 2013, 20:57:07 PM

Previous topic - Next topic

dimikere

hello, i want to write a jquery script in default_addtocart.php file!!
I wrote the script tags<script type="text/javascript"></script>  but didnt  run the code...
how can make it to run my jquery code?

PRO


here is an example of what I use

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
   jQuery(document).ready(function($) {
   $('.guest').hide();
   $('.creates').hide();
   });
");
?>

eriksimonx

joomla 2.5.9
vm 2.0.18a

Hi,

I trying to use a jquery script in      modules\mod_virtuemart_cart\tmpl\default.php . But its not working, neither with the code you wrote.

This is what I want: http://jsfiddle.net/eriksimon/UX4Ce/
My code

Quote$document = JFactory::getDocument();
$document->addScriptDeclaration('
   
   window.onload = function() {
function fadeContent() {
  $(".contentPanel .xcontent:hidden:first").fadeIn(500).delay(2000).fadeOut(500, function() {
    $(this).appendTo($(this).parent());
    fadeContent();
  });
}
fadeContent();
};

');




//dump ($cart,'mod cart');
// Ajax is displayed in vm_cart_products
// ALL THE DISPLAY IS Done by Ajax using "hiddencontainer" ?>

<!-- Virtuemart 2 Ajax Card -->
<div class="vmCartModule <?php echo $params->get('moduleclass_sfx'); ?>" id="vmCartModule">   


<div class="contentPanel">
      <div class="xcontent">
         <div>
<?php echo  $data->totalProductTxt ?>         </div>
      </div>
      <div class="xcontent">
         <div>
<?php if ($data->totalProduct and $show_price) echo  $data->billTotal; ?>         </div>
      </div>
   </div>

PRO

is the code in the head of the document?

eriksimonx

There is no head tag in default.php, but even if I make the tag and put the code into that, it doesnt work.

eriksimonx

Okay, so I put this code to mytemplate/index.php 's <head>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script type="text/javascript">
 
   window.onload = function() {
function fadeContent() {
  $(".contentPanel .xcontent:hidden:first").fadeIn(500).delay(2000).fadeOut(500, function() {
    $(this).appendTo($(this).parent());
    fadeContent();
  });
}
fadeContent();
};
</script>


It wasn't enough so I disabled the virtuemart jQuery in the joomla administration. Now, It works but my slider is dissappeared and my cart became unusable.

vm jquery on = no custom jquery code
vm jQ off = cm jQ code ok, no slider, bad cart
cm jQ code without jquery src = slider ok, no cm jQ code

PRO

when I say head. I mean when you view source

eriksimonx

I found the solution to avoid jQuery conflicts!

Just to wrap your jq script in a self-invoking function.

(function($){
   $(document).ready(function(){

      $('div').click( function(){ alert('ding'); });

   });
})(jQuery);

This creates a private scope so you don't have to worry about any collisions. You can skip all the uneasyness with the jQuery.noConflict(); solution and you don't have to give up that wonderful $! I do this as a matter of habbit when I know there are other chunks of code at work (eg, any cms) - even if a new extension is added after my testing, it shouldn't break my jQuery.

There's a great overview in the jQuery Cookbook (chapter 1.17).