1. 禁止缩放

      1. <meta name="viewport" content="user-scalable=no" />
    2. 重新封装 ```javascript const tap = (elementObj, callback) => { let isMove = false; let startTime = 0; // 记录触摸时的时间 elementObj.addEventListener(“touchstart”, event => { startTime = Date.now(); // 记录触摸时间 }); elementObj.addEventListener(“touchmove”, e => { isMove = true; // 判断是否有滑动,有滑动算拖拽,不算点击 }); elementObj.addEventListener(“touchend”, e => { // 如果手指触摸和离开时间小于 150ms 算点击 if (!isMove && Date.now() - startTime < 150) { callback && callback(); // 执行回调函数 } // 重置 isMove = false; startTime = 0; }); };

    tap(元素节点, () => {});

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