UNPKG

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