fastclick
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "fastclick", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "lib/fastclick.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
/** | ||
* @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. | ||
* | ||
* @version 1.0.0 | ||
* @version 1.0.1 | ||
* @codingstandard ftlabs-jsv2 | ||
@@ -19,7 +19,9 @@ * @copyright The Financial Times Limited [All Rights Reserved] | ||
* @param {Element} layer The layer to listen on | ||
* @param {Object} options The options to override the defaults | ||
*/ | ||
function FastClick(layer) { | ||
function FastClick(layer, options) { | ||
'use strict'; | ||
var oldOnClick; | ||
options = options || {}; | ||
@@ -35,3 +37,3 @@ /** | ||
/** | ||
* Timestamp for when when click tracking started. | ||
* Timestamp for when click tracking started. | ||
* | ||
@@ -80,3 +82,3 @@ * @type number | ||
*/ | ||
this.touchBoundary = 10; | ||
this.touchBoundary = options.touchBoundary || 10; | ||
@@ -91,2 +93,9 @@ | ||
/** | ||
* The minimum time between tap(touchstart and touchend) events | ||
* | ||
* @type number | ||
*/ | ||
this.tapDelay = options.tapDelay || 200; | ||
if (FastClick.notNeeded(layer)) { | ||
@@ -101,14 +110,21 @@ return; | ||
var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; | ||
var context = this; | ||
for (var i = 0, l = methods.length; i < l; i++) { | ||
context[methods[i]] = bind(context[methods[i]], context); | ||
} | ||
// Set up event handlers as required | ||
if (deviceIsAndroid) { | ||
layer.addEventListener('mouseover', bind(this.onMouse, this), true); | ||
layer.addEventListener('mousedown', bind(this.onMouse, this), true); | ||
layer.addEventListener('mouseup', bind(this.onMouse, this), true); | ||
layer.addEventListener('mouseover', this.onMouse, true); | ||
layer.addEventListener('mousedown', this.onMouse, true); | ||
layer.addEventListener('mouseup', this.onMouse, true); | ||
} | ||
layer.addEventListener('click', bind(this.onClick, this), true); | ||
layer.addEventListener('touchstart', bind(this.onTouchStart, this), false); | ||
layer.addEventListener('touchmove', bind(this.onTouchMove, this), false); | ||
layer.addEventListener('touchend', bind(this.onTouchEnd, this), false); | ||
layer.addEventListener('touchcancel', bind(this.onTouchCancel, this), false); | ||
layer.addEventListener('click', this.onClick, true); | ||
layer.addEventListener('touchstart', this.onTouchStart, false); | ||
layer.addEventListener('touchmove', this.onTouchMove, false); | ||
layer.addEventListener('touchend', this.onTouchEnd, false); | ||
layer.addEventListener('touchcancel', this.onTouchCancel, false); | ||
@@ -418,3 +434,3 @@ // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) | ||
// Prevent phantom clicks on fast double-tap (issue #36) | ||
if ((event.timeStamp - this.lastClickTime) < 200) { | ||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { | ||
event.preventDefault(); | ||
@@ -507,3 +523,3 @@ } | ||
// Prevent phantom clicks on fast double-tap (issue #36) | ||
if ((event.timeStamp - this.lastClickTime) < 200) { | ||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { | ||
this.cancelNextClick = true; | ||
@@ -558,3 +574,4 @@ return true; | ||
// Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. | ||
if (!deviceIsIOS4 || targetTagName !== 'select') { | ||
// Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) | ||
if (!deviceIsIOS || targetTagName !== 'select') { | ||
this.targetElement = null; | ||
@@ -761,6 +778,7 @@ event.preventDefault(); | ||
* @param {Element} layer The layer to listen on | ||
* @param {Object} options The options to override the defaults | ||
*/ | ||
FastClick.attach = function(layer) { | ||
FastClick.attach = function(layer, options) { | ||
'use strict'; | ||
return new FastClick(layer); | ||
return new FastClick(layer, options); | ||
}; | ||
@@ -767,0 +785,0 @@ |
{ | ||
"name": "fastclick", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Polyfill to remove click delays on browsers with touch UIs.", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -34,18 +34,10 @@ # FastClick # | ||
Same goes for Chrome on Android (all versions) with `user-scalable=no` in the viewport meta tag. But be aware that `user-scalable=no` also disables pinch zooming, which may be an accessibility concern. | ||
```html | ||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
``` | ||
For IE10, you can use `-ms-touch-action: none` to disable double-tap-to-zoom on certain elements (like links and buttons) as described in [this MSDN blog post](http://blogs.msdn.com/b/askie/archive/2013/01/06/how-to-implement-the-ms-touch-action-none-property-to-disable-double-tap-zoom-on-touch-devices.aspx). For example: | ||
Same goes for Chrome on Android (all versions) with `user-scalable=no` in the viewport meta tag. But be aware that `user-scalable=no` also disables pinch zooming, which may be an accessibility concern. | ||
```css | ||
a, input, button { | ||
-ms-touch-action: none !important; | ||
} | ||
``` | ||
For IE10, you can use `-ms-touch-action: none` to disable double-tap-to-zoom on certain elements (like links and buttons) as described in [this MSDN blog post](http://blogs.msdn.com/b/askie/archive/2013/01/06/how-to-implement-the-ms-touch-action-none-property-to-disable-double-tap-zoom-on-touch-devices.aspx). | ||
You'll then have no tap delay on those elements, without needing FastClick. | ||
## Usage ## | ||
@@ -92,4 +84,9 @@ | ||
FastClick has AMD (Asynchronous Module Definition) support. This allows it to be lazy-loaded with an AMD loader, such as [RequireJS](http://requirejs.org/). | ||
FastClick has AMD (Asynchronous Module Definition) support. This allows it to be lazy-loaded with an AMD loader, such as [RequireJS](http://requirejs.org/). Note that when using the AMD style require, the full `FastClick` object will be returned, _not_ `FastClick.attach` | ||
```js | ||
var FastClick = require('fastclick'); | ||
FastClick.attach(document.body); | ||
``` | ||
### Package managers ### | ||
@@ -96,0 +93,0 @@ |
39809
691
134