!function(n,t){"function"==typeof define&&define.amd?define([],t(n)):"object"==typeof exports?module.exports=t(n):n.smoothScroll=t(n)}("undefined"!=typeof global?global:this.window||this.global,function(n){"use strict";var i,f,t,r,u={},l="querySelector"in document&&"addEventListener"in n,c={selector:"[data-scroll]",selectorHeader:"[data-scroll-header]",speed:500,easing:"easeInOutCubic",offset:0,updateURL:!0,callback:function(){}},e=function(){var n={},i=!1,t=0,f=arguments.length,r,u;for("[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(i=arguments[0],t++),r=function(t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=i&&"[object Object]"===Object.prototype.toString.call(t[r])?e(!0,n[r],t[r]):t[r])};f>t;t++)u=arguments[t],r(u);return n},a=function(n){return Math.max(n.scrollHeight,n.offsetHeight,n.clientHeight)},v=function(n,t){var i,u,r=t.charAt(0),f="classList"in document.documentElement;for("["===r&&(t=t.substr(1,t.length-2),i=t.split("="),i.length>1&&(u=!0,i[1]=i[1].replace(/"/g,"").replace(/'/g,"")));n&&n!==document;n=n.parentNode){if("."===r)if(f){if(n.classList.contains(t.substr(1)))return n}else if(new RegExp("(^|\\s)"+t.substr(1)+"(\\s|$)").test(n.className))return n;if("#"===r&&n.id===t.substr(1)||"["===r&&n.hasAttribute(i[0])&&(!u||n.getAttribute(i[0])===i[1])||n.tagName.toLowerCase()===t)return n}return null},y=function(n){for(var t,r=String(n),f=r.length,i=-1,u="",e=r.charCodeAt(0);++i<f;){if(t=r.charCodeAt(i),0===t)throw new InvalidCharacterError("Invalid character: the input contains U+0000.");u+=t>=1&&31>=t||127==t||0===i&&t>=48&&57>=t||1===i&&t>=48&&57>=t&&45===e?"\\"+t.toString(16)+" ":t>=128||45===t||95===t||t>=48&&57>=t||t>=65&&90>=t||t>=97&&122>=t?r.charAt(i):"\\"+r.charAt(i)}return u},p=function(n,t){var i;return"easeInQuad"===n&&(i=t*t),"easeOutQuad"===n&&(i=t*(2-t)),"easeInOutQuad"===n&&(i=.5>t?2*t*t:-1+(4-2*t)*t),"easeInCubic"===n&&(i=t*t*t),"easeOutCubic"===n&&(i=--t*t*t+1),"easeInOutCubic"===n&&(i=.5>t?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===n&&(i=t*t*t*t),"easeOutQuart"===n&&(i=1- --t*t*t*t),"easeInOutQuart"===n&&(i=.5>t?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===n&&(i=t*t*t*t*t),"easeOutQuint"===n&&(i=1+--t*t*t*t*t),"easeInOutQuint"===n&&(i=.5>t?16*t*t*t*t*t:1+16*--t*t*t*t*t),i||t},w=function(n,t,i){var r=0;if(n.offsetParent)do r+=n.offsetTop,n=n.offsetParent;while(n);return r=r-t-i,r>=0?r:0},b=function(){return Math.max(n.document.body.scrollHeight,n.document.documentElement.scrollHeight,n.document.body.offsetHeight,n.document.documentElement.offsetHeight,n.document.body.clientHeight,n.document.documentElement.clientHeight)},k=function(n){return n&&"object"==typeof JSON&&"function"==typeof JSON.parse?JSON.parse(n):{}},d=function(t,i){n.history.pushState&&(i||"true"===i)&&n.history.pushState(null,null,[n.location.protocol,"//",n.location.host,n.location.pathname,n.location.search,t].join(""))},o=function(n){return null===n?0:a(n)+n.offsetTop},s,h;return u.animateScroll=function(i,u,f){var it=k(i?i.getAttribute("data-options"):null),s=e(s||c,f||{},it),l,a;u="#"+y(u.substr(1));l="#"===u?n.document.documentElement:n.document.querySelector(u);a=n.pageYOffset;t||(t=n.document.querySelector(s.selectorHeader));r||(r=o(t));var g,h,v,nt=w(l,r,parseInt(s.offset,10)),rt=nt-a,ut=b(),tt=0;d(u,s.updateURL);var ft=function(t,r,f){var e=n.pageYOffset;(t==r||e==r||n.innerHeight+e>=ut)&&(clearInterval(f),l.focus(),s.callback(i,u))},et=function(){tt+=16;h=tt/parseInt(s.speed,10);h=h>1?1:h;v=a+rt*p(s.easing,h);n.scrollTo(0,Math.floor(v));ft(v,nt,g)},ot=function(){g=setInterval(et,16)};0===n.pageYOffset&&n.scrollTo(0,0);ot()},s=function(n){var t=v(n.target,i.selector);t&&"a"===t.tagName.toLowerCase()&&(n.preventDefault(),u.animateScroll(t,t.hash,i))},h=function(){f||(f=setTimeout(function(){f=null;r=o(t)},66))},u.destroy=function(){i&&(n.document.removeEventListener("click",s,!1),n.removeEventListener("resize",h,!1),i=null,f=null,t=null,r=null)},u.init=function(f){l&&(u.destroy(),i=e(c,f||{}),t=n.document.querySelector(i.selectorHeader),r=o(t),n.document.addEventListener("click",s,!1),t&&n.addEventListener("resize",h,!1))},u})