Skip to content

Commit

Permalink
Fix Chrome 55+ mobile & new pad sensitivity option
Browse files Browse the repository at this point in the history
- fixed Chrome 55+ mobile pich/touch flickering bug timmywil#303
- fixed Chrome passive event warning timmywil#328
- add new otion "pan sensitivity"
  • Loading branch information
inuyaksa authored and Cecelia Wren committed Jun 1, 2017
1 parent 13ddd2a commit 2118363
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions dist/jquery.panzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@
// Pan only when the scale is greater than minScale
panOnlyWhenZoomed: false,

// Pan sensitivity, min pixels to start to panning
panSensitivity: 4,

// min and max zoom scales
minScale: 0.3,
maxScale: 6,
Expand Down Expand Up @@ -957,7 +960,7 @@
if (!options.disablePan || !options.disableZoom) {
events[ str_start ] = function(e) {
var touches;
if (e.type === 'touchstart' ?
if ( /touchstart|pointerdown/.test(e.type) ? // fix double events pointer/touch on Chrome >=55 #303
// Touch
(touches = e.touches || e.originalEvent.touches) &&
((touches.length === 1 && !options.disablePan) || touches.length === 2) :
Expand Down Expand Up @@ -1125,6 +1128,10 @@
if (this.panning) {
return;
}

var type = event.type;
if (window.PointerEvents&&(type === 'touchstart')) return false; // fix double events pointer/touch on Chrome >=55 #303

var moveEvent, endEvent,
startDistance, startScale, startMiddle,
startPageX, startPageY, touch;
Expand All @@ -1136,15 +1143,17 @@
var origPageX = +original[4];
var origPageY = +original[5];
var panOptions = { matrix: matrix, animate: 'skip' };
var type = event.type;

// Indicate that we are currently panning
//this.panning = true;

// Use proper events
if (type === 'pointerdown') {
moveEvent = 'pointermove';
endEvent = 'pointerup';
} else if (type === 'touchstart') {
moveEvent = 'touchmove';
endEvent = 'touchend';
endEvent = 'touchend';
} else if (type === 'MSPointerDown') {
moveEvent = 'MSPointerMove';
endEvent = 'MSPointerUp';
Expand All @@ -1160,9 +1169,6 @@
// Remove any transitions happening
this.transition(true);

// Indicate that we are currently panning
this.panning = true;

// Trigger start event
this._trigger('start', event, touches);

Expand Down Expand Up @@ -1196,7 +1202,8 @@

var move = function(e) {
var coords;
e.preventDefault();
//e.preventDefault(); // chrome passive event warning https://www.chromestatus.com/features/5093566007214080 #328
e.stopPropagation();
touches = e.touches || e.originalEvent.touches;
setStart(e, touches);

Expand Down Expand Up @@ -1230,6 +1237,11 @@
coords = e;
}

if (!self.panning) {
if ((Math.abs(coords.pageX-startPageX)<self.options.panSensitivity)&&(Math.abs(coords.pageY-startPageY)<self.options.panSensitivity)) return true;
}

self.panning = true;
self.pan(
origPageX + coords.pageX - startPageX,
origPageY + coords.pageY - startPageY,
Expand Down

0 comments on commit 2118363

Please sign in to comment.