@mattlewis92/dom-autoscroller
Advanced tools
Comparing version 2.3.7 to 2.4.0
@@ -60,3 +60,13 @@ import { boolean } from 'type-func'; | ||
this.margin = options.margin || -1; | ||
if (typeof this.margin !== 'object') { | ||
var margin = options.margin || -1; | ||
this.margin = { | ||
left: margin, | ||
right: margin, | ||
top: margin, | ||
bottom: margin | ||
}; | ||
} | ||
//this.scrolling = false; | ||
@@ -77,2 +87,11 @@ this.scrollWhenOutside = options.scrollWhenOutside || false; | ||
if (typeof maxSpeed !== 'object') { | ||
maxSpeed = { | ||
left: maxSpeed, | ||
right: maxSpeed, | ||
top: maxSpeed, | ||
bottom: maxSpeed | ||
}; | ||
} | ||
this.autoScroll = boolean(options.autoScroll); | ||
@@ -303,9 +322,9 @@ this.syncMove = boolean(options.syncMove, false); | ||
if(point.x < rect.left + self.margin){ | ||
if(point.x < rect.left + self.margin.left){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.x - rect.left) / self.margin.left - 1) * self.maxSpeed.left | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
}else if(point.x > rect.right - self.margin.right){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.x - rect.right) / self.margin.right + 1) * self.maxSpeed.right | ||
); | ||
@@ -316,9 +335,9 @@ }else{ | ||
if(point.y < rect.top + self.margin){ | ||
if(point.y < rect.top + self.margin.top){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.y - rect.top) / self.margin.top - 1) * self.maxSpeed.top | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
}else if(point.y > rect.bottom - self.margin.bottom){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.y - rect.bottom) / self.margin.bottom + 1) * self.maxSpeed.bottom | ||
); | ||
@@ -325,0 +344,0 @@ }else{ |
@@ -64,3 +64,13 @@ 'use strict'; | ||
this.margin = options.margin || -1; | ||
if (typeof this.margin !== 'object') { | ||
var margin = options.margin || -1; | ||
this.margin = { | ||
left: margin, | ||
right: margin, | ||
top: margin, | ||
bottom: margin | ||
}; | ||
} | ||
//this.scrolling = false; | ||
@@ -81,2 +91,11 @@ this.scrollWhenOutside = options.scrollWhenOutside || false; | ||
if (typeof maxSpeed !== 'object') { | ||
maxSpeed = { | ||
left: maxSpeed, | ||
right: maxSpeed, | ||
top: maxSpeed, | ||
bottom: maxSpeed | ||
}; | ||
} | ||
this.autoScroll = typeFunc.boolean(options.autoScroll); | ||
@@ -307,9 +326,9 @@ this.syncMove = typeFunc.boolean(options.syncMove, false); | ||
if(point.x < rect.left + self.margin){ | ||
if(point.x < rect.left + self.margin.left){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.x - rect.left) / self.margin.left - 1) * self.maxSpeed.left | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
}else if(point.x > rect.right - self.margin.right){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.x - rect.right) / self.margin.right + 1) * self.maxSpeed.right | ||
); | ||
@@ -320,9 +339,9 @@ }else{ | ||
if(point.y < rect.top + self.margin){ | ||
if(point.y < rect.top + self.margin.top){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.y - rect.top) / self.margin.top - 1) * self.maxSpeed.top | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
}else if(point.y > rect.bottom - self.margin.bottom){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.y - rect.bottom) / self.margin.bottom + 1) * self.maxSpeed.bottom | ||
); | ||
@@ -329,0 +348,0 @@ }else{ |
@@ -708,3 +708,13 @@ var autoScroll = (function () { | ||
this.margin = options.margin || -1; | ||
if (typeof this.margin !== 'object') { | ||
var margin = options.margin || -1; | ||
this.margin = { | ||
left: margin, | ||
right: margin, | ||
top: margin, | ||
bottom: margin | ||
}; | ||
} | ||
//this.scrolling = false; | ||
@@ -725,2 +735,11 @@ this.scrollWhenOutside = options.scrollWhenOutside || false; | ||
if (typeof maxSpeed !== 'object') { | ||
maxSpeed = { | ||
left: maxSpeed, | ||
right: maxSpeed, | ||
top: maxSpeed, | ||
bottom: maxSpeed | ||
}; | ||
} | ||
this.autoScroll = boolean(options.autoScroll); | ||
@@ -951,9 +970,9 @@ this.syncMove = boolean(options.syncMove, false); | ||
if(point.x < rect.left + self.margin){ | ||
if(point.x < rect.left + self.margin.left){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.x - rect.left) / self.margin.left - 1) * self.maxSpeed.left | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
}else if(point.x > rect.right - self.margin.right){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.x - rect.right) / self.margin.right + 1) * self.maxSpeed.right | ||
); | ||
@@ -964,9 +983,9 @@ }else{ | ||
if(point.y < rect.top + self.margin){ | ||
if(point.y < rect.top + self.margin.top){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
Math.max(-1, (point.y - rect.top) / self.margin.top - 1) * self.maxSpeed.top | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
}else if(point.y > rect.bottom - self.margin.bottom){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
Math.min(1, (point.y - rect.bottom) / self.margin.bottom + 1) * self.maxSpeed.bottom | ||
); | ||
@@ -973,0 +992,0 @@ }else{ |
@@ -1,1 +0,1 @@ | ||
var autoScroll=function(){"use strict";function e(e,n){return void 0===e?void 0===n?e:n:e}function n(n,t){return n=e(n,t),"function"==typeof n?function(){for(var e=arguments,t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=e[o];return!!n.apply(this,r)}:n?function(){return!0}:function(){return!1}}function t(e,n){if(n=u(n,!0),!b(n))return-1;for(var t=0;t<e.length;t++)if(e[t]===n)return t;return-1}function r(e,n){return-1!==t(e,n)}function o(e,n){for(var t=0;t<n.length;t++)r(e,n[t])||e.push(n[t]);return n}function i(e){for(var n=arguments,t=[],r=arguments.length-1;r-- >0;)t[r]=n[r+1];return t=t.map(u),o(e,t)}function a(e){for(var n=arguments,r=[],o=arguments.length-1;o-- >0;)r[o]=n[o+1];return r.map(u).reduce(function(n,r){var o=t(e,r);return-1!==o?n.concat(e.splice(o,1)):n},[])}function u(e,n){if("string"==typeof e)try{return document.querySelector(e)}catch(e){throw e}if(!b(e)&&!n)throw new TypeError(e+" is not a DOM element.");return e}function c(e,t){t=t||{};var r=n(t.allowUpdate,!0);return function(n){if(n=n||window.event,e.target=n.target||n.srcElement||n.originalTarget,e.element=this,e.type=n.type,r(n)){if(n.targetTouches)e.x=n.targetTouches[0].clientX,e.y=n.targetTouches[0].clientY,e.pageX=n.targetTouches[0].pageX,e.pageY=n.targetTouches[0].pageY,e.screenX=n.targetTouches[0].screenX,e.screenY=n.targetTouches[0].screenY;else{if(null===n.pageX&&null!==n.clientX){var t=n.target&&n.target.ownerDocument||document,o=t.documentElement,i=t.body;e.pageX=n.clientX+(o&&o.scrollLeft||i&&i.scrollLeft||0)-(o&&o.clientLeft||i&&i.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||i&&i.scrollTop||0)-(o&&o.clientTop||i&&i.clientTop||0)}else e.pageX=n.pageX,e.pageY=n.pageY;e.x=n.clientX,e.y=n.clientY,e.screenX=n.screenX,e.screenY=n.screenY}e.clientX=e.x,e.clientY=e.y}}}function l(){var e={top:{value:0,enumerable:!0},left:{value:0,enumerable:!0},right:{value:window.innerWidth,enumerable:!0},bottom:{value:window.innerHeight,enumerable:!0},width:{value:window.innerWidth,enumerable:!0},height:{value:window.innerHeight,enumerable:!0},x:{value:0,enumerable:!0},y:{value:0,enumerable:!0}};if(Object.create)return Object.create({},e);var n={};return Object.defineProperties(n,e),n}function f(e){if(e===window)return l();try{var n=e.getBoundingClientRect();return void 0===n.x&&(n.x=n.left,n.y=n.top),n}catch(n){throw new TypeError("Can't call getBoundingClientRect on "+e)}}function d(e,n){var t=f(n);return e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right}function s(e){function n(e){for(var n=0;n<x.length;n++)r[x[n]]=e[x[n]]}function t(){e&&e.removeEventListener("mousemove",n,!1),r=null}var r={screenX:0,screenY:0,clientX:0,clientY:0,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1,button:0,buttons:1,relatedTarget:null,region:null};return void 0!==e&&e.addEventListener("mousemove",n),{destroy:t,dispatch:function(){return MouseEvent?function(e,n,t){var o=new MouseEvent("mousemove",m(r,n));return v(o,t),e.dispatchEvent(o)}:"function"==typeof document.createEvent?function(e,n,t){var o=m(r,n),i=document.createEvent("MouseEvents");return i.initMouseEvent("mousemove",!0,!0,window,0,o.screenX,o.screenY,o.clientX,o.clientY,o.ctrlKey,o.altKey,o.shiftKey,o.metaKey,o.button,o.relatedTarget),v(i,t),e.dispatchEvent(i)}:"function"==typeof document.createEventObject?function(e,n,t){var o=document.createEventObject(),i=m(r,n);for(var a in i)o[a]=i[a];return v(o,t),e.dispatchEvent(o)}:void 0}()}}function m(e,n){n=n||{};for(var t=T(e),r=0;r<x.length;r++)void 0!==n[x[r]]&&(t[x[r]]=n[x[r]]);return t}function v(e,n){console.log("data ",n),e.data=n||{},e.dispatched="mousemove"}function w(e,t){function o(n){for(var t=0;t<e.length;t++)if(e[t]===n.target){A=!0;break}A&&X(function(){return A=!1})}function u(){M=!0}function l(){M=!1,d()}function d(){Y(q),Y(F)}function m(){M=!1}function v(n){if(!n)return null;if(N===n)return n;if(r(e,n))return n;for(;n=n.parentNode;)if(r(e,n))return n;return null}function w(){for(var n=null,t=0;t<e.length;t++)h(O,e[t])&&(n=e[t]);return n}function p(e){if(x.autoScroll()&&!e.dispatched){var n=e.target,t=document.body;N&&!h(O,N)&&(x.scrollWhenOutside||(N=null)),n&&n.parentNode===t?n=w():(n=v(n))||(n=w()),n&&n!==N&&(N=n),K&&(Y(F),F=X(y)),N&&(Y(q),q=X(g))}}function y(){b(K),Y(F),F=X(y)}function g(){N&&(b(N),Y(q),q=X(g))}function b(e){var n,t,r=f(e);n=O.x<r.left+x.margin?Math.floor(Math.max(-1,(O.x-r.left)/x.margin-1)*x.maxSpeed):O.x>r.right-x.margin?Math.ceil(Math.min(1,(O.x-r.right)/x.margin+1)*x.maxSpeed):0,t=O.y<r.top+x.margin?Math.floor(Math.max(-1,(O.y-r.top)/x.margin-1)*x.maxSpeed):O.y>r.bottom-x.margin?Math.ceil(Math.min(1,(O.y-r.bottom)/x.margin+1)*x.maxSpeed):0,x.syncMove()&&j.dispatch(e,{pageX:O.pageX+n,pageY:O.pageY+t,clientX:O.x+n,clientY:O.y+t}),setTimeout(function(){t&&E(e,t),n&&T(e,n)})}function E(e,n){e===window?window.scrollTo(e.pageXOffset,e.pageYOffset+n):e.scrollTop+=n}function T(e,n){e===window?window.scrollTo(e.pageXOffset+n,e.pageYOffset):e.scrollLeft+=n}void 0===t&&(t={});var x=this,L=4,A=!1;this.margin=t.margin||-1,this.scrollWhenOutside=t.scrollWhenOutside||!1;var O={},S=c(O),j=s(),M=!1;window.addEventListener("mousemove",S,!1),window.addEventListener("touchmove",S,!1),isNaN(t.maxSpeed)||(L=t.maxSpeed),this.autoScroll=n(t.autoScroll),this.syncMove=n(t.syncMove,!1),this.destroy=function(n){window.removeEventListener("mousemove",S,!1),window.removeEventListener("touchmove",S,!1),window.removeEventListener("mousedown",u,!1),window.removeEventListener("touchstart",u,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("touchend",l,!1),window.removeEventListener("pointerup",l,!1),window.removeEventListener("mouseleave",m,!1),window.removeEventListener("mousemove",p,!1),window.removeEventListener("touchmove",p,!1),window.removeEventListener("scroll",o,!0),e=[],n&&d()},this.add=function(){for(var n=[],t=arguments.length;t--;)n[t]=arguments[t];return i.apply(void 0,[e].concat(n)),this},this.remove=function(){for(var n=[],t=arguments.length;t--;)n[t]=arguments[t];return a.apply(void 0,[e].concat(n))};var F,K=null;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(n){e=[],n.forEach(function(e){e===window?K=window:x.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return M}},maxSpeed:{get:function(){return L}},point:{get:function(){return O}},scrolling:{get:function(){return A}}});var q,N=null;window.addEventListener("mousedown",u,!1),window.addEventListener("touchstart",u,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("touchend",l,!1),window.addEventListener("pointerup",l,!1),window.addEventListener("mousemove",p,!1),window.addEventListener("touchmove",p,!1),window.addEventListener("mouseleave",m,!1),window.addEventListener("scroll",o,!0)}function p(e,n){return new w(e,n)}function h(e,n,t){return t?e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right:d(e,n)}var y=function(){var e=function(e){return"function"==typeof e},n=function(e){var n=Number(e);return isNaN(n)?0:0!==n&&isFinite(n)?(n>0?1:-1)*Math.floor(Math.abs(n)):n},t=Math.pow(2,53)-1,r=function(e){var r=n(e);return Math.min(Math.max(r,0),t)},o=function(e){if(null!=e){if(["string","number","boolean","symbol"].indexOf(typeof e)>-1)return Symbol.iterator;if("undefined"!=typeof Symbol&&"iterator"in Symbol&&Symbol.iterator in e)return Symbol.iterator;if("@@iterator"in e)return"@@iterator"}},i=function(n,t){if(null!=n&&null!=t){var r=n[t];if(null==r)return;if(!e(r))throw new TypeError(r+" is not a function");return r}},a=function(e){var n=e.next();return!Boolean(n.done)&&n};return function(n){var t,u=this,c=arguments.length>1?arguments[1]:void 0;if(void 0!==c){if(!e(c))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(t=arguments[2])}var l,f,d=i(n,o(n));if(void 0!==d){l=e(u)?Object(new u):[];var s=d.call(n);if(null==s)throw new TypeError("Array.from requires an array-like or iterable object");f=0;for(var m,v;;){if(!(m=a(s)))return l.length=f,l;v=m.value,l[f]=c?c.call(t,v,f):v,f++}}else{var w=Object(n);if(null==n)throw new TypeError("Array.from requires an array-like object - not null or undefined");var p=r(w.length);l=e(u)?Object(new u(p)):new Array(p),f=0;for(var h;f<p;)h=w[f],l[f]=c?c.call(t,h,f):h,f++;l.length=p}return l}}(),g=("function"==typeof Array.from&&Array.from,Array.isArray,Object.prototype.toString,"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}),b=function(e){return null!=e&&"object"===(void 0===e?"undefined":g(e))&&1===e.nodeType&&"object"===g(e.style)&&"object"===g(e.ownerDocument)},E=void 0;E="function"!=typeof Object.create?function(e){var n=function(){};return function(e,t){if(e!==Object(e)&&null!==e)throw TypeError("Argument must be an object, or null");n.prototype=e||{};var r=new n;return n.prototype=null,void 0!==t&&Object.defineProperties(r,t),null===e&&(r.__proto__=null),r}}():Object.create;var T=E,x=["altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","offsetX","offsetY","pageX","pageY","region","relatedTarget","screenX","screenY","shiftKey","which","x","y"],L=["webkit","moz","ms","o"],X=function(){if("undefined"==typeof window)return function(){};for(var e=0,n=L.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[L[e]+"RequestAnimationFrame"];if(!window.requestAnimationFrame){var t=0;window.requestAnimationFrame=function(e){var n=(new Date).getTime(),r=Math.max(0,16-n-t),o=window.setTimeout(function(){return e(n+r)},r);return t=n+r,o}}return window.requestAnimationFrame.bind(window)}(),Y=function(){if("undefined"==typeof window)return function(){};for(var e=0,n=L.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[L[e]+"CancelAnimationFrame"]||window[L[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}();return p}(); | ||
var autoScroll=function(){"use strict";function e(e,t){return void 0===e?void 0===t?e:t:e}function t(t,n){return t=e(t,n),"function"==typeof t?function(){for(var e=arguments,n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=e[o];return!!t.apply(this,r)}:t?function(){return!0}:function(){return!1}}function n(e,t){if(t=u(t,!0),!b(t))return-1;for(var n=0;n<e.length;n++)if(e[n]===t)return n;return-1}function r(e,t){return-1!==n(e,t)}function o(e,t){for(var n=0;n<t.length;n++)r(e,t[n])||e.push(t[n]);return t}function i(e){for(var t=arguments,n=[],r=arguments.length-1;r-- >0;)n[r]=t[r+1];return n=n.map(u),o(e,n)}function a(e){for(var t=arguments,r=[],o=arguments.length-1;o-- >0;)r[o]=t[o+1];return r.map(u).reduce(function(t,r){var o=n(e,r);return-1!==o?t.concat(e.splice(o,1)):t},[])}function u(e,t){if("string"==typeof e)try{return document.querySelector(e)}catch(e){throw e}if(!b(e)&&!t)throw new TypeError(e+" is not a DOM element.");return e}function c(e,n){n=n||{};var r=t(n.allowUpdate,!0);return function(t){if(t=t||window.event,e.target=t.target||t.srcElement||t.originalTarget,e.element=this,e.type=t.type,r(t)){if(t.targetTouches)e.x=t.targetTouches[0].clientX,e.y=t.targetTouches[0].clientY,e.pageX=t.targetTouches[0].pageX,e.pageY=t.targetTouches[0].pageY,e.screenX=t.targetTouches[0].screenX,e.screenY=t.targetTouches[0].screenY;else{if(null===t.pageX&&null!==t.clientX){var n=t.target&&t.target.ownerDocument||document,o=n.documentElement,i=n.body;e.pageX=t.clientX+(o&&o.scrollLeft||i&&i.scrollLeft||0)-(o&&o.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(o&&o.scrollTop||i&&i.scrollTop||0)-(o&&o.clientTop||i&&i.clientTop||0)}else e.pageX=t.pageX,e.pageY=t.pageY;e.x=t.clientX,e.y=t.clientY,e.screenX=t.screenX,e.screenY=t.screenY}e.clientX=e.x,e.clientY=e.y}}}function l(){var e={top:{value:0,enumerable:!0},left:{value:0,enumerable:!0},right:{value:window.innerWidth,enumerable:!0},bottom:{value:window.innerHeight,enumerable:!0},width:{value:window.innerWidth,enumerable:!0},height:{value:window.innerHeight,enumerable:!0},x:{value:0,enumerable:!0},y:{value:0,enumerable:!0}};if(Object.create)return Object.create({},e);var t={};return Object.defineProperties(t,e),t}function f(e){if(e===window)return l();try{var t=e.getBoundingClientRect();return void 0===t.x&&(t.x=t.left,t.y=t.top),t}catch(t){throw new TypeError("Can't call getBoundingClientRect on "+e)}}function d(e,t){var n=f(t);return e.y>n.top&&e.y<n.bottom&&e.x>n.left&&e.x<n.right}function m(e){function t(e){for(var t=0;t<x.length;t++)r[x[t]]=e[x[t]]}function n(){e&&e.removeEventListener("mousemove",t,!1),r=null}var r={screenX:0,screenY:0,clientX:0,clientY:0,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1,button:0,buttons:1,relatedTarget:null,region:null};return void 0!==e&&e.addEventListener("mousemove",t),{destroy:n,dispatch:function(){return MouseEvent?function(e,t,n){var o=new MouseEvent("mousemove",s(r,t));return v(o,n),e.dispatchEvent(o)}:"function"==typeof document.createEvent?function(e,t,n){var o=s(r,t),i=document.createEvent("MouseEvents");return i.initMouseEvent("mousemove",!0,!0,window,0,o.screenX,o.screenY,o.clientX,o.clientY,o.ctrlKey,o.altKey,o.shiftKey,o.metaKey,o.button,o.relatedTarget),v(i,n),e.dispatchEvent(i)}:"function"==typeof document.createEventObject?function(e,t,n){var o=document.createEventObject(),i=s(r,t);for(var a in i)o[a]=i[a];return v(o,n),e.dispatchEvent(o)}:void 0}()}}function s(e,t){t=t||{};for(var n=T(e),r=0;r<x.length;r++)void 0!==t[x[r]]&&(n[x[r]]=t[x[r]]);return n}function v(e,t){console.log("data ",t),e.data=t||{},e.dispatched="mousemove"}function w(e,n){function o(t){for(var n=0;n<e.length;n++)if(e[n]===t.target){j=!0;break}j&&X(function(){return j=!1})}function u(){F=!0}function l(){F=!1,d()}function d(){Y(N),Y(K)}function s(){F=!1}function v(t){if(!t)return null;if(C===t)return t;if(r(e,t))return t;for(;t=t.parentNode;)if(r(e,t))return t;return null}function w(){for(var t=null,n=0;n<e.length;n++)h(O,e[n])&&(t=e[n]);return t}function p(e){if(x.autoScroll()&&!e.dispatched){var t=e.target,n=document.body;C&&!h(O,C)&&(x.scrollWhenOutside||(C=null)),t&&t.parentNode===n?t=w():(t=v(t))||(t=w()),t&&t!==C&&(C=t),q&&(Y(K),K=X(g)),C&&(Y(N),N=X(y))}}function g(){b(q),Y(K),K=X(g)}function y(){C&&(b(C),Y(N),N=X(y))}function b(e){var t,n,r=f(e);t=O.x<r.left+x.margin.left?Math.floor(Math.max(-1,(O.x-r.left)/x.margin.left-1)*x.maxSpeed.left):O.x>r.right-x.margin.right?Math.ceil(Math.min(1,(O.x-r.right)/x.margin.right+1)*x.maxSpeed.right):0,n=O.y<r.top+x.margin.top?Math.floor(Math.max(-1,(O.y-r.top)/x.margin.top-1)*x.maxSpeed.top):O.y>r.bottom-x.margin.bottom?Math.ceil(Math.min(1,(O.y-r.bottom)/x.margin.bottom+1)*x.maxSpeed.bottom):0,x.syncMove()&&M.dispatch(e,{pageX:O.pageX+t,pageY:O.pageY+n,clientX:O.x+t,clientY:O.y+n}),setTimeout(function(){n&&E(e,n),t&&T(e,t)})}function E(e,t){e===window?window.scrollTo(e.pageXOffset,e.pageYOffset+t):e.scrollTop+=t}function T(e,t){e===window?window.scrollTo(e.pageXOffset+t,e.pageYOffset):e.scrollLeft+=t}void 0===n&&(n={});var x=this,L=4,j=!1;if("object"!=typeof this.margin){var A=n.margin||-1;this.margin={left:A,right:A,top:A,bottom:A}}this.scrollWhenOutside=n.scrollWhenOutside||!1;var O={},S=c(O),M=m(),F=!1;window.addEventListener("mousemove",S,!1),window.addEventListener("touchmove",S,!1),isNaN(n.maxSpeed)||(L=n.maxSpeed),"object"!=typeof L&&(L={left:L,right:L,top:L,bottom:L}),this.autoScroll=t(n.autoScroll),this.syncMove=t(n.syncMove,!1),this.destroy=function(t){window.removeEventListener("mousemove",S,!1),window.removeEventListener("touchmove",S,!1),window.removeEventListener("mousedown",u,!1),window.removeEventListener("touchstart",u,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("touchend",l,!1),window.removeEventListener("pointerup",l,!1),window.removeEventListener("mouseleave",s,!1),window.removeEventListener("mousemove",p,!1),window.removeEventListener("touchmove",p,!1),window.removeEventListener("scroll",o,!0),e=[],t&&d()},this.add=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];return i.apply(void 0,[e].concat(t)),this},this.remove=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];return a.apply(void 0,[e].concat(t))};var K,q=null;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(t){e=[],t.forEach(function(e){e===window?q=window:x.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return F}},maxSpeed:{get:function(){return L}},point:{get:function(){return O}},scrolling:{get:function(){return j}}});var N,C=null;window.addEventListener("mousedown",u,!1),window.addEventListener("touchstart",u,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("touchend",l,!1),window.addEventListener("pointerup",l,!1),window.addEventListener("mousemove",p,!1),window.addEventListener("touchmove",p,!1),window.addEventListener("mouseleave",s,!1),window.addEventListener("scroll",o,!0)}function p(e,t){return new w(e,t)}function h(e,t,n){return n?e.y>n.top&&e.y<n.bottom&&e.x>n.left&&e.x<n.right:d(e,t)}var g=function(){var e=function(e){return"function"==typeof e},t=function(e){var t=Number(e);return isNaN(t)?0:0!==t&&isFinite(t)?(t>0?1:-1)*Math.floor(Math.abs(t)):t},n=Math.pow(2,53)-1,r=function(e){var r=t(e);return Math.min(Math.max(r,0),n)},o=function(e){if(null!=e){if(["string","number","boolean","symbol"].indexOf(typeof e)>-1)return Symbol.iterator;if("undefined"!=typeof Symbol&&"iterator"in Symbol&&Symbol.iterator in e)return Symbol.iterator;if("@@iterator"in e)return"@@iterator"}},i=function(t,n){if(null!=t&&null!=n){var r=t[n];if(null==r)return;if(!e(r))throw new TypeError(r+" is not a function");return r}},a=function(e){var t=e.next();return!Boolean(t.done)&&t};return function(t){var n,u=this,c=arguments.length>1?arguments[1]:void 0;if(void 0!==c){if(!e(c))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(n=arguments[2])}var l,f,d=i(t,o(t));if(void 0!==d){l=e(u)?Object(new u):[];var m=d.call(t);if(null==m)throw new TypeError("Array.from requires an array-like or iterable object");f=0;for(var s,v;;){if(!(s=a(m)))return l.length=f,l;v=s.value,l[f]=c?c.call(n,v,f):v,f++}}else{var w=Object(t);if(null==t)throw new TypeError("Array.from requires an array-like object - not null or undefined");var p=r(w.length);l=e(u)?Object(new u(p)):new Array(p),f=0;for(var h;f<p;)h=w[f],l[f]=c?c.call(n,h,f):h,f++;l.length=p}return l}}(),y=("function"==typeof Array.from&&Array.from,Array.isArray,Object.prototype.toString,"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}),b=function(e){return null!=e&&"object"===(void 0===e?"undefined":y(e))&&1===e.nodeType&&"object"===y(e.style)&&"object"===y(e.ownerDocument)},E=void 0;E="function"!=typeof Object.create?function(e){var t=function(){};return function(e,n){if(e!==Object(e)&&null!==e)throw TypeError("Argument must be an object, or null");t.prototype=e||{};var r=new t;return t.prototype=null,void 0!==n&&Object.defineProperties(r,n),null===e&&(r.__proto__=null),r}}():Object.create;var T=E,x=["altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","offsetX","offsetY","pageX","pageY","region","relatedTarget","screenX","screenY","shiftKey","which","x","y"],L=["webkit","moz","ms","o"],X=function(){if("undefined"==typeof window)return function(){};for(var e=0,t=L.length;e<t&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[L[e]+"RequestAnimationFrame"];if(!window.requestAnimationFrame){var n=0;window.requestAnimationFrame=function(e){var t=(new Date).getTime(),r=Math.max(0,16-t-n),o=window.setTimeout(function(){return e(t+r)},r);return n=t+r,o}}return window.requestAnimationFrame.bind(window)}(),Y=function(){if("undefined"==typeof window)return function(){};for(var e=0,t=L.length;e<t&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[L[e]+"CancelAnimationFrame"]||window[L[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}();return p}(); |
{ | ||
"name": "@mattlewis92/dom-autoscroller", | ||
"version": "2.3.7", | ||
"version": "2.4.0", | ||
"description": "Auto scroll dom elements", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174101
1499