sweet-scroll
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "sweet-scroll", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Modern and the sweet smooth scroll library.", | ||
@@ -47,3 +47,3 @@ "main": "sweet-scroll.js", | ||
"babel-eslint": "^6.0.4", | ||
"babel-plugin-espower": "^2.1.2", | ||
"babel-plugin-espower": "^2.2.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
@@ -53,6 +53,6 @@ "babel-preset-es2015-rollup": "^1.1.1", | ||
"babelify": "^7.3.0", | ||
"browser-sync": "^2.12.8", | ||
"browser-sync": "^2.13.0", | ||
"browserify": "^13.0.1", | ||
"copyfiles": "^0.2.1", | ||
"eslint": "^2.10.2", | ||
"eslint": "^2.12.0", | ||
"karma": "^0.13.22", | ||
@@ -66,10 +66,10 @@ "karma-browserify": "^5.0.5", | ||
"karma-phantomjs-shim": "^1.4.0", | ||
"mocha": "^2.4.5", | ||
"mocha": "^2.5.3", | ||
"node-sass": "^3.7.0", | ||
"onchange": "^2.4.0", | ||
"onchange": "^2.5.0", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"postcss-cli": "^2.5.2", | ||
"power-assert": "^1.4.1", | ||
"rollup": "^0.26.3", | ||
"rollup-plugin-babel": "^2.4.0", | ||
"rollup": "^0.31.1", | ||
"rollup-plugin-babel": "^2.5.1", | ||
"uglify-js": "^2.6.2", | ||
@@ -76,0 +76,0 @@ "watchify": "^3.7.0" |
@@ -6,3 +6,3 @@ /*! | ||
* @license MIT | ||
* @version 1.0.0 | ||
* @version 1.0.1 | ||
*/ | ||
@@ -16,4 +16,14 @@ | ||
var babelHelpers = {}; | ||
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
var cos = Math.cos; | ||
var sin = Math.sin; | ||
var pow = Math.pow; | ||
var abs = Math.abs; | ||
var sqrt = Math.sqrt; | ||
var asin = Math.asin; | ||
var PI = Math.PI; | ||
var max = Math.max; | ||
var min = Math.min; | ||
var round = Math.round; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
@@ -24,3 +34,3 @@ } : function (obj) { | ||
babelHelpers.classCallCheck = function (instance, Constructor) { | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
@@ -31,3 +41,3 @@ throw new TypeError("Cannot call a class as a function"); | ||
babelHelpers.createClass = function () { | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
@@ -50,15 +60,2 @@ for (var i = 0; i < props.length; i++) { | ||
babelHelpers; | ||
var cos = Math.cos; | ||
var sin = Math.sin; | ||
var pow = Math.pow; | ||
var abs = Math.abs; | ||
var sqrt = Math.sqrt; | ||
var asin = Math.asin; | ||
var PI = Math.PI; | ||
var max = Math.max; | ||
var min = Math.min; | ||
var round = Math.round; | ||
var MAX_ARRAY_INDEX = pow(2, 53) - 1; | ||
@@ -77,3 +74,3 @@ var classTypeList = ["Boolean", "Number", "String", "Function", "Array", "Object"]; | ||
return (typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj)) === "object" || typeof obj === "function" ? classTypes[Object.prototype.toString.call(obj)] || "object" : typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj); | ||
return (typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object" || typeof obj === "function" ? classTypes[Object.prototype.toString.call(obj)] || "object" : typeof obj === "undefined" ? "undefined" : _typeof(obj); | ||
} | ||
@@ -623,3 +620,3 @@ | ||
function ScrollTween(el) { | ||
babelHelpers.classCallCheck(this, ScrollTween); | ||
classCallCheck(this, ScrollTween); | ||
@@ -635,3 +632,3 @@ this.el = el; | ||
babelHelpers.createClass(ScrollTween, [{ | ||
createClass(ScrollTween, [{ | ||
key: "run", | ||
@@ -751,3 +748,3 @@ value: function run(x, y, options) { | ||
/* eslint-disable max-len */ | ||
/* eslint-enable max-len */ | ||
@@ -766,3 +763,3 @@ /** | ||
var container = arguments.length <= 1 || arguments[1] === undefined ? "body, html" : arguments[1]; | ||
babelHelpers.classCallCheck(this, SweetScroll); | ||
classCallCheck(this, SweetScroll); | ||
@@ -795,3 +792,3 @@ var params = merge({}, SweetScroll.defaults, options); | ||
babelHelpers.createClass(SweetScroll, [{ | ||
createClass(SweetScroll, [{ | ||
key: "to", | ||
@@ -1040,3 +1037,3 @@ value: function to(distance) { | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-enable no-unused-vars */ | ||
@@ -1058,2 +1055,3 @@ /** | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
@@ -1064,2 +1062,4 @@ }, { | ||
/* eslint-enable no-unused-vars */ | ||
/** | ||
@@ -1070,2 +1070,3 @@ * Called at complete of the scroll. | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
@@ -1076,2 +1077,4 @@ }, { | ||
/* eslint-enable no-unused-vars */ | ||
/** | ||
@@ -1083,2 +1086,3 @@ * Called at each animation frame of the scroll. | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
@@ -1089,2 +1093,4 @@ }, { | ||
/* eslint-enable no-unused-vars */ | ||
/** | ||
@@ -1091,0 +1097,0 @@ * Parse the value of coordinate |
@@ -6,4 +6,4 @@ /*! | ||
* @license MIT | ||
* @version 1.0.0 | ||
* @version 1.0.1 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?"":"object"===("undefined"==typeof t?"undefined":lt["typeof"](t))||"function"==typeof t?mt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":lt["typeof"](t)}function n(n){return"number"===t(n)}function e(n){return"string"===t(n)}function i(n){return"function"===t(n)}function o(t){return Array.isArray(t)}function r(t){var e=null==t?null:t.length;return n(e)&&e>=0&&yt>=e}function l(t){return!o(t)&&t-parseFloat(t)+1>=0}function u(n){return!o(n)&&"object"===t(n)}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t,n,e){if(null==t)return t;var i=e||t;if(u(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!1)break}else if(r(t))for(var l=0;l<t.length&&n.call(i,t[l],l)!==!1;l++);return t}function s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;n>i;i++)e[i-1]=arguments[i];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function f(t){return t.replace(/\s*/g,"")||""}function h(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?kt:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?kt:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){return t===kt.documentElement||t===kt.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],i=bt[n],o=t instanceof Element?[t]:p(t),r=[],l=kt.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1,a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:null}function S(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function m(t){return dt(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return dt(t.scrollWidth,t.clientWidth,t.offsetWidth)}function k(t){return{width:C(t),height:m(t)}}function b(){return{width:dt(C(kt.body),C(kt.documentElement)),height:dt(m(kt.body),m(kt.documentElement))}}function w(t){return v(t)?{viewport:{width:vt(Ct.innerWidth,kt.documentElement.clientWidth),height:Ct.innerHeight},size:b()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:k(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=S(t);return e?e[wt[n]]:t[bt[n]]}function _(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=S(t),o="y"===e;i?i.scrollTo(o?i[wt.x]:n,o?n:i[wt.y]):t[bt[e]]=n}function I(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=null;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=Ct.pageYOffset,i.left=Ct.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=-1*r.top+o.scrollTop,i.left=-1*r.left+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function x(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function A(t,n,e,i,o){return i*(n/=o)*n+e}function T(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function z(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function M(t,n,e,i,o){return i*(n/=o)*n*n+e}function D(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function Q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,i,o){return-i*ut(n/o*(pt/2))+i+e}function F(t,n,e,i,o){return i*at(n/o*(pt/2))+e}function U(t,n,e,i,o){return-i/2*(ut(pt*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*ct(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-ct(2,-10*n/o)+1)+e}function X(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*ct(2,10*(n-1))+e:i/2*(-ct(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(ft(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*ft(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(ft(1-n*n)-1)+e:i/2*(ft(1-(n-=2)*n)+1)+e}function G(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),-(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e)}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),u*ct(2,-10*n)*at((n*o-r)*(2*pt)/l)+i+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),1>n?-.5*(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e:u*ct(2,-10*(n-=1))*at((n*o-r)*(2*pt)/l)*.5+i+e)}function tt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function it(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:2/2.75>n?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function ot(t,n,e,i,o){return i-it(t,o-n,0,i,o)+e}function rt(t,n,e,i,o){return o/2>n?.5*ot(t,2*n,0,i,o)+e:.5*it(t,2*n-o,0,i,o)+.5*i+e}var lt={};lt["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},lt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt.createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}();var ut=Math.cos,at=Math.sin,ct=Math.pow,st=Math.abs,ft=Math.sqrt,ht=Math.asin,pt=Math.PI,dt=Math.max,vt=Math.min,gt=Math.round,yt=ct(2,53)-1,St=["Boolean","Number","String","Function","Array","Object"],mt={};St.forEach(function(t){mt["[object "+t+"]"]=t.toLowerCase()});for(var Ct=window,kt=document,bt={y:"scrollTop",x:"scrollLeft"},wt={y:"pageYOffset",x:"pageXOffset"},Ot=(function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}()),_t=Object.freeze({linear:E,InQuad:A,OutQuad:T,InOutQuad:z,InCubic:M,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,OutBounce:it,InBounce:ot,InOutBounce:rt}),It=["ms","moz","webkit"],xt=0,Lt=Ct.requestAnimationFrame,Et=Ct.cancelAnimationFrame,At=0;At<It.length&&!Lt;++At)Lt=Ct[It[At]+"RequestAnimationFrame"],Et=Ct[It[At]+"CancelAnimationFrame"]||Ct[It[At]+"CancelRequestAnimationFrame"];Lt||(Lt=function(t){var n=Date.now(),e=dt(0,16-(n-xt)),i=setTimeout(function(){t(n+e)},e);return xt=n+e,i}),Et||(Et=function(t){clearTimeout(t)});var Tt=function(){function t(n){lt.classCallCheck(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.easing=null,this.startTime=null,this.rafId=null}return lt.createClass(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.easing=i(e.easing)?e.easing:_t[e.easing.replace("ease","")],this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},o.rafId=Lt(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,Et(this.rafId),t&&(_(this.el,this.props.x,"x"),_(this.el,this.props.y,"y")),i(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.options,r=this.startTime,l=this.startProps,u=this.easing,a=o.duration,s=o.step,f={},h=t-r,p=vt(1,dt(h/a,0));c(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var o=u(p,a*p,0,1,a);f[n]=gt(e+i*o)}),c(f,function(t,n){_(e,t,n)}),a>=h?(s.call(this,p,f),this.rafId=Lt(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),zt=function(){return"onwheel"in kt?"wheel":"onmousewheel"in kt?"mousewheel":"DOMMouseScroll"}(),Mt=zt+", touchstart, touchmove",Dt="DOMContentLoaded",Qt=!1;x(kt,Dt,function(){Qt=!0});var jt=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];lt.classCallCheck(this,t);var o=s({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new Tt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return lt.createClass(t,[{key:"to",value:function(t){var n=this,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,r=this.header,l=s({},this.options,i);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!c&&e(t))if(f=/^#/.test(t)?t:null,"#"===t)c={top:0,left:0};else{var p=h(t),d=I(p,o);if(!d)return;c=d}if(c){u&&(c.top+=u.top,c.left+=u.left),r&&(c.top=dt(0,c.top-k(r).height));var v=w(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",c,a)!==!1&&(c.top=l.verticalScroll?dt(0,vt(y.height-g.height,c.top)):O(o,"y"),c.left=l.horizontalScroll?dt(0,vt(y.width-g.width,c.left)):O(o,"x"),this.tween.run(c.left,c.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=f&&f!==window.location.hash&&n.updateURLHash(f,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",c,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=I(t,this.container);this.to(e,s({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=s({},this.options,t),this.header=h(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var n=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=s(i,t);else if(o(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=n?t[0]:0,i.left=n?0:t[0]);else if(l(t))i.top=n?t:0,i.left=n?0:t;else{if(!e(t))return null;var r=f(t);if(/^\d+,\d+$/.test(r))r=r.split(","),i.top=r[0],i.left=r[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(r)){var u=r.match(/top:(\d+)/),c=r.match(/left:(\d+)/);i.top=u?u[1]:0,i.left=c?c[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(r))return null;var h=O(this.container,n?"y":"x"),p=r.match(/^(\+|-)=(\d+)$/),d=p[1],v=parseInt(p[2],10);"+"===d?(i.top=n?h+v:0,i.left=n?0:h+v):(i.top=n?h-v:0,i.left=n?0:h-v)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t,n){Ot&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=null;o&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Qt?n.call(this,l):!function(){var i=!1;x(kt,Dt,function(){i=!0,e.getContainer(t,n)}),x(Ct,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),x(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),x(t,Mt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Mt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,r=Array(o>2?o-2:0),l=2;o>l;l++)r[l-2]=arguments[l];if(i(e)){var u=e.apply(this,r);if("undefined"==typeof u)return u}return this[n].apply(this,r)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==kt;e=e.parentNode)if(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=s({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return jt.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},jt}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?"":"object"===("undefined"==typeof t?"undefined":gt(t))||"function"==typeof t?kt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":gt(t)}function n(n){return"number"===t(n)}function e(n){return"string"===t(n)}function i(n){return"function"===t(n)}function o(t){return Array.isArray(t)}function r(t){var e=null==t?null:t.length;return n(e)&&e>=0&&mt>=e}function l(t){return!o(t)&&t-parseFloat(t)+1>=0}function u(n){return!o(n)&&"object"===t(n)}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t,n,e){if(null==t)return t;var i=e||t;if(u(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!1)break}else if(r(t))for(var l=0;l<t.length&&n.call(i,t[l],l)!==!1;l++);return t}function s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;n>i;i++)e[i-1]=arguments[i];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function f(t){return t.replace(/\s*/g,"")||""}function h(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?wt:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?wt:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){return t===wt.documentElement||t===wt.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],i=Ot[n],o=t instanceof Element?[t]:p(t),r=[],l=wt.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1,a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:null}function S(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function m(t){return pt(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return pt(t.scrollWidth,t.clientWidth,t.offsetWidth)}function k(t){return{width:C(t),height:m(t)}}function b(){return{width:pt(C(wt.body),C(wt.documentElement)),height:pt(m(wt.body),m(wt.documentElement))}}function w(t){return v(t)?{viewport:{width:dt(bt.innerWidth,wt.documentElement.clientWidth),height:bt.innerHeight},size:b()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:k(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=S(t);return e?e[_t[n]]:t[Ot[n]]}function _(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=S(t),o="y"===e;i?i.scrollTo(o?i[_t.x]:n,o?n:i[_t.y]):t[Ot[e]]=n}function I(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=null;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=bt.pageYOffset,i.left=bt.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=-1*r.top+o.scrollTop,i.left=-1*r.left+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function x(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function A(t,n,e,i,o){return i*(n/=o)*n+e}function T(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function z(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function M(t,n,e,i,o){return i*(n/=o)*n*n+e}function D(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function Q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,i,o){return-i*lt(n/o*(ht/2))+i+e}function F(t,n,e,i,o){return i*ut(n/o*(ht/2))+e}function U(t,n,e,i,o){return-i/2*(lt(ht*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*at(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-at(2,-10*n/o)+1)+e}function X(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*at(2,10*(n-1))+e:i/2*(-at(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(st(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*st(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(st(1-n*n)-1)+e:i/2*(st(1-(n-=2)*n)+1)+e}function G(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),-(u*at(2,10*(n-=1))*ut((n*o-r)*(2*ht)/l))+e)}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),u*at(2,-10*n)*ut((n*o-r)*(2*ht)/l)+i+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),1>n?-.5*(u*at(2,10*(n-=1))*ut((n*o-r)*(2*ht)/l))+e:u*at(2,-10*(n-=1))*ut((n*o-r)*(2*ht)/l)*.5+i+e)}function tt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function it(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:2/2.75>n?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function ot(t,n,e,i,o){return i-it(t,o-n,0,i,o)+e}function rt(t,n,e,i,o){return o/2>n?.5*ot(t,2*n,0,i,o)+e:.5*it(t,2*n-o,0,i,o)+.5*i+e}var lt=Math.cos,ut=Math.sin,at=Math.pow,ct=Math.abs,st=Math.sqrt,ft=Math.asin,ht=Math.PI,pt=Math.max,dt=Math.min,vt=Math.round,gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},yt=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},St=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),mt=at(2,53)-1,Ct=["Boolean","Number","String","Function","Array","Object"],kt={};Ct.forEach(function(t){kt["[object "+t+"]"]=t.toLowerCase()});for(var bt=window,wt=document,Ot={y:"scrollTop",x:"scrollLeft"},_t={y:"pageYOffset",x:"pageXOffset"},It=(function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}()),xt=Object.freeze({linear:E,InQuad:A,OutQuad:T,InOutQuad:z,InCubic:M,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,OutBounce:it,InBounce:ot,InOutBounce:rt}),Lt=["ms","moz","webkit"],Et=0,At=bt.requestAnimationFrame,Tt=bt.cancelAnimationFrame,zt=0;zt<Lt.length&&!At;++zt)At=bt[Lt[zt]+"RequestAnimationFrame"],Tt=bt[Lt[zt]+"CancelAnimationFrame"]||bt[Lt[zt]+"CancelRequestAnimationFrame"];At||(At=function(t){var n=Date.now(),e=pt(0,16-(n-Et)),i=setTimeout(function(){t(n+e)},e);return Et=n+e,i}),Tt||(Tt=function(t){clearTimeout(t)});var Mt=function(){function t(n){yt(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.easing=null,this.startTime=null,this.rafId=null}return St(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.easing=i(e.easing)?e.easing:xt[e.easing.replace("ease","")],this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},o.rafId=At(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,Tt(this.rafId),t&&(_(this.el,this.props.x,"x"),_(this.el,this.props.y,"y")),i(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.options,r=this.startTime,l=this.startProps,u=this.easing,a=o.duration,s=o.step,f={},h=t-r,p=dt(1,pt(h/a,0));c(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var o=u(p,a*p,0,1,a);f[n]=vt(e+i*o)}),c(f,function(t,n){_(e,t,n)}),a>=h?(s.call(this,p,f),this.rafId=At(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),Dt=function(){return"onwheel"in wt?"wheel":"onmousewheel"in wt?"mousewheel":"DOMMouseScroll"}(),Qt=Dt+", touchstart, touchmove",jt="DOMContentLoaded",Bt=!1;x(wt,jt,function(){Bt=!0});var Pt=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];yt(this,t);var o=s({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new Mt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return St(t,[{key:"to",value:function(t){var n=this,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,r=this.header,l=s({},this.options,i);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!c&&e(t))if(f=/^#/.test(t)?t:null,"#"===t)c={top:0,left:0};else{var p=h(t),d=I(p,o);if(!d)return;c=d}if(c){u&&(c.top+=u.top,c.left+=u.left),r&&(c.top=pt(0,c.top-k(r).height));var v=w(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",c,a)!==!1&&(c.top=l.verticalScroll?pt(0,dt(y.height-g.height,c.top)):O(o,"y"),c.left=l.horizontalScroll?pt(0,dt(y.width-g.width,c.left)):O(o,"x"),this.tween.run(c.left,c.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=f&&f!==window.location.hash&&n.updateURLHash(f,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",c,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=I(t,this.container);this.to(e,s({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=s({},this.options,t),this.header=h(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var n=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=s(i,t);else if(o(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=n?t[0]:0,i.left=n?0:t[0]);else if(l(t))i.top=n?t:0,i.left=n?0:t;else{if(!e(t))return null;var r=f(t);if(/^\d+,\d+$/.test(r))r=r.split(","),i.top=r[0],i.left=r[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(r)){var u=r.match(/top:(\d+)/),c=r.match(/left:(\d+)/);i.top=u?u[1]:0,i.left=c?c[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(r))return null;var h=O(this.container,n?"y":"x"),p=r.match(/^(\+|-)=(\d+)$/),d=p[1],v=parseInt(p[2],10);"+"===d?(i.top=n?h+v:0,i.left=n?0:h+v):(i.top=n?h-v:0,i.left=n?0:h-v)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t,n){It&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=null;o&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Bt?n.call(this,l):!function(){var i=!1;x(wt,jt,function(){i=!0,e.getContainer(t,n)}),x(bt,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),x(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),x(t,Qt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Qt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,r=Array(o>2?o-2:0),l=2;o>l;l++)r[l-2]=arguments[l];if(i(e)){var u=e.apply(this,r);if("undefined"==typeof u)return u}return this[n].apply(this,r)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==wt;e=e.parentNode)if(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=s({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return Pt.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},Pt}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1154
69943