smooth-scroll.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. (function () {
  2. function aq() {
  3. if (!ap && document.body) {
  4. ap = !0;
  5. const h = document.body;
  6. const f = document.documentElement;
  7. let m = window.innerHeight;
  8. const r = h.scrollHeight;
  9. aK = document.compatMode.indexOf("CSS") >= 0 ? f : h;
  10. aJ = h;
  11. aO.keyboardSupport && window.addEventListener("keydown", ag, !1);
  12. if (top != self) {
  13. aF = !0;
  14. } else {
  15. if (ax && r > m && (h.offsetHeight <= m || f.offsetHeight <= m)) {
  16. const l = document.createElement("div");
  17. l.style.cssText =
  18. "position:absolute; z-index:-10000; top:0; left:0; right:0; height:" +
  19. aK.scrollHeight +
  20. "px";
  21. document.body.appendChild(l);
  22. let k;
  23. aE = function () {
  24. k ||
  25. (k = setTimeout(function () {
  26. l.style.height = "0";
  27. l.style.height = aK.scrollHeight + "px";
  28. k = null;
  29. }, 500));
  30. };
  31. setTimeout(aE, 10);
  32. window.addEventListener("resize", aE, !1);
  33. aA = new av(aE);
  34. aA.observe(h, { attributes: !0, childList: !0, characterData: !1 });
  35. aK.offsetHeight <= m &&
  36. ((m = document.createElement("div")),
  37. (m.style.clear = "both"),
  38. h.appendChild(m));
  39. }
  40. }
  41. aO.fixedBackground ||
  42. ((h.style.backgroundAttachment = "scroll"),
  43. (f.style.backgroundAttachment = "scroll"));
  44. }
  45. }
  46. function af(h, f, m) {
  47. b(f, m);
  48. if (aO.accelerationMax != 1) {
  49. var r = Date.now() - ao;
  50. r < aO.accelerationDelta &&
  51. ((r = (1 + 50 / r) / 2),
  52. r > 1 && ((r = Math.min(r, aO.accelerationMax)), (f *= r), (m *= r)));
  53. ao = Date.now();
  54. }
  55. aH.push({
  56. x: f,
  57. y: m,
  58. lastX: f < 0 ? 0.99 : -0.99,
  59. lastY: m < 0 ? 0.99 : -0.99,
  60. start: Date.now(),
  61. });
  62. if (!an) {
  63. r = ae();
  64. const l = h === r || h === document.body;
  65. h.$scrollBehavior == null &&
  66. ay(h) &&
  67. ((h.$scrollBehavior = h.style.scrollBehavior),
  68. (h.style.scrollBehavior = "auto"));
  69. var k = function (y) {
  70. y = Date.now();
  71. for (var t = 0, g = 0, u = 0; u < aH.length; u++) {
  72. const x = aH[u];
  73. let w = y - x.start;
  74. const a = w >= aO.animationTime;
  75. let v = a ? 1 : w / aO.animationTime;
  76. aO.pulseAlgorithm &&
  77. ((w = v),
  78. w >= 1
  79. ? (v = 1)
  80. : w <= 0
  81. ? (v = 0)
  82. : (aO.pulseNormalize == 1 && (aO.pulseNormalize /= ad(1)),
  83. (v = ad(w))));
  84. w = (x.x * v - x.lastX) >> 0;
  85. v = (x.y * v - x.lastY) >> 0;
  86. t += w;
  87. g += v;
  88. x.lastX += w;
  89. x.lastY += v;
  90. a && (aH.splice(u, 1), u--);
  91. }
  92. l
  93. ? window.scrollBy(t, g)
  94. : (t && (h.scrollLeft += t), g && (h.scrollTop += g));
  95. f || m || (aH = []);
  96. aH.length
  97. ? ac(k, h, 1000 / aO.frameRate + 1)
  98. : ((an = !1),
  99. h.$scrollBehavior != null &&
  100. ((h.style.scrollBehavior = h.$scrollBehavior),
  101. (h.$scrollBehavior = null)));
  102. };
  103. ac(k, h, 0);
  104. an = !0;
  105. }
  106. }
  107. function ab(g) {
  108. ap || aq();
  109. let f = g.target;
  110. if (
  111. g.defaultPrevented ||
  112. g.ctrlKey ||
  113. aI(aJ, "embed") ||
  114. (aI(f, "embed") && /\.pdf/i.test(f.src)) ||
  115. aI(aJ, "object") ||
  116. f.shadowRoot
  117. ) {
  118. return !0;
  119. }
  120. let h = -g.wheelDeltaX || g.deltaX || 0;
  121. let k = -g.wheelDeltaY || g.deltaY || 0;
  122. c &&
  123. (g.wheelDeltaX &&
  124. aD(g.wheelDeltaX, 120) &&
  125. (h = (g.wheelDeltaX / Math.abs(g.wheelDeltaX)) * -120),
  126. g.wheelDeltaY &&
  127. aD(g.wheelDeltaY, 120) &&
  128. (k = (g.wheelDeltaY / Math.abs(g.wheelDeltaY)) * -120));
  129. h || k || (k = -g.wheelDelta || 0);
  130. g.deltaMode === 1 && ((h *= 40), (k *= 40));
  131. f = s(f);
  132. if (!f) {
  133. return aF && am
  134. ? (Object.defineProperty(g, "target", { value: window.frameElement }),
  135. (g = new g.constructor(g.type, g)),
  136. parent.dispatchEvent(g))
  137. : !0;
  138. }
  139. if (az(k)) {
  140. return !0;
  141. }
  142. Math.abs(h) > 1.2 && (h *= aO.stepSize / 120);
  143. Math.abs(k) > 1.2 && (k *= aO.stepSize / 120);
  144. af(f, h, k);
  145. g.preventDefault();
  146. q();
  147. }
  148. function ag(g) {
  149. let f = g.target;
  150. let m =
  151. g.ctrlKey ||
  152. g.altKey ||
  153. g.metaKey ||
  154. (g.shiftKey && g.keyCode !== aN.spacebar);
  155. document.body.contains(aJ) || (aJ = document.activeElement);
  156. let r = /^(textarea|select|embed|object)$/i;
  157. let l = /^(button|submit|radio|checkbox|file|color|image)$/i;
  158. if (
  159. !(r =
  160. g.defaultPrevented ||
  161. r.test(f.nodeName) ||
  162. (aI(f, "input") && !l.test(f.type)) ||
  163. aI(aJ, "video"))
  164. ) {
  165. r = g.target;
  166. let k = !1;
  167. if (document.URL.indexOf("www.youtube.com/watch") != -1) {
  168. do {
  169. if (
  170. (k = r.classList && r.classList.contains("html5-video-controls"))
  171. ) {
  172. break;
  173. }
  174. } while ((r = r.parentNode));
  175. }
  176. r = k;
  177. }
  178. if (
  179. r ||
  180. f.isContentEditable ||
  181. m ||
  182. ((aI(f, "button") || (aI(f, "input") && l.test(f.type))) &&
  183. g.keyCode === aN.spacebar) ||
  184. (aI(f, "input") && f.type == "radio" && aw[g.keyCode])
  185. ) {
  186. return !0;
  187. }
  188. r = f = 0;
  189. m = s(aJ);
  190. if (!m) {
  191. return aF && am ? parent.keydown(g) : !0;
  192. }
  193. l = m.clientHeight;
  194. m == document.body && (l = window.innerHeight);
  195. switch (g.keyCode) {
  196. case aN.up:
  197. r = -aO.arrowScroll;
  198. break;
  199. case aN.down:
  200. r = aO.arrowScroll;
  201. break;
  202. case aN.spacebar:
  203. r = g.shiftKey ? 1 : -1;
  204. r = -r * l * 0.9;
  205. break;
  206. case aN.pageup:
  207. r = 0.9 * -l;
  208. break;
  209. case aN.pagedown:
  210. r = 0.9 * l;
  211. break;
  212. case aN.home:
  213. m == document.body &&
  214. document.scrollingElement &&
  215. (m = document.scrollingElement);
  216. r = -m.scrollTop;
  217. break;
  218. case aN.end:
  219. l = m.scrollHeight - m.scrollTop - l;
  220. r = l > 0 ? l + 10 : 0;
  221. break;
  222. case aN.left:
  223. f = -aO.arrowScroll;
  224. break;
  225. case aN.right:
  226. f = aO.arrowScroll;
  227. break;
  228. default:
  229. return !0;
  230. }
  231. af(m, f, r);
  232. g.preventDefault();
  233. q();
  234. }
  235. function p(f) {
  236. aJ = f.target;
  237. }
  238. function q() {
  239. clearTimeout(o);
  240. o = setInterval(function () {
  241. n = al = at = {};
  242. }, 1000);
  243. }
  244. function ak(g, f, h) {
  245. h = h ? n : al;
  246. for (let k = g.length; k--; ) {
  247. h[aj(g[k])] = f;
  248. }
  249. return f;
  250. }
  251. function s(g) {
  252. const f = [];
  253. const k = document.body;
  254. const l = aK.scrollHeight;
  255. do {
  256. let h = al[aj(g)];
  257. if (h) {
  258. return ak(f, h);
  259. }
  260. f.push(g);
  261. if (l === g.scrollHeight) {
  262. if (
  263. ((h = (j(aK) && j(k)) || i(aK)),
  264. (aF && aK.clientHeight + 10 < aK.scrollHeight) || (!aF && h))
  265. ) {
  266. return ak(f, ae());
  267. }
  268. } else {
  269. if (g.clientHeight + 10 < g.scrollHeight && i(g)) {
  270. return ak(f, g);
  271. }
  272. }
  273. } while ((g = g.parentElement));
  274. }
  275. function j(f) {
  276. return getComputedStyle(f, "").getPropertyValue("overflow-y") !== "hidden";
  277. }
  278. function i(f) {
  279. f = getComputedStyle(f, "").getPropertyValue("overflow-y");
  280. return f === "scroll" || f === "auto";
  281. }
  282. function ay(g) {
  283. const f = aj(g);
  284. at[f] == null &&
  285. ((g = getComputedStyle(g, "")["scroll-behavior"]),
  286. (at[f] = g == "smooth"));
  287. return at[f];
  288. }
  289. function aI(g, f) {
  290. return g && (g.nodeName || "").toLowerCase() === f.toLowerCase();
  291. }
  292. function b(g, f) {
  293. g = g > 0 ? 1 : -1;
  294. f = f > 0 ? 1 : -1;
  295. if (ar.x !== g || ar.y !== f) {
  296. (ar.x = g), (ar.y = f), (aH = []), (ao = 0);
  297. }
  298. }
  299. function az(f) {
  300. if (f) {
  301. return (
  302. aM.length || (aM = [f, f, f]),
  303. (f = Math.abs(f)),
  304. aM.push(f),
  305. aM.shift(),
  306. clearTimeout(d),
  307. (d = setTimeout(function () {
  308. try {
  309. localStorage.SS_deltaBuffer = aM.join(",");
  310. } catch (a) {}
  311. }, 1000)),
  312. (f = f > 120 && ai(f)),
  313. !ai(120) && !ai(100) && !f
  314. );
  315. }
  316. }
  317. function aD(g, f) {
  318. return Math.floor(g / f) == g / f;
  319. }
  320. function ai(f) {
  321. return aD(aM[0], f) && aD(aM[1], f) && aD(aM[2], f);
  322. }
  323. function ad(g) {
  324. g *= aO.pulseScale;
  325. if (g < 1) {
  326. var f = g - (1 - Math.exp(-g));
  327. } else {
  328. (f = Math.exp(-1)), (g = 1 - Math.exp(-(g - 1))), (f += g * (1 - f));
  329. }
  330. return f * aO.pulseNormalize;
  331. }
  332. function aB(g) {
  333. for (const f in g) {
  334. au.hasOwnProperty(f) && (aO[f] = g[f]);
  335. }
  336. }
  337. var au = {
  338. frameRate: 150,
  339. animationTime: 400,
  340. stepSize: 100,
  341. pulseAlgorithm: !0,
  342. pulseScale: 4,
  343. pulseNormalize: 1,
  344. accelerationDelta: 50,
  345. accelerationMax: 3,
  346. keyboardSupport: !0,
  347. arrowScroll: 50,
  348. fixedBackground: !0,
  349. excluded: "",
  350. };
  351. var aO = au;
  352. var aF = !1;
  353. var ar = { x: 0, y: 0 };
  354. var ap = !1;
  355. var aK = document.documentElement;
  356. let aJ;
  357. let aA;
  358. let aE;
  359. var aM = [];
  360. let d;
  361. var c = /^Mac/.test(navigator.platform);
  362. var aN = {
  363. left: 37,
  364. up: 38,
  365. right: 39,
  366. down: 40,
  367. spacebar: 32,
  368. pageup: 33,
  369. pagedown: 34,
  370. end: 35,
  371. home: 36,
  372. };
  373. var aw = { 37: 1, 38: 1, 39: 1, 40: 1 };
  374. var aH = [];
  375. var an = !1;
  376. var ao = Date.now();
  377. var aj = (function () {
  378. let f = 0;
  379. return function (a) {
  380. return a.uniqueID || (a.uniqueID = f++);
  381. };
  382. })();
  383. var n = {};
  384. var al = {};
  385. let o;
  386. var at = {};
  387. if (window.localStorage && localStorage.SS_deltaBuffer) {
  388. try {
  389. aM = localStorage.SS_deltaBuffer.split(",");
  390. } catch (aP) {}
  391. }
  392. var ac = (function () {
  393. return (
  394. window.requestAnimationFrame ||
  395. window.webkitRequestAnimationFrame ||
  396. window.mozRequestAnimationFrame ||
  397. function (g, f, h) {
  398. window.setTimeout(g, h || 1000 / 60);
  399. }
  400. );
  401. })();
  402. var av =
  403. window.MutationObserver ||
  404. window.WebKitMutationObserver ||
  405. window.MozMutationObserver;
  406. var ae = (function () {
  407. let f = document.scrollingElement;
  408. return function () {
  409. if (!f) {
  410. const a = document.createElement("div");
  411. a.style.cssText = "height:10000px;width:1px;";
  412. document.body.appendChild(a);
  413. const g = document.body.scrollTop;
  414. window.scrollBy(0, 3);
  415. f =
  416. document.body.scrollTop != g
  417. ? document.body
  418. : document.documentElement;
  419. window.scrollBy(0, -3);
  420. document.body.removeChild(a);
  421. }
  422. return f;
  423. };
  424. })();
  425. let aL = window.navigator.userAgent;
  426. let aG = /Edge/.test(aL);
  427. var am = /chrome/i.test(aL) && !aG;
  428. aG = /safari/i.test(aL) && !aG;
  429. const e = /mobile/i.test(aL);
  430. const aC = /Windows NT 6.1/i.test(aL) && /rv:11/i.test(aL);
  431. var ax = aG && (/Version\/8/i.test(aL) || /Version\/9/i.test(aL));
  432. aL = (am || aG || aC) && !e;
  433. let aQ = !1;
  434. try {
  435. window.addEventListener(
  436. "test",
  437. null,
  438. Object.defineProperty({}, "passive", {
  439. get: function () {
  440. aQ = !0;
  441. },
  442. })
  443. );
  444. } catch (aP) {}
  445. aG = aQ ? { passive: !1 } : !1;
  446. const ah =
  447. "onwheel" in document.createElement("div") ? "wheel" : "mousewheel";
  448. ah &&
  449. aL &&
  450. (window.addEventListener(ah, ab, aG || !1),
  451. window.addEventListener("mousedown", p, !1),
  452. window.addEventListener("load", aq, !1));
  453. aB.destroy = function () {
  454. aA && aA.disconnect();
  455. window.removeEventListener(ah, ab, !1);
  456. window.removeEventListener("mousedown", p, !1);
  457. window.removeEventListener("keydown", ag, !1);
  458. window.removeEventListener("resize", aE, !1);
  459. window.removeEventListener("load", aq, !1);
  460. };
  461. window.SmoothScrollOptions && aB(window.SmoothScrollOptions);
  462. typeof define === "function" && define.amd
  463. ? define(function () {
  464. return aB;
  465. })
  466. : typeof exports === "object"
  467. ? (module.exports = aB)
  468. : (window.SmoothScroll = aB);
  469. })();