UNPKG

iscrolljs

Version:
1 lines 4.75 kB
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};(function(){"use strict";var a={historySetting:!0,selector:".navigation__link",eventEmitting:!0};!function(){function a(a){return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)}function b(){function b(a,b){this.scrollLeft=a,this.scrollTop=b}function k(a){return .5*(1-Math.cos(Math.PI*a))}function e(a){if(null===a||"object"!=("undefined"==typeof a?"undefined":_typeof(a))||void 0===a.behavior||"auto"===a.behavior||"instant"===a.behavior)return!0;if("object"==("undefined"==typeof a?"undefined":_typeof(a))&&"smooth"===a.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")}function i(a,b){return"Y"===b?a.clientHeight+p<a.scrollHeight:"X"===b?a.clientWidth+p<a.scrollWidth:void 0}function m(a,b){var c=g.getComputedStyle(a,null)["overflow"+b];return"auto"===c||"scroll"===c}function c(a){var b=i(a,"Y")&&m(a,"Y"),c=i(a,"X")&&m(a,"X");return b||c}function l(a){var b;do b=(a=a.parentNode)===j.body;while(!1===b&&!1===c(a));return b=null,a}function q(a){var b,c,e,f=(u()-a.startTime)/d;b=k(f=1<f?1:f),c=a.startX+(a.x-a.startX)*b,e=a.startY+(a.y-a.startY)*b,a.method.call(a.scrollable,c,e),c===a.x&&e===a.y||g.requestAnimationFrame(q.bind(g,a))}function f(a,d,e){var k,l,m,o,t=u();a===j.body?(k=g,l=g.scrollX||g.pageXOffset,m=g.scrollY||g.pageYOffset,o=h.scroll):(k=a,l=a.scrollLeft,m=a.scrollTop,o=b),q({scrollable:k,method:o,startTime:t,startX:l,startY:m,x:d,y:e})}if(!("scrollBehavior"in j.documentElement.style&&!0!==g.__forceSmoothScrollPolyfill__)){var n=g.HTMLElement||g.Element,d=468,p=a(g.navigator.userAgent)?1:0,h={scroll:g.scroll||g.scrollTo,scrollBy:g.scrollBy,elementScroll:n.prototype.scroll||b,scrollIntoView:n.prototype.scrollIntoView},u=g.performance&&g.performance.now?g.performance.now.bind(g.performance):Date.now;g.scroll=g.scrollTo=function(){void 0!==arguments[0]&&(!0===e(arguments[0])?h.scroll.call(g,void 0===arguments[0].left?"object"==_typeof(arguments[0])?g.scrollX||g.pageXOffset:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?g.scrollY||g.pageYOffset:arguments[1]:arguments[0].top):f.call(g,j.body,void 0===arguments[0].left?g.scrollX||g.pageXOffset:~~arguments[0].left,void 0===arguments[0].top?g.scrollY||g.pageYOffset:~~arguments[0].top))},g.scrollBy=function(){void 0!==arguments[0]&&(e(arguments[0])?h.scrollBy.call(g,void 0===arguments[0].left?"object"==_typeof(arguments[0])?0:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?0:arguments[1]:arguments[0].top):f.call(g,j.body,~~arguments[0].left+(g.scrollX||g.pageXOffset),~~arguments[0].top+(g.scrollY||g.pageYOffset)))},n.prototype.scroll=n.prototype.scrollTo=function(){if(void 0!==arguments[0])if(!0!==e(arguments[0])){var a=arguments[0].left,b=arguments[0].top;f.call(this,this,void 0===a?this.scrollLeft:~~a,void 0===b?this.scrollTop:~~b)}else{if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value couldn't be converted");h.elementScroll.call(this,void 0===arguments[0].left?"object"==_typeof(arguments[0])?this.scrollLeft:~~arguments[0]:~~arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?this.scrollTop:~~arguments[1]:~~arguments[0].top)}},n.prototype.scrollBy=function(){void 0!==arguments[0]&&(!0===e(arguments[0])?h.elementScroll.call(this,void 0===arguments[0].left?~~arguments[0]+this.scrollLeft:~~arguments[0].left+this.scrollLeft,void 0===arguments[0].top?~~arguments[1]+this.scrollTop:~~arguments[0].top+this.scrollTop):this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior}))},n.prototype.scrollIntoView=function(){if(!0!==e(arguments[0])){var a=l(this),b=a.getBoundingClientRect(),c=this.getBoundingClientRect();a===j.body?g.scrollBy({left:c.left,top:c.top,behavior:"smooth"}):(f.call(this,a,a.scrollLeft+c.left-b.left,a.scrollTop+c.top-b.top),"fixed"!==g.getComputedStyle(a).position&&g.scrollBy({left:b.left,top:b.top,behavior:"smooth"}))}else h.scrollIntoView.call(this,void 0===arguments[0]||arguments[0])}}}var g=window,j=document;"object"==("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports={polyfill:b}:b()}();var b=a.selector,c=a.historySetting;document.querySelectorAll(b).forEach(function(a){var b=a.href;a.addEventListener("click",function(a){a.preventDefault(),document.getElementById(b.split("#")[1]).scrollIntoView({behavior:"smooth"}),c&&history.pushState(null,null,"/"+b.split("#")[1])})},!0)})();