|
1 | | -/*! |
2 | | - * smooth-scroll v16.1.4 |
3 | | - * Animate scrolling to anchor links |
4 | | - * (c) 2020 Chris Ferdinandi |
5 | | - * MIT License |
6 | | - * http://github.com/cferdinandi/smooth-scroll |
7 | | - */ |
8 | | - |
9 | | -/** |
10 | | - * closest() polyfill |
11 | | - * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill |
12 | | - */ |
13 | | -if (window.Element && !Element.prototype.closest) { |
14 | | - Element.prototype.closest = function(s) { |
15 | | - var matches = (this.document || this.ownerDocument).querySelectorAll(s), |
16 | | - i, |
17 | | - el = this; |
18 | | - do { |
19 | | - i = matches.length; |
20 | | - while (--i >= 0 && matches.item(i) !== el) {} |
21 | | - } while ((i < 0) && (el = el.parentElement)); |
22 | | - return el; |
23 | | - }; |
24 | | -} |
| 1 | +/*! SmoothScroll v16.1.4 | (c) 2020 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */ |
| 2 | +(function (global, factory) { |
| 3 | + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 4 | + typeof define === 'function' && define.amd ? define(factory) : |
| 5 | + (global = global || self, global.SmoothScroll = factory()); |
| 6 | +}(this, (function () { 'use strict'; |
25 | 7 |
|
26 | | -/** |
27 | | - * CustomEvent() polyfill |
28 | | - * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill |
29 | | - */ |
30 | | -(function () { |
| 8 | + /** |
| 9 | + * closest() polyfill |
| 10 | + * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill |
| 11 | + */ |
| 12 | + if (window.Element && !Element.prototype.closest) { |
| 13 | + Element.prototype.closest = function(s) { |
| 14 | + var matches = (this.document || this.ownerDocument).querySelectorAll(s), |
| 15 | + i, |
| 16 | + el = this; |
| 17 | + do { |
| 18 | + i = matches.length; |
| 19 | + while (--i >= 0 && matches.item(i) !== el) {} |
| 20 | + } while ((i < 0) && (el = el.parentElement)); |
| 21 | + return el; |
| 22 | + }; |
| 23 | + } |
31 | 24 |
|
32 | | - if (typeof window.CustomEvent === "function") return false; |
| 25 | + /** |
| 26 | + * CustomEvent() polyfill |
| 27 | + * https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill |
| 28 | + */ |
| 29 | + (function () { |
33 | 30 |
|
34 | | - function CustomEvent(event, params) { |
35 | | - params = params || { bubbles: false, cancelable: false, detail: undefined }; |
36 | | - var evt = document.createEvent('CustomEvent'); |
37 | | - evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); |
38 | | - return evt; |
39 | | - } |
| 31 | + if (typeof window.CustomEvent === "function") return false; |
40 | 32 |
|
41 | | - CustomEvent.prototype = window.Event.prototype; |
42 | | - |
43 | | - window.CustomEvent = CustomEvent; |
44 | | -})(); |
45 | | -/** |
46 | | - * requestAnimationFrame() polyfill |
47 | | - * By Erik Möller. Fixes from Paul Irish and Tino Zijdel. |
48 | | - * @link http://paulirish.com/2011/requestanimationframe-for-smart-animating/ |
49 | | - * @link http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating |
50 | | - * @license MIT |
51 | | - */ |
52 | | -(function() { |
53 | | - var lastTime = 0; |
54 | | - var vendors = ['ms', 'moz', 'webkit', 'o']; |
55 | | - for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { |
56 | | - window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; |
57 | | - window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || |
58 | | - window[vendors[x]+'CancelRequestAnimationFrame']; |
59 | | - } |
| 33 | + function CustomEvent(event, params) { |
| 34 | + params = params || { bubbles: false, cancelable: false, detail: undefined }; |
| 35 | + var evt = document.createEvent('CustomEvent'); |
| 36 | + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); |
| 37 | + return evt; |
| 38 | + } |
60 | 39 |
|
61 | | - if (!window.requestAnimationFrame) { |
62 | | - window.requestAnimationFrame = function(callback, element) { |
63 | | - var currTime = new Date().getTime(); |
64 | | - var timeToCall = Math.max(0, 16 - (currTime - lastTime)); |
65 | | - var id = window.setTimeout((function() { callback(currTime + timeToCall); }), |
66 | | - timeToCall); |
67 | | - lastTime = currTime + timeToCall; |
68 | | - return id; |
69 | | - }; |
70 | | - } |
| 40 | + CustomEvent.prototype = window.Event.prototype; |
71 | 41 |
|
72 | | - if (!window.cancelAnimationFrame) { |
73 | | - window.cancelAnimationFrame = function(id) { |
74 | | - clearTimeout(id); |
75 | | - }; |
76 | | - } |
77 | | -}()); |
78 | | - |
79 | | -(function (root, factory) { |
80 | | - if (typeof define === 'function' && define.amd) { |
81 | | - define([], (function () { |
82 | | - return factory(root); |
83 | | - })); |
84 | | - } else if (typeof exports === 'object') { |
85 | | - module.exports = factory(root); |
86 | | - } else { |
87 | | - root.SmoothScroll = factory(root); |
88 | | - } |
89 | | -})(typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this, (function (window) { |
| 42 | + window.CustomEvent = CustomEvent; |
| 43 | + })(); |
90 | 44 |
|
91 | | - 'use strict'; |
| 45 | + /** |
| 46 | + * requestAnimationFrame() polyfill |
| 47 | + * By Erik Möller. Fixes from Paul Irish and Tino Zijdel. |
| 48 | + * @link http://paulirish.com/2011/requestanimationframe-for-smart-animating/ |
| 49 | + * @link http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating |
| 50 | + * @license MIT |
| 51 | + */ |
| 52 | + (function() { |
| 53 | + var lastTime = 0; |
| 54 | + var vendors = ['ms', 'moz', 'webkit', 'o']; |
| 55 | + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { |
| 56 | + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; |
| 57 | + window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || |
| 58 | + window[vendors[x]+'CancelRequestAnimationFrame']; |
| 59 | + } |
| 60 | + |
| 61 | + if (!window.requestAnimationFrame) { |
| 62 | + window.requestAnimationFrame = function(callback, element) { |
| 63 | + var currTime = new Date().getTime(); |
| 64 | + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); |
| 65 | + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, |
| 66 | + timeToCall); |
| 67 | + lastTime = currTime + timeToCall; |
| 68 | + return id; |
| 69 | + }; |
| 70 | + } |
| 71 | + |
| 72 | + if (!window.cancelAnimationFrame) { |
| 73 | + window.cancelAnimationFrame = function(id) { |
| 74 | + clearTimeout(id); |
| 75 | + }; |
| 76 | + } |
| 77 | + }()); |
92 | 78 |
|
93 | 79 | // |
94 | 80 | // Default settings |
@@ -147,12 +133,12 @@ if (window.Element && !Element.prototype.closest) { |
147 | 133 | */ |
148 | 134 | var extend = function () { |
149 | 135 | var merged = {}; |
150 | | - Array.prototype.forEach.call(arguments, (function (obj) { |
| 136 | + Array.prototype.forEach.call(arguments, function (obj) { |
151 | 137 | for (var key in obj) { |
152 | 138 | if (!obj.hasOwnProperty(key)) return; |
153 | 139 | merged[key] = obj[key]; |
154 | 140 | } |
155 | | - })); |
| 141 | + }); |
156 | 142 | return merged; |
157 | 143 | }; |
158 | 144 |
|
@@ -319,7 +305,7 @@ if (window.Element && !Element.prototype.closest) { |
319 | 305 | if (clip) { |
320 | 306 | location = Math.min(location, getDocumentHeight() - window.innerHeight); |
321 | 307 | } |
322 | | - return location; |
| 308 | + return location; |
323 | 309 | }; |
324 | 310 |
|
325 | 311 | /** |
@@ -449,7 +435,7 @@ if (window.Element && !Element.prototype.closest) { |
449 | 435 | // |
450 | 436 |
|
451 | 437 | var smoothScroll = {}; // Object for public APIs |
452 | | - var settings, anchor, toggle, fixedHeader, eventTimeout, animationInterval; |
| 438 | + var settings, toggle, fixedHeader, animationInterval; |
453 | 439 |
|
454 | 440 |
|
455 | 441 | // |
@@ -661,10 +647,8 @@ if (window.Element && !Element.prototype.closest) { |
661 | 647 |
|
662 | 648 | // Reset variables |
663 | 649 | settings = null; |
664 | | - anchor = null; |
665 | 650 | toggle = null; |
666 | 651 | fixedHeader = null; |
667 | | - eventTimeout = null; |
668 | 652 | animationInterval = null; |
669 | 653 |
|
670 | 654 | }; |
@@ -713,4 +697,4 @@ if (window.Element && !Element.prototype.closest) { |
713 | 697 |
|
714 | 698 | return SmoothScroll; |
715 | 699 |
|
716 | | -})); |
| 700 | +}))); |
0 commit comments