0

I have joomla module, in the module I have this jquery script, I want to show this javascript from js file in the of joomla but there is problem php variable how can I make this?

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

var container = $('.carmrg <?php echo $uniqid; ?>');
var first     = container.find('.img-log img').eq(0);
var ori     = container.find('.img-log a').eq(0);

container.find('.cars-img img').attr('src', first.attr('src'));
container.find('.cars-img a').attr('href', ori.attr('href'));
first.addClass('active');
ori.addClass('active');

$('.img-log img').hover(function(){

    var $self  = $(this);
    var parent = $self.parents('.carmrg');

    parent.find('.cars-img img').attr('src', $self.attr('src'));
    parent.find('.img-log img').removeClass('active');
    $self.addClass('active');
});

$('.img-log a').hover(function(){

    var $self  = $(this);
    var parent = $self.parents('.carmrg');

    parent.find('.cars-img a').attr('href', $self.attr('href'));
    parent.find('.img-log a').removeClass('active');
    $self.addClass('active');
});

    lightbox.option({
  'showImageNumberLabel': false,
});

});

  • I don't quote understand what you're saying or trying to do. Could you try explaining in a little more detail please? – Lodder Apr 18 '16 at 17:34
  • sorry, for my bad english, ok – Gocha Gochitashvili Apr 18 '16 at 17:36
3

Assuming you are asking how to combine PHP and JavaScript, one way would be to add the JavaScript inline via your module's PHP using this method, which will add it to the head of the page when the module is loaded.

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration('
    jQuery(document).ready(function($){
        CONTENT HERE
    });
');
?>

If you need the js in a separate file, or the intention is to have multiple versions of this module on a page and this would create conflicts, then you could always search the DOM for any elements with a relevent class and create an array of their related IDs, which you can then loop through - not sure you need PHP for what you are trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.