Allow configuring cancelling synthetic click behavior (#5536)

This commit is contained in:
Lars den Bakker
2019-05-13 09:06:52 -07:00
committed by Tim van der Lippe
parent a7cb0ae086
commit 9a8bca4954
2 changed files with 24 additions and 3 deletions
+8 -3
View File
@@ -226,6 +226,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
function ignoreMouse(e) {
if (!Polymer.cancelSyntheticClickEvents) {
return;
}
if (!POINTERSTATE.mouse.mouseIgnoreJob) {
setupTeardownMouseCanceller(true);
}
@@ -335,9 +338,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
stateObj.upfn = null;
}
// use a document-wide touchend listener to start the ghost-click prevention mechanism
// Use passive event listeners, if supported, to not affect scrolling performance
document.addEventListener('touchend', ignoreMouse, SUPPORTS_PASSIVE ? {passive: true} : false);
if (Polymer.cancelSyntheticClickEvents) {
// use a document-wide touchend listener to start the ghost-click prevention mechanism
// Use passive event listeners, if supported, to not affect scrolling performance
document.addEventListener('touchend', ignoreMouse, SUPPORTS_PASSIVE ? {passive: true} : false);
}
/**
* Module for adding listeners to a node for the following normalized
+16
View File
@@ -122,5 +122,21 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.setLegacyOptimizations = function(useLegacyOptimizations) {
Polymer.legacyOptimizations = useLegacyOptimizations;
};
Polymer.cancelSyntheticClickEvents = typeof Polymer.cancelSyntheticClickEvents === 'boolean'
? Polymer.cancelSyntheticClickEvents : true;
/**
* Sets `setCancelSyntheticEvents` globally for all elements to cancel synthetic click events
* fired by older mobile browsers. Modern browsers no longer fire synthetic click events, and
* the cancellation behavior can interfere when programmatically clicking on elements.
*
* @param {boolean} useCancelSyntheticClickEvents enable or disable cancelling synthetic
* events
* @return {void}
*/
Polymer.setCancelSyntheticClickEvents = function(useCancelSyntheticClickEvents) {
Polymer.cancelSyntheticClickEvents = useCancelSyntheticClickEvents;
};
})();
</script>