Skip to content

Commit

Permalink
fix(catalog): MERC-3743 Fix zoom behavior for small images in gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Chu committed Aug 7, 2018
1 parent 5dfd090 commit 62dc130
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions assets/js/theme/product/image-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import $ from 'jquery';
import 'easyzoom';
import _ from 'lodash';


export default class ImageGallery {
constructor($gallery) {
this.$mainImage = $gallery.find('[data-image-gallery-main]');
Expand Down Expand Up @@ -39,9 +40,9 @@ export default class ImageGallery {
}
}


selectNewImage(e) {
e.preventDefault();

const $target = $(e.currentTarget);
const imgObj = {
mainImageUrl: $target.attr('data-image-gallery-new-image-url'),
Expand All @@ -63,12 +64,27 @@ export default class ImageGallery {
this.easyzoom.data('easyZoom').swap(this.currentImage.mainImageUrl, this.currentImage.zoomImageUrl);

this.$mainImage.attr({
'data-zoom-image': this.currentImage.zoomImageUrl,
});
'data-zoom-image': this.currentImage.zoomImageUrl,
});
}


checkImage(){
const containerHeight = $(".productView-image").height()
const containerWidth = $(".productView-image").width()
const height = this.easyzoom.data('easyZoom').$zoom.context.height
const width = this.easyzoom.data('easyZoom').$zoom.context.width
if (height < containerHeight || width < containerWidth) {
this.easyzoom.data('easyZoom').hide();
}
}


setImageZoom() {
this.easyzoom = this.$mainImage.easyZoom({ errorNotice: '', loadingNotice: '' });
this.easyzoom = this.$mainImage.easyZoom({
onShow: () => this.checkImage(),
errorNotice: '',
loadingNotice: ''});
}

bindEvents() {
Expand Down

0 comments on commit 62dc130

Please sign in to comment.