// Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
// Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
// Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
// Prevent the actual click from going though - unless the target node is marked as requiring
// real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
if(!this.needsClick(targetElement)){
event.preventDefault();
this.sendClick(targetElement,event);
event.preventDefault()
this.sendClick(targetElement,event)
}
returnfalse;
};
returnfalse
}
/**
* On touch cancel, stop tracking the click.
*
* @returns {void}
*/
FastClick.prototype.onTouchCancel=function(){
this.trackingClick=false;
this.targetElement=null;
};
FastClick.prototype.onTouchCancel=function(){
this.trackingClick=false
this.targetElement=null
}
/**
* Determine mouse events which should be permitted.
...
...
@@ -632,20 +631,20 @@
* @param {Event} event
* @returns {boolean}
*/
FastClick.prototype.onMouse=function(event){
FastClick.prototype.onMouse=function(event){
// If a target element was never set (because a touch event was never fired) allow the event
if(!this.targetElement){
returntrue;
returntrue
}
if(event.forwardedTouchEvent){
returntrue;
returntrue
}
// Programmatically generated events targeting a specific element should be permitted
if(!event.cancelable){
returntrue;
returntrue
}
// Derive and check the target element to see whether the mouse event needs to be permitted;
...
...
@@ -655,24 +654,23 @@
// Prevent any user-added listeners declared on FastClick element from being fired.
if(event.stopImmediatePropagation){
event.stopImmediatePropagation();
event.stopImmediatePropagation()
}else{
// Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
event.propagationStopped=true;
event.propagationStopped=true
}
// Cancel the event
event.stopPropagation();
event.preventDefault();
event.stopPropagation()
event.preventDefault()
returnfalse;
returnfalse
}
// If the mouse event is permitted, return true for the action to go through.
returntrue;
};
returntrue
}
/**
* On actual clicks, determine whether this is a touch-generated click, a click action occurring
...
...
@@ -682,112 +680,110 @@
* @param {Event} event
* @returns {boolean}
*/
FastClick.prototype.onClick=function(event){
varpermitted;
FastClick.prototype.onClick=function(event){
varpermitted
// It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
if(this.trackingClick){
this.targetElement=null;
this.trackingClick=false;
returntrue;
this.targetElement=null
this.trackingClick=false
returntrue
}
// Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
// Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
if(!permitted){
this.targetElement=null;
this.targetElement=null
}
// If clicks are permitted, return true for the action to go through.