2 lines
6.7 KiB
JavaScript
2 lines
6.7 KiB
JavaScript
window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;0<=--t&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),function(){if("function"==typeof window.CustomEvent)return;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}e.prototype=window.Event.prototype,window.CustomEvent=e}(),function(){for(var a=0,e=["ms","moz","webkit","o"],t=0;t<e.length&&!window.requestAnimationFrame;++t)window.requestAnimationFrame=window[e[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[t]+"CancelAnimationFrame"]||window[e[t]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e,t){var n=(new Date).getTime(),o=Math.max(0,16-(n-a)),i=window.setTimeout(function(){e(n+o)},o);return a=n+o,i}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)})}(),function(e,t){"function"==typeof define&&define.amd?define([],function(){return t(e)}):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(A){"use strict";var C={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,clip:!0,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},q=function(){for(var n={},e=function(e){for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t])},t=0;t<arguments.length;t++)e(arguments[t]);return n},c=function(t){var n;try{n=decodeURIComponent(t)}catch(e){n=t}return n},s=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n,o=String(e),i=o.length,a=-1,r="",c=o.charCodeAt(0);++a<i;){if(0===(t=o.charCodeAt(a)))throw new InvalidCharacterError("Invalid character: the input contains U+0000.");1<=t&&t<=31||127==t||0===a&&48<=t&&t<=57||1===a&&48<=t&&t<=57&&45===c?r+="\\"+t.toString(16)+" ":r+=128<=t||45===t||95===t||48<=t&&t<=57||65<=t&&t<=90||97<=t&&t<=122?o.charAt(a):"\\"+o.charAt(a)}try{n=decodeURIComponent("#"+r)}catch(e){n="#"+r}return n},O=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},H=function(e){return e?(t=e,parseInt(A.getComputedStyle(t).height,10)+e.offsetTop):0;var t},I=function(e,t,n,o){if(t.emitEvents&&"function"==typeof A.CustomEvent){var i=new CustomEvent(e,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(i)}};return function(o,e){var v,i,w,b,t,S,E={};E.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||I("scrollCancel",v)},E.animateScroll=function(r,c,e){var s=q(v||C,e||{}),u="[object Number]"===Object.prototype.toString.call(r),t=u||!r.tagName?null:r;if(u||t){var l=A.pageYOffset;s.header&&!w&&(w=document.querySelector(s.header)),b||(b=H(w));var m,i,a,n,o,d=u?r:function(e,t,n,o){var i=0;if(e.offsetParent)for(;i+=e.offsetTop,e=e.offsetParent;);return i=Math.max(i-t-n,0),o&&(i=Math.min(i,O()-A.innerHeight)),i}(t,b,parseInt("function"==typeof s.offset?s.offset(r,c):s.offset,10),s.clip),f=d-l,h=O(),p=0,g=function(e,t){var n,o,i,a=A.pageYOffset;if(e==t||a==t||(l<t&&A.innerHeight+a)>=h)return E.cancelScroll(!0),o=t,i=u,0===(n=r)&&document.body.focus(),i||(n.focus(),document.activeElement!==n&&(n.setAttribute("tabindex","-1"),n.focus(),n.style.outline="none"),A.scrollTo(0,o)),I("scrollStop",s,r,c),!(S=m=null)},y=function(e){var t,n,o;m||(m=e),i=(p+=e-m)/parseInt(s.speed,10),a=l+f*(n=i=1<i?1:i,"easeInQuad"===(t=s).easing&&(o=n*n),"easeOutQuad"===t.easing&&(o=n*(2-n)),"easeInOutQuad"===t.easing&&(o=n<.5?2*n*n:(4-2*n)*n-1),"easeInCubic"===t.easing&&(o=n*n*n),"easeOutCubic"===t.easing&&(o=--n*n*n+1),"easeInOutCubic"===t.easing&&(o=n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1),"easeInQuart"===t.easing&&(o=n*n*n*n),"easeOutQuart"===t.easing&&(o=1- --n*n*n*n),"easeInOutQuart"===t.easing&&(o=n<.5?8*n*n*n*n:1-8*--n*n*n*n),"easeInQuint"===t.easing&&(o=n*n*n*n*n),"easeOutQuint"===t.easing&&(o=1+--n*n*n*n*n),"easeInOutQuint"===t.easing&&(o=n<.5?16*n*n*n*n*n:1+16*--n*n*n*n*n),t.customEasing&&(o=t.customEasing(n)),o||n),A.scrollTo(0,Math.floor(a)),g(a,d)||(S=A.requestAnimationFrame(y),m=e)};0===A.pageYOffset&&A.scrollTo(0,0),n=r,o=s,u||history.pushState&&o.updateURL&&history.pushState({smoothScroll:JSON.stringify(o),anchor:n.id},document.title,n===document.documentElement?"#top":"#"+n.id),I("scrollStart",s,r,c),E.cancelScroll(!0),A.requestAnimationFrame(y)}};var n=function(e){if(!("matchMedia"in A&&A.matchMedia("(prefers-reduced-motion)").matches)&&0===e.button&&!e.metaKey&&!e.ctrlKey&&"closest"in e.target&&(i=e.target.closest(o))&&"a"===i.tagName.toLowerCase()&&!e.target.closest(v.ignore)&&i.hostname===A.location.hostname&&i.pathname===A.location.pathname&&/#/.test(i.href)){var t=s(c(i.hash)),n=v.topOnEmptyHash&&"#"===t?document.documentElement:document.querySelector(t);(n=n||"#top"!==t?n:document.documentElement)&&(e.preventDefault(),E.animateScroll(n,i))}},a=function(e){if(null!==history.state&&history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(v)&&history.state.anchor){var t=document.querySelector(s(c(history.state.anchor)));t&&E.animateScroll(t,null,{updateURL:!1})}},r=function(e){t||(t=setTimeout(function(){t=null,b=H(w)},66))};return E.destroy=function(){v&&(document.removeEventListener("click",n,!1),A.removeEventListener("resize",r,!1),A.removeEventListener("popstate",a,!1),E.cancelScroll(),S=t=b=w=i=v=null)},E.init=function(e){if(!("querySelector"in document&&"addEventListener"in A&&"requestAnimationFrame"in A&&"closest"in A.Element.prototype))throw"Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.";E.destroy(),v=q(C,e||{}),w=v.header?document.querySelector(v.header):null,b=H(w),document.addEventListener("click",n,!1),w&&A.addEventListener("resize",r,!1),v.updateURL&&v.popstate&&A.addEventListener("popstate",a,!1)},E.init(e),E}});var gpscroll=new SmoothScroll(smooth.elements.join(),{speed:smooth.duration,offset:function(e,t){var n=document.body,o=document.querySelector("#site-navigation"),i=document.querySelector("#sticky-navigation"),a=document.querySelector("#mobile-header"),r=document.querySelector(".menu-toggle"),c=0;return a&&(a.offsetWidth||a.offsetHeight||a.getClientRects().length)?n.classList.contains("mobile-header-sticky")&&(c+=a.clientHeight):r&&(r.offsetWidth||r.offsetHeight||r.getClientRects().length)?(n.classList.contains("both-sticky-menu")||n.classList.contains("mobile-sticky-menu"))&&(i?c+=i.clientHeight:o&&(c+=o.clientHeight)):(n.classList.contains("both-sticky-menu")||n.classList.contains("desktop-sticky-menu"))&&(i?c+=i.clientHeight:o&&(c+=o.clientHeight)),c}});
|