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 f745862
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 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 @@ -67,8 +68,24 @@ export default class ImageGallery {
});
}


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 f745862

Please sign in to comment.