Skip to content

Commit a463b44

Browse files
JS-493: Double click doesn't work on mobile
1 parent 86d4f38 commit a463b44

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/web/magnifier/magnify.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define([
3030
dragFlag,
3131
endX,
3232
transitionActive = false,
33+
tapFlag = 0,
3334
allowZoomOut = false,
3435
allowZoomIn = true;
3536

@@ -112,7 +113,7 @@ define([
112113

113114
function resetVars($image) {
114115
allowZoomIn = true;
115-
allowZoomOut = dragFlag = false;
116+
allowZoomOut = dragFlag = transitionActive = false;
116117
$image.hasClass(imageDraggableClass) && $image.removeClass(imageDraggableClass);
117118
toggleZoomable($image, false);
118119
}
@@ -593,6 +594,17 @@ define([
593594
}
594595
}
595596

597+
function detectDoubleTap (e) {
598+
var now = new Date().getTime(),
599+
timesince = now - tapFlag;
600+
601+
if (timesince < 500 && timesince > 0) {
602+
transitionActive = false;
603+
dblClickHandler(e);
604+
}
605+
tapFlag = new Date().getTime();
606+
}
607+
596608
$image.unbind('dblclick');
597609
$image.dblclick(dblClickHandler);
598610

@@ -763,6 +775,13 @@ define([
763775
}
764776
});
765777

778+
isTouchEnabled && $image.off('touchend');
779+
isTouchEnabled && $image.on('touchend', function (e) {
780+
if (e.originalEvent.touches.length === 0) {
781+
detectDoubleTap(e);
782+
}
783+
});
784+
766785
$(window).resize(function () {
767786
toggleZoomButtons($image, isTouchEnabled, checkForVideo(fotorama.activeFrame.$stageFrame));
768787
calculateMinSize($image);

0 commit comments

Comments
 (0)