|
1 |
| -(() => { |
2 |
| - const isChrome = window.chrome || navigator.userAgent.match('CriOS'); |
3 |
| - const isTouch = 'ontouchstart' in document.documentElement; |
| 1 | +'use strict'; |
| 2 | + |
| 3 | +(function() { |
| 4 | + var isChrome = window.chrome || navigator.userAgent.match('CriOS'); |
| 5 | + var isTouch = 'ontouchstart' in document.documentElement; |
4 | 6 |
|
5 | 7 | if (!isChrome || !isTouch) {
|
6 | 8 | return;
|
7 | 9 | }
|
8 | 10 |
|
9 |
| - let supportsOverscroll = false; |
10 |
| - let supportsPassive = false; |
11 |
| - let lastTouchY = 0; |
12 |
| - let maybePrevent = false; |
| 11 | + var supportsOverscroll = false; |
| 12 | + var supportsPassive = false; |
| 13 | + var lastTouchY = 0; |
| 14 | + var maybePrevent = false; |
13 | 15 |
|
14 | 16 | try {
|
15 | 17 | if (CSS.supports('overscroll-behavior-y', 'contain')) {
|
|
20 | 22 | if (supportsOverscroll) {
|
21 | 23 | return (document.body.style.overscrollBehaviorY = 'contain');
|
22 | 24 | } else {
|
23 |
| - const head = document.head || document.body; |
24 |
| - const style = document.createElement('style'); |
25 |
| - const css = ` |
26 |
| - ::-webkit-scrollbar { |
27 |
| - width: 5px; |
28 |
| - } |
29 |
| - ::-webkit-scrollbar-thumb { |
30 |
| - border-radius: 5px; |
31 |
| - background-color: rgba(0, 0, 0, 0.2); |
32 |
| - } |
33 |
| - body { |
34 |
| - -webkit-overflow-scrolling: auto!important; |
35 |
| - } |
36 |
| - `; |
37 |
| - |
| 25 | + var head = document.head || document.body; |
| 26 | + var style = document.createElement('style'); |
| 27 | + var css = |
| 28 | + '\n ::-webkit-scrollbar {\n width: 5px;\n }\n ::-webkit-scrollbar-thumb {\n border-radius: 5px;\n background-color: rgba(0, 0, 0, 0.2);\n }\n body {\n -webkit-overflow-scrolling: auto!important;\n }\n '; |
38 | 29 | style.type = 'text/css';
|
39 | 30 |
|
40 | 31 | if (style.styleSheet) {
|
|
47 | 38 | }
|
48 | 39 |
|
49 | 40 | try {
|
50 |
| - addEventListener('test', null, { |
| 41 | + window.addEventListener('test', null, { |
51 | 42 | get passive() {
|
52 | 43 | supportsPassive = true;
|
53 | 44 | },
|
54 | 45 | });
|
55 | 46 | } catch (e) {}
|
56 | 47 |
|
57 |
| - const setTouchStartPoint = event => { |
| 48 | + var setTouchStartPoint = function setTouchStartPoint(event) { |
58 | 49 | lastTouchY = event.touches[0].clientY;
|
59 | 50 | };
|
60 | 51 |
|
61 |
| - const isScrollingUp = event => { |
62 |
| - const touchY = event.touches[0].clientY; |
63 |
| - const touchYDelta = touchY - lastTouchY; |
64 |
| - |
| 52 | + var isScrollingUp = function isScrollingUp(event) { |
| 53 | + var touchY = event.touches[0].clientY; |
| 54 | + var touchYDelta = touchY - lastTouchY; |
65 | 55 | lastTouchY = touchY;
|
66 |
| - |
67 | 56 | return touchYDelta > 0;
|
68 | 57 | };
|
69 | 58 |
|
70 |
| - const touchstartHandler = event => { |
| 59 | + var touchstartHandler = function touchstartHandler(event) { |
71 | 60 | if (event.touches.length !== 1) return;
|
72 | 61 | setTouchStartPoint(event);
|
73 | 62 | maybePrevent = window.pageYOffset === 0;
|
74 | 63 | };
|
75 | 64 |
|
76 |
| - const touchmoveHandler = event => { |
| 65 | + var touchmoveHandler = function touchmoveHandler(event) { |
77 | 66 | if (maybePrevent) {
|
78 | 67 | maybePrevent = false;
|
| 68 | + |
79 | 69 | if (isScrollingUp(event)) {
|
80 | 70 | return event.preventDefault();
|
81 | 71 | }
|
|
85 | 75 | document.addEventListener(
|
86 | 76 | 'touchstart',
|
87 | 77 | touchstartHandler,
|
88 |
| - supportsPassive ? {passive: true} : false, |
| 78 | + supportsPassive |
| 79 | + ? { |
| 80 | + passive: true, |
| 81 | + } |
| 82 | + : false, |
89 | 83 | );
|
90 |
| - |
91 | 84 | document.addEventListener(
|
92 | 85 | 'touchmove',
|
93 | 86 | touchmoveHandler,
|
94 |
| - supportsPassive ? {passive: false} : false, |
| 87 | + supportsPassive |
| 88 | + ? { |
| 89 | + passive: false, |
| 90 | + } |
| 91 | + : false, |
95 | 92 | );
|
96 | 93 | })();
|
0 commit comments