in _includes/scripts/lib/gallery.js [37:137]
Gallery.prototype.init = function() {
var i, item, items = this.items, size, self = this, touchstartFingerCount = 0;
this.$root.append(template);
this.$swiper = this.$root.find('.gallery__swiper');
this.$swiperWrapper = this.$root.find('.swiper__wrapper');
this.contentWidth = this.$swiperWrapper && this.$swiperWrapper.width();
this.contentHeight = this.$swiperWrapper && this.$swiperWrapper.height();
for (i = 0; i < items.length; i++) {
item = items[i];
size = this._calculateImageSize(item.w, item.h);
this.$items.push($(
'<div class="swiper__slide">' +
'<div class="gallery-item">' +
'<div class="gallery-item__content">' +
'<img src="' + item.src + '" style="width:' + size.w + 'px;height:' + size.h + 'px"/>' +
'</div>' +
'</div>' +
'</div>'
));
}
this.$swiperWrapper && this.$swiperWrapper.append(this.$items);
this.swiper = this.$swiper && this.$swiper.swiper({
onChangeEnd: function() {
self._handleChangeEnd.apply(self, Array.prototype.slice.call(arguments));
}
});
$(window).on('resize', function() {
if (self.disabled) { return; }
self._resizeImageSize();
});
// Char Code: 37 ⬅, 39 ➡
$(window).on('keyup', function(e) {
if (window.isFormElement(e.target || e.srcElement) || self.disabled) { return; }
if (e.which === 37) {
self.swiper && self.swiper.previous();
} else if (e.which === 39) {
self.swiper && self.swiper.next();
}
});
function getRect(touch0, touch1) {
return {
o: {
x: (touch0.pageX + touch1.pageX) / 2,
y: (touch0.pageY + touch1.pageY) / 2
},
w: Math.abs(touch0.pageX - touch1.pageX),
h: Math.abs(touch0.pageY - touch1.pageY)
};
}
function getTouches(e) {
return e.touches || e;
}
function getTouchesCount(e) {
if (e.touches) {
return e.touches.length;
} else {
return 1;
}
}
this.$swiperWrapper.on('touchstart', function(e) {
var touch0, touch1, rect;
touchstartFingerCount = getTouchesCount(e);
if (touchstartFingerCount > 1) {
touch0 = e.touches[0];
touch1 = e.touches[1];
rect = getRect(touch0, touch1);
self.lastZoomRect = { w: rect.w, h: rect.h };
self.lastTouchCenter = rect.o;
} else {
var touch = getTouches(e)[0];
self.lastTouchCenter = { x: touch.pageX, y: touch.pageY };
}
});
this.$swiperWrapper.on('touchmove', function(e) {
if (touchstartFingerCount === getTouchesCount(e)) {
if (touchstartFingerCount > 1) {
var touch0 = e.touches[0];
var touch1 = e.touches[1];
var rect = getRect(touch0, touch1);
self.zoomRect = { w: rect.w, h: rect.h };
self.touchCenter = rect.o;
self._zoom(); self._translate();
setState(self.$activeItem, self.zoom, self.translate);
} else {
var touch = getTouches(e)[0];
self.touchCenter = { x: touch.pageX, y: touch.pageY };
self._translate();
setState(self.$activeItem, self.zoom, self.translate);
}
}
});
this.$swiperWrapper.on('touchend', function(e) {
self.lastZoom = self.zoom;
self.lastTranslate = self.translate;
touchstartFingerCount = 0;
});
this.$root.on('touchmove', function(e) {
if (self.disabled) { return; }
e.preventDefault();
});
};