PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.0.7
UpStream: a Project Management Plugin for WordPress v2.0.7
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / templates / assets / js / fastclick.js

fastclick.js in UpStream: a Project Management Plugin for WordPress 2.0.7, at templates/assets/js/fastclick.js

814 lines 30.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ;(function () {
2 'use strict';
3
4 /**
5 * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs.
6 *
7 * @codingstandard ftlabs-jsv2
8 * @copyright The Financial Times Limited [All Rights Reserved]
9 * @license MIT License (see LICENSE.txt)
10 */
11
12 /*jslint browser:true, node:true*/
13
14 /*global define, Event, Node*/
15
16 /**
17 * Instantiate fast-clicking listeners on the specified layer.
18 *
19 * @constructor
20 * @param {Element} layer The layer to listen on
21 * @param {Object} [options={}] The options to override the defaults
22 */
23 function FastClick (layer, options) {
24 var oldOnClick;
25
26 options = options || {};
27
28 /**
29 * Whether a click is currently being tracked.
30 *
31 * @type boolean
32 */
33 this.trackingClick = false;
34
35 /**
36 * Timestamp for when click tracking started.
37 *
38 * @type number
39 */
40 this.trackingClickStart = 0;
41
42 /**
43 * The element being tracked for a click.
44 *
45 * @type EventTarget
46 */
47 this.targetElement = null;
48
49 /**
50 * X-coordinate of touch start event.
51 *
52 * @type number
53 */
54 this.touchStartX = 0;
55
56 /**
57 * Y-coordinate of touch start event.
58 *
59 * @type number
60 */
61 this.touchStartY = 0;
62
63 /**
64 * ID of the last touch, retrieved from Touch.identifier.
65 *
66 * @type number
67 */
68 this.lastTouchIdentifier = 0;
69
70 /**
71 * Touchmove boundary, beyond which a click will be cancelled.
72 *
73 * @type number
74 */
75 this.touchBoundary = options.touchBoundary || 10;
76
77 /**
78 * The FastClick layer.
79 *
80 * @type Element
81 */
82 this.layer = layer;
83
84 /**
85 * The minimum time between tap(touchstart and touchend) events
86 *
87 * @type number
88 */
89 this.tapDelay = options.tapDelay || 200;
90
91 /**
92 * The maximum time for a tap
93 *
94 * @type number
95 */
96 this.tapTimeout = options.tapTimeout || 700;
97
98 if (FastClick.notNeeded(layer)) {
99 return;
100 }
101
102 // Some old versions of Android don't have Function.prototype.bind
103 function bind (method, context) {
104 return function () { return method.apply(context, arguments); };
105 }
106
107 var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'];
108 var context = this;
109 for (var i = 0, l = methods.length; i < l; i++) {
110 context[methods[i]] = bind(context[methods[i]], context);
111 }
112
113 // Set up event handlers as required
114 if (deviceIsAndroid) {
115 layer.addEventListener('mouseover', this.onMouse, true);
116 layer.addEventListener('mousedown', this.onMouse, true);
117 layer.addEventListener('mouseup', this.onMouse, true);
118 }
119
120 layer.addEventListener('click', this.onClick, true);
121 layer.addEventListener('touchstart', this.onTouchStart, false);
122 layer.addEventListener('touchmove', this.onTouchMove, false);
123 layer.addEventListener('touchend', this.onTouchEnd, false);
124 layer.addEventListener('touchcancel', this.onTouchCancel, false);
125
126 // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
127 // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
128 // layer when they are cancelled.
129 if (!Event.prototype.stopImmediatePropagation) {
130 layer.removeEventListener = function (type, callback, capture) {
131 var rmv = Node.prototype.removeEventListener;
132 if (type === 'click') {
133 rmv.call(layer, type, callback.hijacked || callback, capture);
134 } else {
135 rmv.call(layer, type, callback, capture);
136 }
137 };
138
139 layer.addEventListener = function (type, callback, capture) {
140 var adv = Node.prototype.addEventListener;
141 if (type === 'click') {
142 adv.call(layer, type, callback.hijacked || (callback.hijacked = function (event) {
143 if (!event.propagationStopped) {
144 callback(event);
145 }
146 }), capture);
147 } else {
148 adv.call(layer, type, callback, capture);
149 }
150 };
151 }
152
153 // If a handler is already declared in the element's onclick attribute, it will be fired before
154 // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
155 // adding it as listener.
156 if (typeof layer.onclick === 'function') {
157
158 // Android browser on at least 3.2 requires a new reference to the function in layer.onclick
159 // - the old one won't work if passed to addEventListener directly.
160 oldOnClick = layer.onclick;
161 layer.addEventListener('click', function (event) {
162 oldOnClick(event);
163 }, false);
164 layer.onclick = null;
165 }
166 }
167
168 /**
169 * Windows Phone 8.1 fakes user agent string to look like Android and iPhone.
170 *
171 * @type boolean
172 */
173 var deviceIsWindowsPhone = navigator.userAgent.indexOf('Windows Phone') >= 0;
174
175 /**
176 * Android requires exceptions.
177 *
178 * @type boolean
179 */
180 var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone;
181
182 /**
183 * iOS requires exceptions.
184 *
185 * @type boolean
186 */
187 var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
188
189 /**
190 * iOS 4 requires an exception for select elements.
191 *
192 * @type boolean
193 */
194 var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
195
196 /**
197 * iOS 6.0-7.* requires the target element to be manually derived
198 *
199 * @type boolean
200 */
201 var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent);
202
203 /**
204 * BlackBerry requires exceptions.
205 *
206 * @type boolean
207 */
208 var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;
209
210 /**
211 * Determine whether a given element requires a native click.
212 *
213 * @param {EventTarget|Element} target Target DOM element
214 * @returns {boolean} Returns true if the element needs a native click
215 */
216 FastClick.prototype.needsClick = function (target) {
217 switch (target.nodeName.toLowerCase()) {
218
219 // Don't send a synthetic click to disabled inputs (issue #62)
220 case 'button':
221 case 'select':
222 case 'textarea':
223 if (target.disabled) {
224 return true;
225 }
226
227 break;
228 case 'input':
229
230 // File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
231 if ((deviceIsIOS && target.type === 'file') || target.disabled) {
232 return true;
233 }
234
235 break;
236 case 'label':
237 case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
238 case 'video':
239 return true;
240 }
241
242 return (/\bneedsclick\b/).test(target.className);
243 };
244
245 /**
246 * Determine whether a given element requires a call to focus to simulate click into element.
247 *
248 * @param {EventTarget|Element} target Target DOM element
249 * @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
250 */
251 FastClick.prototype.needsFocus = function (target) {
252 switch (target.nodeName.toLowerCase()) {
253 case 'textarea':
254 return true;
255 case 'select':
256 return !deviceIsAndroid;
257 case 'input':
258 switch (target.type) {
259 case 'button':
260 case 'checkbox':
261 case 'file':
262 case 'image':
263 case 'radio':
264 case 'submit':
265 return false;
266 }
267
268 // No point in attempting to focus disabled inputs
269 return !target.disabled && !target.readOnly;
270 default:
271 return (/\bneedsfocus\b/).test(target.className);
272 }
273 };
274
275 /**
276 * Send a click event to the specified element.
277 *
278 * @param {EventTarget|Element} targetElement
279 * @param {Event} event
280 */
281 FastClick.prototype.sendClick = function (targetElement, event) {
282 var clickEvent, touch;
283
284 // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
285 if (document.activeElement && document.activeElement !== targetElement) {
286 document.activeElement.blur();
287 }
288
289 touch = event.changedTouches[0];
290
291 // Synthesise a click event, with an extra attribute so it can be tracked
292 clickEvent = document.createEvent('MouseEvents');
293 clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
294 clickEvent.forwardedTouchEvent = true;
295 targetElement.dispatchEvent(clickEvent);
296 };
297
298 FastClick.prototype.determineEventType = function (targetElement) {
299
300 //Issue #159: Android Chrome Select Box does not open with a synthetic click event
301 if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
302 return 'mousedown';
303 }
304
305 return 'click';
306 };
307
308 /**
309 * @param {EventTarget|Element} targetElement
310 */
311 FastClick.prototype.focus = function (targetElement) {
312 var length;
313
314 // 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.
315 if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
316 length = targetElement.value.length;
317 targetElement.setSelectionRange(length, length);
318 } else {
319 targetElement.focus();
320 }
321 };
322
323 /**
324 * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
325 *
326 * @param {EventTarget|Element} targetElement
327 */
328 FastClick.prototype.updateScrollParent = function (targetElement) {
329 var scrollParent, parentElement;
330
331 scrollParent = targetElement.fastClickScrollParent;
332
333 // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
334 // target element was moved to another parent.
335 if (!scrollParent || !scrollParent.contains(targetElement)) {
336 parentElement = targetElement;
337 do {
338 if (parentElement.scrollHeight > parentElement.offsetHeight) {
339 scrollParent = parentElement;
340 targetElement.fastClickScrollParent = parentElement;
341 break;
342 }
343
344 parentElement = parentElement.parentElement;
345 } while (parentElement);
346 }
347
348 // Always update the scroll top tracker if possible.
349 if (scrollParent) {
350 scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
351 }
352 };
353
354 /**
355 * @param {EventTarget} targetElement
356 * @returns {Element|EventTarget}
357 */
358 FastClick.prototype.getTargetElementFromEventTarget = function (eventTarget) {
359
360 // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
361 if (eventTarget.nodeType === Node.TEXT_NODE) {
362 return eventTarget.parentNode;
363 }
364
365 return eventTarget;
366 };
367
368 /**
369 * On touch start, record the position and scroll offset.
370 *
371 * @param {Event} event
372 * @returns {boolean}
373 */
374 FastClick.prototype.onTouchStart = function (event) {
375 var targetElement, touch, selection;
376
377 // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
378 if (event.targetTouches.length > 1) {
379 return true;
380 }
381
382 targetElement = this.getTargetElementFromEventTarget(event.target);
383 touch = event.targetTouches[0];
384
385 if (deviceIsIOS) {
386
387 // Only trusted events will deselect text on iOS (issue #49)
388 selection = window.getSelection();
389 if (selection.rangeCount && !selection.isCollapsed) {
390 return true;
391 }
392
393 if (!deviceIsIOS4) {
394
395 // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
396 // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
397 // with the same identifier as the touch event that previously triggered the click that triggered the alert.
398 // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
399 // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
400 // Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string,
401 // which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long,
402 // random integers, it's safe to to continue if the identifier is 0 here.
403 if (touch.identifier && touch.identifier === this.lastTouchIdentifier) {
404 event.preventDefault();
405 return false;
406 }
407
408 this.lastTouchIdentifier = touch.identifier;
409
410 // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
411 // 1) the user does a fling scroll on the scrollable layer
412 // 2) the user stops the fling scroll with another tap
413 // then the event.target of the last 'touchend' event will be the element that was under the user's finger
414 // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
415 // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
416 this.updateScrollParent(targetElement);
417 }
418 }
419
420 this.trackingClick = true;
421 this.trackingClickStart = event.timeStamp;
422 this.targetElement = targetElement;
423
424 this.touchStartX = touch.pageX;
425 this.touchStartY = touch.pageY;
426
427 // Prevent phantom clicks on fast double-tap (issue #36)
428 if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
429 event.preventDefault();
430 }
431
432 return true;
433 };
434
435 /**
436 * Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
437 *
438 * @param {Event} event
439 * @returns {boolean}
440 */
441 FastClick.prototype.touchHasMoved = function (event) {
442 var touch = event.changedTouches[0], boundary = this.touchBoundary;
443
444 if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
445 return true;
446 }
447
448 return false;
449 };
450
451 /**
452 * Update the last position.
453 *
454 * @param {Event} event
455 * @returns {boolean}
456 */
457 FastClick.prototype.onTouchMove = function (event) {
458 if (!this.trackingClick) {
459 return true;
460 }
461
462 // If the touch has moved, cancel the click tracking
463 if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
464 this.trackingClick = false;
465 this.targetElement = null;
466 }
467
468 return true;
469 };
470
471 /**
472 * Attempt to find the labelled control for the given label element.
473 *
474 * @param {EventTarget|HTMLLabelElement} labelElement
475 * @returns {Element|null}
476 */
477 FastClick.prototype.findControl = function (labelElement) {
478
479 // Fast path for newer browsers supporting the HTML5 control attribute
480 if (labelElement.control !== undefined) {
481 return labelElement.control;
482 }
483
484 // All browsers under test that support touch events also support the HTML5 htmlFor attribute
485 if (labelElement.htmlFor) {
486 return document.getElementById(labelElement.htmlFor);
487 }
488
489 // If no for attribute exists, attempt to retrieve the first labellable descendant element
490 // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
491 return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
492 };
493
494 /**
495 * On touch end, determine whether to send a click event at once.
496 *
497 * @param {Event} event
498 * @returns {boolean}
499 */
500 FastClick.prototype.onTouchEnd = function (event) {
501 var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
502
503 if (!this.trackingClick) {
504 return true;
505 }
506
507 // Prevent phantom clicks on fast double-tap (issue #36)
508 if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
509 this.cancelNextClick = true;
510 return true;
511 }
512
513 if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) {
514 return true;
515 }
516
517 // Reset to prevent wrong click cancel on input (issue #156).
518 this.cancelNextClick = false;
519
520 this.lastClickTime = event.timeStamp;
521
522 trackingClickStart = this.trackingClickStart;
523 this.trackingClick = false;
524 this.trackingClickStart = 0;
525
526 // On some iOS devices, the targetElement supplied with the event is invalid if the layer
527 // is performing a transition or scroll, and has to be re-detected manually. Note that
528 // for this to function correctly, it must be called *after* the event target is checked!
529 // See issue #57; also filed as rdar://13048589 .
530 if (deviceIsIOSWithBadTarget) {
531 touch = event.changedTouches[0];
532
533 // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
534 targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
535 targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
536 }
537
538 targetTagName = targetElement.tagName.toLowerCase();
539 if (targetTagName === 'label') {
540 forElement = this.findControl(targetElement);
541 if (forElement) {
542 this.focus(targetElement);
543 if (deviceIsAndroid) {
544 return false;
545 }
546
547 targetElement = forElement;
548 }
549 } else if (this.needsFocus(targetElement)) {
550
551 // 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.
552 // 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).
553 if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) {
554 this.targetElement = null;
555 return false;
556 }
557
558 this.focus(targetElement);
559 this.sendClick(targetElement, event);
560
561 // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
562 // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
563 if (!deviceIsIOS || targetTagName !== 'select') {
564 this.targetElement = null;
565 event.preventDefault();
566 }
567
568 return false;
569 }
570
571 if (deviceIsIOS && !deviceIsIOS4) {
572
573 // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
574 // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
575 scrollParent = targetElement.fastClickScrollParent;
576 if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
577 return true;
578 }
579 }
580
581 // Prevent the actual click from going though - unless the target node is marked as requiring
582 // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
583 if (!this.needsClick(targetElement)) {
584 event.preventDefault();
585 this.sendClick(targetElement, event);
586 }
587
588 return false;
589 };
590
591 /**
592 * On touch cancel, stop tracking the click.
593 *
594 * @returns {void}
595 */
596 FastClick.prototype.onTouchCancel = function () {
597 this.trackingClick = false;
598 this.targetElement = null;
599 };
600
601 /**
602 * Determine mouse events which should be permitted.
603 *
604 * @param {Event} event
605 * @returns {boolean}
606 */
607 FastClick.prototype.onMouse = function (event) {
608
609 // If a target element was never set (because a touch event was never fired) allow the event
610 if (!this.targetElement) {
611 return true;
612 }
613
614 if (event.forwardedTouchEvent) {
615 return true;
616 }
617
618 // Programmatically generated events targeting a specific element should be permitted
619 if (!event.cancelable) {
620 return true;
621 }
622
623 // Derive and check the target element to see whether the mouse event needs to be permitted;
624 // unless explicitly enabled, prevent non-touch click events from triggering actions,
625 // to prevent ghost/doubleclicks.
626 if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
627
628 // Prevent any user-added listeners declared on FastClick element from being fired.
629 if (event.stopImmediatePropagation) {
630 event.stopImmediatePropagation();
631 } else {
632
633 // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
634 event.propagationStopped = true;
635 }
636
637 // Cancel the event
638 event.stopPropagation();
639 event.preventDefault();
640
641 return false;
642 }
643
644 // If the mouse event is permitted, return true for the action to go through.
645 return true;
646 };
647
648 /**
649 * On actual clicks, determine whether this is a touch-generated click, a click action occurring
650 * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
651 * an actual click which should be permitted.
652 *
653 * @param {Event} event
654 * @returns {boolean}
655 */
656 FastClick.prototype.onClick = function (event) {
657 var permitted;
658
659 // 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.
660 if (this.trackingClick) {
661 this.targetElement = null;
662 this.trackingClick = false;
663 return true;
664 }
665
666 // 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.
667 if (event.target.type === 'submit' && event.detail === 0) {
668 return true;
669 }
670
671 permitted = this.onMouse(event);
672
673 // 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.
674 if (!permitted) {
675 this.targetElement = null;
676 }
677
678 // If clicks are permitted, return true for the action to go through.
679 return permitted;
680 };
681
682 /**
683 * Remove all FastClick's event listeners.
684 *
685 * @returns {void}
686 */
687 FastClick.prototype.destroy = function () {
688 var layer = this.layer;
689
690 if (deviceIsAndroid) {
691 layer.removeEventListener('mouseover', this.onMouse, true);
692 layer.removeEventListener('mousedown', this.onMouse, true);
693 layer.removeEventListener('mouseup', this.onMouse, true);
694 }
695
696 layer.removeEventListener('click', this.onClick, true);
697 layer.removeEventListener('touchstart', this.onTouchStart, false);
698 layer.removeEventListener('touchmove', this.onTouchMove, false);
699 layer.removeEventListener('touchend', this.onTouchEnd, false);
700 layer.removeEventListener('touchcancel', this.onTouchCancel, false);
701 };
702
703 /**
704 * Check whether FastClick is needed.
705 *
706 * @param {Element} layer The layer to listen on
707 */
708 FastClick.notNeeded = function (layer) {
709 var metaViewport;
710 var chromeVersion;
711 var blackberryVersion;
712 var firefoxVersion;
713
714 // Devices that don't support touch don't need FastClick
715 if (typeof window.ontouchstart === 'undefined') {
716 return true;
717 }
718
719 // Chrome version - zero for other browsers
720 chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1];
721
722 if (chromeVersion) {
723
724 if (deviceIsAndroid) {
725 metaViewport = document.querySelector('meta[name=viewport]');
726
727 if (metaViewport) {
728 // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
729 if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
730 return true;
731 }
732 // Chrome 32 and above with width=device-width or less don't need FastClick
733 if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
734 return true;
735 }
736 }
737
738 // Chrome desktop doesn't need FastClick (issue #15)
739 } else {
740 return true;
741 }
742 }
743
744 if (deviceIsBlackBerry10) {
745 blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/);
746
747 // BlackBerry 10.3+ does not require Fastclick library.
748 // https://github.com/ftlabs/fastclick/issues/251
749 if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) {
750 metaViewport = document.querySelector('meta[name=viewport]');
751
752 if (metaViewport) {
753 // user-scalable=no eliminates click delay.
754 if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
755 return true;
756 }
757 // width=device-width (or less than device-width) eliminates click delay.
758 if (document.documentElement.scrollWidth <= window.outerWidth) {
759 return true;
760 }
761 }
762 }
763 }
764
765 // IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97)
766 if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') {
767 return true;
768 }
769
770 // Firefox version - zero for other browsers
771 firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1];
772
773 if (firefoxVersion >= 27) {
774 // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896
775
776 metaViewport = document.querySelector('meta[name=viewport]');
777 if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) {
778 return true;
779 }
780 }
781
782 // IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version
783 // http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx
784 if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') {
785 return true;
786 }
787
788 return false;
789 };
790
791 /**
792 * Factory method for creating a FastClick object
793 *
794 * @param {Element} layer The layer to listen on
795 * @param {Object} [options={}] The options to override the defaults
796 */
797 FastClick.attach = function (layer, options) {
798 return new FastClick(layer, options);
799 };
800
801 if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
802
803 // AMD. Register as an anonymous module.
804 define(function () {
805 return FastClick;
806 });
807 } else if (typeof module !== 'undefined' && module.exports) {
808 module.exports = FastClick.attach;
809 module.exports.FastClick = FastClick;
810 } else {
811 window.FastClick = FastClick;
812 }
813 }());
814