Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x configure cancel synthetic click #5535

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>