Do not propagate click if the event is handled
This commit is contained in:
parent
de150c0105
commit
fbb4d71b1c
7 changed files with 70 additions and 1 deletions
2
dist/pinch-zoom-min.js
vendored
2
dist/pinch-zoom-min.js
vendored
File diff suppressed because one or more lines are too long
13
dist/pinch-zoom.cjs.js
vendored
13
dist/pinch-zoom.cjs.js
vendored
|
@ -76,6 +76,7 @@ function createPoint() {
|
||||||
const MIN_SCALE = 0.01;
|
const MIN_SCALE = 0.01;
|
||||||
const ALLOW_PAN_MIN_SCALE = -1;
|
const ALLOW_PAN_MIN_SCALE = -1;
|
||||||
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
||||||
|
const BUTTON_LEFT = 0;
|
||||||
const roundedCmp = (a, b) => {
|
const roundedCmp = (a, b) => {
|
||||||
return Math.round(a * 100) - Math.round(b * 100);
|
return Math.round(a * 100) - Math.round(b * 100);
|
||||||
};
|
};
|
||||||
|
@ -114,6 +115,7 @@ class PinchZoom extends HTMLElement {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addEventListener('wheel', event => this._onWheel(event));
|
this.addEventListener('wheel', event => this._onWheel(event));
|
||||||
|
this.addEventListener('click', event => this._onClick(event, pointerTracker));
|
||||||
}
|
}
|
||||||
static get observedAttributes() { return [minScaleAttr]; }
|
static get observedAttributes() { return [minScaleAttr]; }
|
||||||
attributeChangedCallback(name, oldValue, newValue) {
|
attributeChangedCallback(name, oldValue, newValue) {
|
||||||
|
@ -438,6 +440,17 @@ class PinchZoom extends HTMLElement {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_onClick(event, pointerTracker) {
|
||||||
|
// We never handle non-left-clicks
|
||||||
|
if (event.button !== BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const wasPanning = pointerTracker.currentPointers.length === 0;
|
||||||
|
const handled = !(wasPanning && !this._allowPan());
|
||||||
|
if (handled) {
|
||||||
|
this._maybeStopPropagate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('pinch-zoom', PinchZoom);
|
customElements.define('pinch-zoom', PinchZoom);
|
||||||
|
|
1
dist/pinch-zoom.d.ts
vendored
1
dist/pinch-zoom.d.ts
vendored
|
@ -64,5 +64,6 @@ export default class PinchZoom extends HTMLElement {
|
||||||
private _maybeStopPropagate;
|
private _maybeStopPropagate;
|
||||||
private _allowPan;
|
private _allowPan;
|
||||||
private _maybeEmitCancel;
|
private _maybeEmitCancel;
|
||||||
|
private _onClick;
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|
13
dist/pinch-zoom.es.js
vendored
13
dist/pinch-zoom.es.js
vendored
|
@ -72,6 +72,7 @@ function createPoint() {
|
||||||
const MIN_SCALE = 0.01;
|
const MIN_SCALE = 0.01;
|
||||||
const ALLOW_PAN_MIN_SCALE = -1;
|
const ALLOW_PAN_MIN_SCALE = -1;
|
||||||
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
||||||
|
const BUTTON_LEFT = 0;
|
||||||
const roundedCmp = (a, b) => {
|
const roundedCmp = (a, b) => {
|
||||||
return Math.round(a * 100) - Math.round(b * 100);
|
return Math.round(a * 100) - Math.round(b * 100);
|
||||||
};
|
};
|
||||||
|
@ -110,6 +111,7 @@ class PinchZoom extends HTMLElement {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addEventListener('wheel', event => this._onWheel(event));
|
this.addEventListener('wheel', event => this._onWheel(event));
|
||||||
|
this.addEventListener('click', event => this._onClick(event, pointerTracker));
|
||||||
}
|
}
|
||||||
static get observedAttributes() { return [minScaleAttr]; }
|
static get observedAttributes() { return [minScaleAttr]; }
|
||||||
attributeChangedCallback(name, oldValue, newValue) {
|
attributeChangedCallback(name, oldValue, newValue) {
|
||||||
|
@ -434,6 +436,17 @@ class PinchZoom extends HTMLElement {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_onClick(event, pointerTracker) {
|
||||||
|
// We never handle non-left-clicks
|
||||||
|
if (event.button !== BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const wasPanning = pointerTracker.currentPointers.length === 0;
|
||||||
|
const handled = !(wasPanning && !this._allowPan());
|
||||||
|
if (handled) {
|
||||||
|
this._maybeStopPropagate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('pinch-zoom', PinchZoom);
|
customElements.define('pinch-zoom', PinchZoom);
|
||||||
|
|
13
dist/pinch-zoom.js
vendored
13
dist/pinch-zoom.js
vendored
|
@ -257,6 +257,7 @@ var PinchZoom = (function () {
|
||||||
const MIN_SCALE = 0.01;
|
const MIN_SCALE = 0.01;
|
||||||
const ALLOW_PAN_MIN_SCALE = -1;
|
const ALLOW_PAN_MIN_SCALE = -1;
|
||||||
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
||||||
|
const BUTTON_LEFT = 0;
|
||||||
const roundedCmp = (a, b) => {
|
const roundedCmp = (a, b) => {
|
||||||
return Math.round(a * 100) - Math.round(b * 100);
|
return Math.round(a * 100) - Math.round(b * 100);
|
||||||
};
|
};
|
||||||
|
@ -295,6 +296,7 @@ var PinchZoom = (function () {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addEventListener('wheel', event => this._onWheel(event));
|
this.addEventListener('wheel', event => this._onWheel(event));
|
||||||
|
this.addEventListener('click', event => this._onClick(event, pointerTracker));
|
||||||
}
|
}
|
||||||
static get observedAttributes() { return [minScaleAttr]; }
|
static get observedAttributes() { return [minScaleAttr]; }
|
||||||
attributeChangedCallback(name, oldValue, newValue) {
|
attributeChangedCallback(name, oldValue, newValue) {
|
||||||
|
@ -619,6 +621,17 @@ var PinchZoom = (function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_onClick(event, pointerTracker) {
|
||||||
|
// We never handle non-left-clicks
|
||||||
|
if (event.button !== BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const wasPanning = pointerTracker.currentPointers.length === 0;
|
||||||
|
const handled = !(wasPanning && !this._allowPan());
|
||||||
|
if (handled) {
|
||||||
|
this._maybeStopPropagate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('pinch-zoom', PinchZoom);
|
customElements.define('pinch-zoom', PinchZoom);
|
||||||
|
|
13
dist/pinch-zoom.mjs
vendored
13
dist/pinch-zoom.mjs
vendored
|
@ -72,6 +72,7 @@ function createPoint() {
|
||||||
const MIN_SCALE = 0.01;
|
const MIN_SCALE = 0.01;
|
||||||
const ALLOW_PAN_MIN_SCALE = -1;
|
const ALLOW_PAN_MIN_SCALE = -1;
|
||||||
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
||||||
|
const BUTTON_LEFT = 0;
|
||||||
const roundedCmp = (a, b) => {
|
const roundedCmp = (a, b) => {
|
||||||
return Math.round(a * 100) - Math.round(b * 100);
|
return Math.round(a * 100) - Math.round(b * 100);
|
||||||
};
|
};
|
||||||
|
@ -110,6 +111,7 @@ class PinchZoom extends HTMLElement {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.addEventListener('wheel', event => this._onWheel(event));
|
this.addEventListener('wheel', event => this._onWheel(event));
|
||||||
|
this.addEventListener('click', event => this._onClick(event, pointerTracker));
|
||||||
}
|
}
|
||||||
static get observedAttributes() { return [minScaleAttr]; }
|
static get observedAttributes() { return [minScaleAttr]; }
|
||||||
attributeChangedCallback(name, oldValue, newValue) {
|
attributeChangedCallback(name, oldValue, newValue) {
|
||||||
|
@ -434,6 +436,17 @@ class PinchZoom extends HTMLElement {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_onClick(event, pointerTracker) {
|
||||||
|
// We never handle non-left-clicks
|
||||||
|
if (event.button !== BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const wasPanning = pointerTracker.currentPointers.length === 0;
|
||||||
|
const handled = !(wasPanning && !this._allowPan());
|
||||||
|
if (handled) {
|
||||||
|
this._maybeStopPropagate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('pinch-zoom', PinchZoom);
|
customElements.define('pinch-zoom', PinchZoom);
|
||||||
|
|
|
@ -91,6 +91,8 @@ const MIN_SCALE = 0.01;
|
||||||
const ALLOW_PAN_MIN_SCALE = -1;
|
const ALLOW_PAN_MIN_SCALE = -1;
|
||||||
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
const RESET_TO_MIN_SCALE_LIMIT = -1;
|
||||||
|
|
||||||
|
const BUTTON_LEFT = 0;
|
||||||
|
|
||||||
const roundedCmp = (a: number, b: number) => {
|
const roundedCmp = (a: number, b: number) => {
|
||||||
return Math.round(a * 100) - Math.round(b * 100)
|
return Math.round(a * 100) - Math.round(b * 100)
|
||||||
}
|
}
|
||||||
|
@ -142,6 +144,7 @@ export default class PinchZoom extends HTMLElement {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addEventListener('wheel', event => this._onWheel(event));
|
this.addEventListener('wheel', event => this._onWheel(event));
|
||||||
|
this.addEventListener('click', event => this._onClick(event, pointerTracker));
|
||||||
}
|
}
|
||||||
|
|
||||||
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
||||||
|
@ -552,4 +555,17 @@ export default class PinchZoom extends HTMLElement {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _onClick(event: MouseEvent, pointerTracker: PointerTracker) {
|
||||||
|
// We never handle non-left-clicks
|
||||||
|
if (event.button !== BUTTON_LEFT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const wasPanning = pointerTracker.currentPointers.length === 0;
|
||||||
|
const handled = !(wasPanning && !this._allowPan());
|
||||||
|
if (handled) {
|
||||||
|
this._maybeStopPropagate(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue