├── .eslintrc ├── .gitignore ├── History.md ├── LICENSE ├── Readme.md ├── bower.json ├── dist ├── touch-action.js └── touch-action.min.js ├── index.js └── package.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb/legacy", 3 | "rules": { 4 | "semi": [2, "never"], 5 | "no-use-before-define": [2, "nofunc"], 6 | "no-param-reassign": 0, 7 | "id-length": 0, 8 | "max-len": 0 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | ## 1.0.1 / 2016-02-20 2 | 3 | * add bower support 4 | * improve docs 5 | 6 | ## 1.0.0 / 2016-02-18 7 | 8 | * initial release 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Aleksey Kulikov (alekseykulikov.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # touch-action 2 | 3 | > Disable 300ms delay on mobile using CSS touch-action or asynchronously download FastClick as polyfill. 4 | 5 | [![](https://img.shields.io/npm/v/touch-action.svg)](https://npmjs.org/package/touch-action) 6 | 7 | [CSS touch-action property](http://caniuse.com/#search=touch-action) allows eliminate the 300ms delay between a physical tap and the firing of a click event on mobile browsers. It's supported by all major browsers including Safari 9.3. 8 | Therefore, there's no reason to always use [FastClick](https://github.com/ftlabs/fastclick) and include it to javascript bundle. 9 | 10 | This library is just [17 lines of code](./index.js) and 14x smaller than FastClick (2.68Kb vs 0.2Kb). It checks support of CSS `touch-action`, and sets `touch-action: manipulation` to document body. When `touch-action` property is not supported, it asynchronously downloads [FastClick](https://github.com/ftlabs/fastclick) from CDN and use `FastClick.attach(document.body)` as polyfill. 11 | 12 | This module is inspired by [gajus's gist](https://gist.github.com/gajus/bbf06ea2e37047b01e70). 13 | 14 | ## Installation 15 | 16 | npm install touch-action --save 17 | bower install touch-action 18 | 19 | Standalone version available as [dist/touch-action.min.js](./dist/touch-action.min.js). 20 | 21 | ```html 22 | 23 | 24 | ``` 25 | 26 | ## Example 27 | 28 | ```js 29 | import touchAction from 'touch-action' 30 | 31 | // use default behavior and download FastClick from CDN when needed 32 | // https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js 33 | touchAction() 34 | 35 | // use your own copy of FastClick 36 | touchAction({ src: '/assets/fastclick.min.js' }) 37 | ``` 38 | 39 | ## touchAction(opts) 40 | 41 | Init `touch-action` or download and attach `FastClick`. 42 | 43 | Available options: 44 | - `src` - custom path to fastclick (default: https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js) 45 | - `val` - specify [custom](https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action) touch-action value, but be careful, since FastClick enables only `manipulation` (default: `manipulation`) 46 | 47 | ## License 48 | 49 | [MIT]('./LICENSE') 50 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "touch-action", 3 | "version": "1.0.1", 4 | "description": "Disable 300ms delay on mobile using CSS touch-action when property is supported or asynchronously download FastClick as polyfill", 5 | "main": "dist/touch-action.js", 6 | "homepage": "https://github.com/alekseykulikov/touch-action", 7 | "authors": [ 8 | "Aleksey Kulikov" 9 | ], 10 | "license": "MIT", 11 | "keywords": [ 12 | "touch-action", 13 | "fastclick", 14 | "css", 15 | "300ms", 16 | "mobile" 17 | ], 18 | "ignore": [ 19 | "**/.*", 20 | "index.js" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /dist/touch-action.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.touchAction = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o dist/touch-action.js && uglifyjs dist/touch-action.js -m > dist/touch-action.min.js", 20 | "test": "eslint index.js" 21 | }, 22 | "devDependencies": { 23 | "browserify": "^13.0.0", 24 | "eslint": "^1.10.3", 25 | "eslint-config-airbnb": "^5.0.1", 26 | "uglify-js": "^2.6.1" 27 | } 28 | } 29 | --------------------------------------------------------------------------------