()
| 1332 | } |
| 1333 | |
| 1334 | static enable() { |
| 1335 | _win = window; |
| 1336 | _doc = document; |
| 1337 | _docEl = _doc.documentElement; |
| 1338 | _body = _doc.body; |
| 1339 | if (gsap) { |
| 1340 | _toArray = gsap.utils.toArray; |
| 1341 | _clamp = gsap.utils.clamp; |
| 1342 | _context = gsap.core.context || _passThrough; |
| 1343 | _suppressOverwrites = gsap.core.suppressOverwrites || _passThrough; |
| 1344 | _scrollRestoration = _win.history.scrollRestoration || "auto"; |
| 1345 | _lastScroll = _win.pageYOffset || 0; |
| 1346 | gsap.core.globals("ScrollTrigger", ScrollTrigger); // must register the global manually because in Internet Explorer, functions (classes) don't have a "name" property. |
| 1347 | if (_body) { |
| 1348 | _enabled = 1; |
| 1349 | _div100vh = document.createElement("div"); // to solve mobile browser address bar show/hide resizing, we shouldn't rely on window.innerHeight. Instead, use a <div> with its height set to 100vh and measure that since that's what the scrolling is based on anyway and it's not affected by address bar showing/hiding. |
| 1350 | _div100vh.style.height = "100vh"; |
| 1351 | _div100vh.style.position = "absolute"; |
| 1352 | _refresh100vh(); |
| 1353 | _rafBugFix(); |
| 1354 | Observer.register(gsap); |
| 1355 | // isTouch is 0 if no touch, 1 if ONLY touch, and 2 if it can accommodate touch but also other types like mouse/pointer. |
| 1356 | ScrollTrigger.isTouch = Observer.isTouch; |
| 1357 | _fixIOSBug = Observer.isTouch && /(iPad|iPhone|iPod|Mac)/g.test(navigator.userAgent); // since 2017, iOS has had a bug that causes event.clientX/Y to be inaccurate when a scroll occurs, thus we must alternate ignoring every other touchmove event to work around it. See https://bugs.webkit.org/show_bug.cgi?id=181954 and https://codepen.io/GreenSock/pen/ExbrPNa/087cef197dc35445a0951e8935c41503 |
| 1358 | _ignoreMobileResize = Observer.isTouch === 1; |
| 1359 | _addListener(_win, "wheel", _onScroll); // mostly for 3rd party smooth scrolling libraries. |
| 1360 | _root = [_win, _doc, _docEl, _body]; |
| 1361 | if (gsap.matchMedia) { |
| 1362 | ScrollTrigger.matchMedia = vars => { |
| 1363 | let mm = gsap.matchMedia(), |
| 1364 | p; |
| 1365 | for (p in vars) { |
| 1366 | mm.add(p, vars[p]); |
| 1367 | } |
| 1368 | return mm; |
| 1369 | }; |
| 1370 | gsap.addEventListener("matchMediaInit", () => { _recordScrollPositions(); _revertAll(); }); |
| 1371 | gsap.addEventListener("matchMediaRevert", () => _revertRecorded()); |
| 1372 | gsap.addEventListener("matchMedia", () => { |
| 1373 | _refreshAll(0, 1); |
| 1374 | _dispatch("matchMedia"); |
| 1375 | }); |
| 1376 | gsap.matchMedia().add("(orientation: portrait)", () => { // when orientation changes, we should take new base measurements for the ignoreMobileResize feature. |
| 1377 | _setBaseDimensions(); |
| 1378 | return _setBaseDimensions; |
| 1379 | }); |
| 1380 | } else { |
| 1381 | console.warn("Requires GSAP 3.11.0 or later"); |
| 1382 | } |
| 1383 | _setBaseDimensions(); |
| 1384 | _addListener(_doc, "scroll", _onScroll); // some browsers (like Chrome), the window stops dispatching scroll events on the window if you scroll really fast, but it's consistent on the document! |
| 1385 | let bodyHasStyle = _body.hasAttribute("style"), |
| 1386 | bodyStyle = _body.style, |
| 1387 | border = bodyStyle.borderTopStyle, |
| 1388 | AnimationProto = gsap.core.Animation.prototype, |
| 1389 | bounds, i; |
| 1390 | AnimationProto.revert || Object.defineProperty(AnimationProto, "revert", { value: function() { return this.time(-0.01, true); }}); // only for backwards compatibility (Animation.revert() was added after 3.10.4) |
| 1391 | bodyStyle.borderTopStyle = "solid"; // works around an issue where a margin of a child element could throw off the bounds of the _body, making it seem like there's a margin when there actually isn't. The border ensures that the bounds are accurate. |
no test coverage detected