1 | var _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 |
|
4 | var _FastClick = null
|
5 |
|
6 | ;(function () {
|
7 | 'use strict';
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | _FastClick = function FastClick(layer, options) {
|
30 | var oldOnClick;
|
31 |
|
32 | options = options || {};
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | this.trackingClick = false;
|
40 |
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 | this.trackingClickStart = 0;
|
47 |
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | this.targetElement = null;
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | this.touchStartX = 0;
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | this.touchStartY = 0;
|
68 |
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 | this.lastTouchIdentifier = 0;
|
75 |
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 | this.touchBoundary = options.touchBoundary || 10;
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | this.layer = layer;
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | this.tapDelay = options.tapDelay || 200;
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 | this.tapTimeout = options.tapTimeout || 700;
|
103 |
|
104 | if (_FastClick.notNeeded(layer)) {
|
105 | return;
|
106 | }
|
107 |
|
108 |
|
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 |
|
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 |
|
135 |
|
136 |
|
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 |
|
162 |
|
163 |
|
164 | if (typeof layer.onclick === 'function') {
|
165 |
|
166 |
|
167 |
|
168 | oldOnClick = layer.onclick;
|
169 | layer.addEventListener('click', function (event) {
|
170 | oldOnClick(event);
|
171 | }, false);
|
172 | layer.onclick = null;
|
173 | }
|
174 | };
|
175 |
|
176 | |
177 |
|
178 |
|
179 |
|
180 |
|
181 | var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
|
182 |
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 | var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone;
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 | var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
|
196 |
|
197 | |
198 |
|
199 |
|
200 |
|
201 |
|
202 | var deviceIsIOS4 = deviceIsIOS && /OS 4_\d(_\d)?/.test(navigator.userAgent);
|
203 |
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 | var deviceIsIOSWithBadTarget = deviceIsIOS && /OS [6-7]_\d/.test(navigator.userAgent);
|
210 |
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 | var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;
|
217 |
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | _FastClick.prototype.needsClick = function (target) {
|
225 | switch (target.nodeName.toLowerCase()) {
|
226 |
|
227 |
|
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 |
|
239 | if (deviceIsIOS && target.type === 'file' || target.disabled) {
|
240 | return true;
|
241 | }
|
242 |
|
243 | break;
|
244 | case 'label':
|
245 | case 'iframe':
|
246 | case 'video':
|
247 | return true;
|
248 | }
|
249 |
|
250 | return (/\bneedsclick\b/.test(target.className)
|
251 | );
|
252 | };
|
253 |
|
254 | |
255 |
|
256 |
|
257 |
|
258 |
|
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 |
|
278 | return !target.disabled && !target.readOnly;
|
279 | default:
|
280 | return (/\bneedsfocus\b/.test(target.className)
|
281 | );
|
282 | }
|
283 | };
|
284 |
|
285 | |
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | _FastClick.prototype.sendClick = function (targetElement, event) {
|
292 | var clickEvent, touch;
|
293 |
|
294 |
|
295 | if (document.activeElement && document.activeElement !== targetElement) {
|
296 | document.activeElement.blur();
|
297 | }
|
298 |
|
299 | touch = event.changedTouches[0];
|
300 |
|
301 |
|
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 |
|
311 | if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
|
312 | return 'mousedown';
|
313 | }
|
314 |
|
315 | return 'click';
|
316 | };
|
317 |
|
318 | |
319 |
|
320 |
|
321 | _FastClick.prototype.focus = function (targetElement) {
|
322 | var length;
|
323 |
|
324 |
|
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 |
|
328 |
|
329 | if (deviceIsIOS) {
|
330 | try {
|
331 | length = targetElement.value.length;
|
332 | targetElement.setSelectionRange(length, length);
|
333 | } catch (error) {
|
334 | console.log(error);
|
335 | }
|
336 |
|
337 | targetElement.focus();
|
338 | }
|
339 | } else {
|
340 | targetElement.focus();
|
341 | }
|
342 | };
|
343 |
|
344 | |
345 |
|
346 |
|
347 |
|
348 |
|
349 | _FastClick.prototype.updateScrollParent = function (targetElement) {
|
350 | var scrollParent, parentElement;
|
351 |
|
352 | scrollParent = targetElement.fastClickScrollParent;
|
353 |
|
354 |
|
355 |
|
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 |
|
370 | if (scrollParent) {
|
371 | scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
|
372 | }
|
373 | };
|
374 |
|
375 | |
376 |
|
377 |
|
378 |
|
379 | _FastClick.prototype.getTargetElementFromEventTarget = function (eventTarget) {
|
380 |
|
381 |
|
382 | if (eventTarget.nodeType === Node.TEXT_NODE) {
|
383 | return eventTarget.parentNode;
|
384 | }
|
385 |
|
386 | return eventTarget;
|
387 | };
|
388 |
|
389 | |
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 | _FastClick.prototype.onTouchStart = function (event) {
|
396 | var targetElement, touch, selection;
|
397 |
|
398 |
|
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 |
|
409 | selection = window.getSelection();
|
410 | if (selection.rangeCount && !selection.isCollapsed) {
|
411 | return true;
|
412 | }
|
413 |
|
414 | if (!deviceIsIOS4) {
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | if (touch.identifier && touch.identifier === this.lastTouchIdentifier) {
|
425 | event.preventDefault();
|
426 | return false;
|
427 | }
|
428 |
|
429 | this.lastTouchIdentifier = touch.identifier;
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
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 |
|
449 | if (event.timeStamp - this.lastClickTime < this.tapDelay) {
|
450 | event.preventDefault();
|
451 | }
|
452 |
|
453 | return true;
|
454 | };
|
455 |
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
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 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 | _FastClick.prototype.onTouchMove = function (event) {
|
480 | if (!this.trackingClick) {
|
481 | return true;
|
482 | }
|
483 |
|
484 |
|
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 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 | _FastClick.prototype.findControl = function (labelElement) {
|
500 |
|
501 |
|
502 | if (labelElement.control !== undefined) {
|
503 | return labelElement.control;
|
504 | }
|
505 |
|
506 |
|
507 | if (labelElement.htmlFor) {
|
508 | return document.getElementById(labelElement.htmlFor);
|
509 | }
|
510 |
|
511 |
|
512 |
|
513 | return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
|
514 | };
|
515 |
|
516 | |
517 |
|
518 |
|
519 |
|
520 |
|
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 |
|
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 |
|
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 |
|
554 |
|
555 |
|
556 |
|
557 | if (deviceIsIOSWithBadTarget) {
|
558 | touch = event.changedTouches[0];
|
559 |
|
560 |
|
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 |
|
579 |
|
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 |
|
589 |
|
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 |
|
601 |
|
602 | scrollParent = targetElement.fastClickScrollParent;
|
603 | if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
|
604 | return true;
|
605 | }
|
606 | }
|
607 |
|
608 |
|
609 |
|
610 | if (!this.needsClick(targetElement)) {
|
611 | event.preventDefault();
|
612 | this.sendClick(targetElement, event);
|
613 | }
|
614 |
|
615 | return false;
|
616 | };
|
617 |
|
618 | |
619 |
|
620 |
|
621 |
|
622 |
|
623 | _FastClick.prototype.onTouchCancel = function () {
|
624 | this.trackingClick = false;
|
625 | this.targetElement = null;
|
626 | };
|
627 |
|
628 | |
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 | _FastClick.prototype.onMouse = function (event) {
|
635 |
|
636 |
|
637 | if (!this.targetElement) {
|
638 | return true;
|
639 | }
|
640 |
|
641 | if (event.forwardedTouchEvent) {
|
642 | return true;
|
643 | }
|
644 |
|
645 |
|
646 | if (!event.cancelable) {
|
647 | return true;
|
648 | }
|
649 |
|
650 |
|
651 |
|
652 |
|
653 | if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
|
654 |
|
655 |
|
656 | if (event.stopImmediatePropagation) {
|
657 | event.stopImmediatePropagation();
|
658 | } else {
|
659 |
|
660 |
|
661 | event.propagationStopped = true;
|
662 | }
|
663 |
|
664 |
|
665 | event.stopPropagation();
|
666 | event.preventDefault();
|
667 |
|
668 | return false;
|
669 | }
|
670 |
|
671 |
|
672 | return true;
|
673 | };
|
674 |
|
675 | |
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 | _FastClick.prototype.onClick = function (event) {
|
684 | var permitted;
|
685 |
|
686 |
|
687 | if (this.trackingClick) {
|
688 | this.targetElement = null;
|
689 | this.trackingClick = false;
|
690 | return true;
|
691 | }
|
692 |
|
693 |
|
694 | if (event.target.type === 'submit' && event.detail === 0) {
|
695 | return true;
|
696 | }
|
697 |
|
698 | permitted = this.onMouse(event);
|
699 |
|
700 |
|
701 | if (!permitted) {
|
702 | this.targetElement = null;
|
703 | }
|
704 |
|
705 |
|
706 | return permitted;
|
707 | };
|
708 |
|
709 | |
710 |
|
711 |
|
712 |
|
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 |
|
732 |
|
733 |
|
734 |
|
735 | _FastClick.notNeeded = function (layer) {
|
736 | var metaViewport;
|
737 | var chromeVersion;
|
738 | var blackberryVersion;
|
739 | var firefoxVersion;
|
740 |
|
741 |
|
742 | if (typeof window.ontouchstart === 'undefined') {
|
743 | return true;
|
744 | }
|
745 |
|
746 |
|
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 |
|
756 | if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
757 | return true;
|
758 | }
|
759 |
|
760 | if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
|
761 | return true;
|
762 | }
|
763 | }
|
764 |
|
765 |
|
766 | } else {
|
767 | return true;
|
768 | }
|
769 | }
|
770 |
|
771 | if (deviceIsBlackBerry10) {
|
772 | blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/);
|
773 |
|
774 |
|
775 |
|
776 | if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) {
|
777 | metaViewport = document.querySelector('meta[name=viewport]');
|
778 |
|
779 | if (metaViewport) {
|
780 |
|
781 | if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
782 | return true;
|
783 | }
|
784 |
|
785 | if (document.documentElement.scrollWidth <= window.outerWidth) {
|
786 | return true;
|
787 | }
|
788 | }
|
789 | }
|
790 | }
|
791 |
|
792 |
|
793 | if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
794 | return true;
|
795 | }
|
796 |
|
797 |
|
798 | firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [, 0])[1];
|
799 |
|
800 | if (firefoxVersion >= 27) {
|
801 |
|
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 |
|
810 |
|
811 | if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') {
|
812 | return true;
|
813 | }
|
814 |
|
815 | return false;
|
816 | };
|
817 |
|
818 | |
819 |
|
820 |
|
821 |
|
822 |
|
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 |
|
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 |
|
843 |
|
844 | export default _FastClick; |
\ | No newline at end of file |