UNPKG

6.79 kBMarkdownView Raw
1![Quasar Framework logo](https://cdn.quasar.dev/logo/svg/quasar-logo-full-inline.svg)
2
3# Fastclick for Quasar Framework
4> This is a fork of the original Fastclick and is being used and maintained by Quasar Framework.
5> This is injected only for iOS platform (PWA or Cordova).
6
7FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a `click` event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
8
9FastClick is developed by [FT Labs](http://labs.ft.com/), part of the Financial Times.
10
11*Note: As of late 2015 most mobile browsers - notably Chrome and Safari - no longer have a 300ms touch delay, so fastclick offers no benefit on newer browsers, and risks introducing [bugs](https://github.com/ftlabs/fastclick/issues) into your application. Consider carefully whether you really need to use it.*
12
13[Explication en français](http://maxime.sh/2013/02/supprimer-le-lag-des-clics-sur-mobile-avec-fastclick/).
14
15[日本語で説明](https://developer.mozilla.org/ja/docs/Mozilla/Firefox_OS/Apps/Tips_and_techniques#Make_events_immediate)。
16
17## Why does the delay exist? ##
18
19According to [Google](https://developers.google.com/mobile/articles/fast_buttons):
20
21> ...mobile browsers will wait approximately 300ms from the time that you tap the button to fire the click event. The reason for this is that the browser is waiting to see if you are actually performing a double tap.
22
23## Compatibility ##
24
25The library has been deployed as part of the [FT Web App](http://app.ft.com/) and is tried and tested on the following mobile browsers:
26
27* Mobile Safari on iOS 3 and upwards
28* Chrome on iOS 5 and upwards
29* Chrome on Android (ICS)
30* Opera Mobile 11.5 and upwards
31* Android Browser since Android 2
32* PlayBook OS 1 and upwards
33
34## When it isn't needed ##
35
36FastClick doesn't attach any listeners on desktop browsers.
37
38Chrome 32+ on Android with `width=device-width` in the [viewport meta tag](https://developer.mozilla.org/en-US/docs/Mobile/Viewport_meta_tag) doesn't have a 300ms delay, therefore listeners aren't attached.
39
40```html
41<meta name="viewport" content="width=device-width, initial-scale=1">
42```
43
44Same 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.
45
46For IE11+, you can use `touch-action: manipulation;` to disable double-tap-to-zoom on certain elements (like links and buttons). For IE10 use `-ms-touch-action: manipulation`.
47
48## Usage ##
49
50Include fastclick.js in your JavaScript bundle or add it to your HTML page like this:
51
52```html
53<script type='application/javascript' src='/path/to/fastclick.js'></script>
54```
55
56The script must be loaded prior to instantiating FastClick on any element of the page.
57
58To instantiate FastClick on the `body`, which is the recommended method of use:
59
60```js
61if ('addEventListener' in document) {
62 document.addEventListener('DOMContentLoaded', function() {
63 FastClick.attach(document.body);
64 }, false);
65}
66```
67
68Or, if you're using jQuery:
69
70```js
71$(function() {
72 FastClick.attach(document.body);
73});
74```
75
76If you're using Browserify or another CommonJS-style module system, the `FastClick.attach` function will be returned when you call `require('@quasar/fastclick')`. As a result, the easiest way to use FastClick with these loaders is as follows:
77
78```js
79var attachFastClick = require('@quasar/fastclick');
80attachFastClick(document.body);
81```
82
83### Minified ###
84
85Run `make` to build a minified version of FastClick using the Closure Compiler REST API. The minified file is saved to `build/fastclick.min.js`.
86
87### AMD ###
88
89FastClick 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`
90
91```js
92var FastClick = require('@quasar/fastclick');
93FastClick.attach(document.body, options);
94```
95
96## Advanced ##
97
98### Ignore certain elements with `needsclick` ###
99
100Sometimes you need FastClick to ignore certain elements. You can do this easily by adding the `needsclick` class.
101```html
102<a class="needsclick">Ignored by FastClick</a>
103```
104
105#### Use case 1: non-synthetic click required ####
106
107Internally, FastClick uses `document.createEvent` to fire a synthetic `click` event as soon as `touchend` is fired by the browser. It then suppresses the additional `click` event created by the browser after that. In some cases, the non-synthetic `click` event created by the browser is required, as described in the [triggering focus example](http://ftlabs.github.com/fastclick/examples/focus.html).
108
109This is where the `needsclick` class comes in. Add the class to any element that requires a non-synthetic click.
110
111#### Use case 2: Twitter Bootstrap 2.2.2 dropdowns ####
112
113Another example of when to use the `needsclick` class is with dropdowns in Twitter Bootstrap 2.2.2. Bootstrap add its own `touchstart` listener for dropdowns, so you want to tell FastClick to ignore those. If you don't, touch devices will automatically close the dropdown as soon as it is clicked, because both FastClick and Bootstrap execute the synthetic click, one opens the dropdown, the second closes it immediately after.
114
115```html
116<a class="dropdown-toggle needsclick" data-toggle="dropdown">Dropdown</a>
117```
118
119## Examples ##
120
121FastClick is designed to cope with many different browser oddities. Here are some examples to illustrate this:
122
123* [basic use](http://ftlabs.github.com/fastclick/examples/layer.html) showing the increase in perceived responsiveness
124* [triggering focus](http://ftlabs.github.com/fastclick/examples/focus.html) on an input element from a `click` handler
125* [input element](http://ftlabs.github.com/fastclick/examples/input.html) which never receives clicks but gets fast focus
126
127## Tests ##
128
129There are no automated tests. The files in `tests/` are manual reduced test cases. We've had a think about how best to test these cases, but they tend to be very browser/device specific and sometimes subjective which means it's not so trivial to test.
130
131## Credits and collaboration ##
132
133The forked Fastclick is maintained by [Razvan Stoenescu](https://github.com/rstoenescu). Original contributors: [Rowan Beentje](http://twitter.com/rowanbeentje), [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia) and [Matthew Andrews](http://twitter.com/andrewsmatt) at [FT Labs](http://labs.ft.com). All open source code released by FT Labs is licensed under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request.