Question

I'm using drupal commerce kickstart for my e-commerce site and I'm very happy of its flexibility about variation types and more.

I want to use a zoom script for my images like ebay and I found more than one that could be good for my scope but I see there's something wrong with the product page: when I change a variation type there's an AJAX script that loads the variation images in the same windows without a refresh of the whole page, the consquence of this is that the scripts are not reloaded and the images doesn't have the effect desired.

The problem happens only with third party zooming plugins, not with the default cloud_zoom plugin used by commerce kickstart releases.

Thanks for any future help!

Was it helpful?

Solution

Use behaviors:

Drupal.behaviors.myModule = {
  attach: function(context, settings) {
    $('#img-id', context).once('my-module').applyZoomPlugin();
  }
};

Kickstart does things properly and also hooks into behaviors, so once any AJAX request has completed on the page, your attach method will be invoked. To make sure an individual image element doesn't get the plugin applied multiple times, for example if AJAX is used elsewhere non the page, unrelated to the product image, use once() as above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top