Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STENCIL-3106 Switch from jquery-zoom to easyzoom #1096

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions assets/js/theme/product/image-gallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from 'jquery';
import 'jquery-zoom';
import 'easyzoom';
import _ from 'lodash';

export default class ImageGallery {
Expand All @@ -17,10 +17,8 @@ export default class ImageGallery {
setMainImage(imgObj) {
this.currentImage = _.clone(imgObj);

this.destroyImageZoom();
this.setActiveThumb();
this.swapMainImage();
this.setImageZoom();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we still need to call setImageZoom. otherwise this.easyzoom will be undefined in swapMainImage, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we need to, as this zoom library works a bit differently than the old one. Now you just initialize it on an element (in this case the productView-image figure), and it manages swapping both the zoomed image and the normal-sized images. So the same easyzoom instance is actually sticking around as you swap images around.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i see - i completely missed that it's called from the init method.

}

setAlternateImage(imgObj) {
Expand Down Expand Up @@ -62,19 +60,15 @@ export default class ImageGallery {
}

swapMainImage() {
this.easyzoom.data('easyZoom').swap(this.currentImage.mainImageUrl, this.currentImage.zoomImageUrl);

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

setImageZoom() {
this.$mainImage.zoom({ url: this.$mainImage.attr('data-zoom-image'), touch: false });
}

destroyImageZoom() {
this.$mainImage.trigger('zoom.destroy');
this.easyzoom = this.$mainImage.easyZoom({ errorNotice: '', loadingNotice: '' });
}

bindEvents() {
Expand Down
17 changes: 17 additions & 0 deletions assets/scss/components/stencil/productView/_productView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
display: flex;
justify-content: center;
margin: 0;
position: relative;

@include breakpoint("medium") {
min-height: 366px;
Expand Down Expand Up @@ -389,3 +390,19 @@
.shareProduct {
text-align: center;
}


// EasyZoom settings for zoomable product image
// -----------------------------------------------------------------------------

.productView-image .easyzoom-flyout {
overflow: hidden;
position: absolute;
width: 100%;
height: 100%;

img {
max-width: none;
width: auto;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"@bigcommerce/stencil-utils": "^1.0.7",
"async": "^2.5.0",
"babel-polyfill": "^6.26.0",
"easyzoom": "^2.5.0",
"fastclick": "^1.0.6",
"foundation-sites": "^5.5.3",
"html5-history-api": "^4.2.7",
"jquery": "^2.2.4",
"jquery-zoom": "^1.7.15",
"jstree": "vakata/jstree",
"lazysizes": "3.0.0",
"lodash": "^4.17.4",
Expand Down