I have created a page that displays a product list from a database on my home page. When the user clicks on any of the products, a modal is opened and this modal contains product info, as well as a image gallery.
$product_handler = new Product ($cao);
$products = $product_handler->getProducts();
if($products) {
/* @var $prod Product */
foreach ($products as $key => $prod) {
?>
<div class="col-md-4" style="overflow: hidden;">
<img class="image-modal" data-toggle="modal" style="width: 192px; height:192px;" data-target="#<?php echo $prod->prod_name;?>Modal" src="<?php echo $prod->prod_icon; ?>">
<a data-toggle="modal" data-id="<?php echo $prod->prod_name ?>" data-target="#<?php echo $prod->prod_name;?>Modal" class="image_modal"><h2 style='color:#2468A6'><b><?php echo $prod->prod_name ?></b></h2></a>
</div>
<!--------Modal starts here-------->
<?php
$pres_path= "dub/place/folder/Presentation.php";
include $pres_path;
?>
<?php
}
}
Then within the Presentation.php file the modal is called and this contains all the product info and the image gallery.The page also contains a big chunk of javascript used to navigate the images in the gallery.
In this javascript section I have a variable that is used to determine what the current image is.
<script>
var currentImage = 1;
$('a.galleryBullet' + currentImage).addClass("active");
$('a.thumbnailsimage' + currentImage).addClass("active");
$('div.description' + currentImage).addClass("visible");
//Previous Arrow
$('a.previousSlideArrow').click(function () {
$('img.previewImage' + currentImage).hide();
$('a.galleryBullet' + currentImage).removeClass("active");
$('a.thumbnailsimage' + currentImage).removeClass("active");
$('div.description' + currentImage).removeClass("visible");
currentImage--;
if (currentImage == 0) {
currentImage = imagesTotal;
}
$('img.previewImage' + currentImage).show();
$('a.galleryBullet' + currentImage).addClass("active");
$('a.thumbnailsimage' + currentImage).addClass("active");
$('div.description' + currentImage).addClass("visible");
return false;
});
</script>
The problem I have is that when I click on one product and navigate the gallery,and then close the modal and select another product. It continues on the same number as the one I ended on in the previous modal.
In example. In modal 1 there is 5 slides and I close the modal on slide no. 3.If I then open modal 2 which contains 7 slides. I will start on slide no. 3
The reason for this I think, is because the variable currentImage is used by all of the modals. And thus, problems arise
My question is,
How can I make sure that each time a product is clicked, that the variable currentImage is set to 1