Skip to content

Commit

Permalink
Allow configuring cancelling synthetic click behavior (#5536)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsDenBakker authored and TimvdLippe committed May 13, 2019
1 parent a7cb0ae commit 9a8bca4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/utils/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
}

function ignoreMouse(e) {
if (!Polymer.cancelSyntheticClickEvents) {
return;
}
if (!POINTERSTATE.mouse.mouseIgnoreJob) {
setupTeardownMouseCanceller(true);
}
Expand Down Expand Up @@ -335,9 +338,11 @@
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
Expand Down
16 changes: 16 additions & 0 deletions lib/utils/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,21 @@
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>

0 comments on commit 9a8bca4

Please sign in to comment.