From fdc6168c5120e5aea246a75fa82304a7a7adc920 Mon Sep 17 00:00:00 2001 From: Brewal Date: Thu, 5 Feb 2015 11:29:33 +0100 Subject: [PATCH] Prevent default on drag only when zoomed This changes allow the user to scroll the page on drag event on the target only when it is not zoomed. Otherwise, it prevents the default browser behaviour. --- src/e-smart-zoom-jquery.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/e-smart-zoom-jquery.js b/src/e-smart-zoom-jquery.js index 96363e3..0739eba 100644 --- a/src/e-smart-zoom-jquery.js +++ b/src/e-smart-zoom-jquery.js @@ -377,8 +377,6 @@ * @param {Object} e : touch event */ function touchStartHandler(e){ - e.preventDefault(); // prevent default browser drag - $(document).unbind('touchmove.smartZoom'); // unbind if we already listen touch events $(document).unbind('touchend.smartZoom'); @@ -408,7 +406,7 @@ */ function touchMoveHandler(e){ - e.preventDefault(); // prevent default browser behaviour + preventDefaultOnDrag(e); // prevent default browser behaviour when the target is zoomed var smartData = targetElement.data('smartZoomData'); @@ -456,6 +454,22 @@ } } + /** + * Prevent default browser behaviour on drag into the target only when it is zoomed + * + * @param {Event} e : the original touch event + */ + function preventDefaultOnDrag(e) { + var smartData = targetElement.data('smartZoomData'); + var targetRect = getTargetRect(); // the current plugin target size + var originSize = smartData.originalSize; // original plugin target size + var currentScale = (targetRect.width / originSize.width); + + if (currentScale !== 1) { + e.preventDefault(); + } + } + /** * manage touch move end or double tap at touch end * @param {Object} e : touch event