dom-autoscroller
Advanced tools
Comparing version 2.2.8 to 2.3.0
@@ -32,3 +32,3 @@ import { boolean } from 'type-func'; | ||
this.destroy = function() { | ||
this.destroy = function(forceCleanAnimation) { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -46,2 +46,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
elements = []; | ||
if(forceCleanAnimation){ | ||
cleanAnimation(); | ||
} | ||
}; | ||
@@ -130,6 +133,8 @@ | ||
down = false; | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
cleanAnimation(); | ||
} | ||
function cleanAnimation(){ | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
} | ||
function onMouseOut(){ | ||
@@ -136,0 +141,0 @@ down = false; |
@@ -36,3 +36,3 @@ 'use strict'; | ||
this.destroy = function() { | ||
this.destroy = function(forceCleanAnimation) { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -50,2 +50,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
elements = []; | ||
if(forceCleanAnimation){ | ||
cleanAnimation(); | ||
} | ||
}; | ||
@@ -134,6 +137,8 @@ | ||
down = false; | ||
animationFramePolyfill.cancelAnimationFrame(animationFrame); | ||
animationFramePolyfill.cancelAnimationFrame(windowAnimationFrame); | ||
cleanAnimation(); | ||
} | ||
function cleanAnimation(){ | ||
animationFramePolyfill.cancelAnimationFrame(animationFrame); | ||
animationFramePolyfill.cancelAnimationFrame(windowAnimationFrame); | ||
} | ||
function onMouseOut(){ | ||
@@ -140,0 +145,0 @@ down = false; |
@@ -92,3 +92,218 @@ var autoScroll = (function () { | ||
// Reference: http://www.ecma-international.org/ecma-262/6.0/#sec-array.from | ||
var polyfill = (function() { | ||
var isCallable = function(fn) { | ||
return typeof fn === 'function'; | ||
}; | ||
var toInteger = function (value) { | ||
var number = Number(value); | ||
if (isNaN(number)) { return 0; } | ||
if (number === 0 || !isFinite(number)) { return number; } | ||
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); | ||
}; | ||
var maxSafeInteger = Math.pow(2, 53) - 1; | ||
var toLength = function (value) { | ||
var len = toInteger(value); | ||
return Math.min(Math.max(len, 0), maxSafeInteger); | ||
}; | ||
var iteratorProp = function(value) { | ||
if(value != null) { | ||
if(['string','number','boolean','symbol'].indexOf(typeof value) > -1){ | ||
return Symbol.iterator; | ||
} else if ( | ||
(typeof Symbol !== 'undefined') && | ||
('iterator' in Symbol) && | ||
(Symbol.iterator in value) | ||
) { | ||
return Symbol.iterator; | ||
} | ||
// Support "@@iterator" placeholder, Gecko 27 to Gecko 35 | ||
else if ('@@iterator' in value) { | ||
return '@@iterator'; | ||
} | ||
} | ||
}; | ||
var getMethod = function(O, P) { | ||
// Assert: IsPropertyKey(P) is true. | ||
if (O != null && P != null) { | ||
// Let func be GetV(O, P). | ||
var func = O[P]; | ||
// ReturnIfAbrupt(func). | ||
// If func is either undefined or null, return undefined. | ||
if(func == null) { | ||
return void 0; | ||
} | ||
// If IsCallable(func) is false, throw a TypeError exception. | ||
if (!isCallable(func)) { | ||
throw new TypeError(func + ' is not a function'); | ||
} | ||
return func; | ||
} | ||
}; | ||
var iteratorStep = function(iterator) { | ||
// Let result be IteratorNext(iterator). | ||
// ReturnIfAbrupt(result). | ||
var result = iterator.next(); | ||
// Let done be IteratorComplete(result). | ||
// ReturnIfAbrupt(done). | ||
var done = Boolean(result.done); | ||
// If done is true, return false. | ||
if(done) { | ||
return false; | ||
} | ||
// Return result. | ||
return result; | ||
}; | ||
// The length property of the from method is 1. | ||
return function from(items /*, mapFn, thisArg */ ) { | ||
'use strict'; | ||
// 1. Let C be the this value. | ||
var C = this; | ||
// 2. If mapfn is undefined, let mapping be false. | ||
var mapFn = arguments.length > 1 ? arguments[1] : void 0; | ||
var T; | ||
if (typeof mapFn !== 'undefined') { | ||
// 3. else | ||
// a. If IsCallable(mapfn) is false, throw a TypeError exception. | ||
if (!isCallable(mapFn)) { | ||
throw new TypeError( | ||
'Array.from: when provided, the second argument must be a function' | ||
); | ||
} | ||
// b. If thisArg was supplied, let T be thisArg; else let T | ||
// be undefined. | ||
if (arguments.length > 2) { | ||
T = arguments[2]; | ||
} | ||
// c. Let mapping be true (implied by mapFn) | ||
} | ||
var A, k; | ||
// 4. Let usingIterator be GetMethod(items, @@iterator). | ||
// 5. ReturnIfAbrupt(usingIterator). | ||
var usingIterator = getMethod(items, iteratorProp(items)); | ||
// 6. If usingIterator is not undefined, then | ||
if (usingIterator !== void 0) { | ||
// a. If IsConstructor(C) is true, then | ||
// i. Let A be the result of calling the [[Construct]] | ||
// internal method of C with an empty argument list. | ||
// b. Else, | ||
// i. Let A be the result of the abstract operation ArrayCreate | ||
// with argument 0. | ||
// c. ReturnIfAbrupt(A). | ||
A = isCallable(C) ? Object(new C()) : []; | ||
// d. Let iterator be GetIterator(items, usingIterator). | ||
var iterator = usingIterator.call(items); | ||
// e. ReturnIfAbrupt(iterator). | ||
if (iterator == null) { | ||
throw new TypeError( | ||
'Array.from requires an array-like or iterable object' | ||
); | ||
} | ||
// f. Let k be 0. | ||
k = 0; | ||
// g. Repeat | ||
var next, nextValue; | ||
while (true) { | ||
// i. Let Pk be ToString(k). | ||
// ii. Let next be IteratorStep(iterator). | ||
// iii. ReturnIfAbrupt(next). | ||
next = iteratorStep(iterator); | ||
// iv. If next is false, then | ||
if (!next) { | ||
// 1. Let setStatus be Set(A, "length", k, true). | ||
// 2. ReturnIfAbrupt(setStatus). | ||
A.length = k; | ||
// 3. Return A. | ||
return A; | ||
} | ||
// v. Let nextValue be IteratorValue(next). | ||
// vi. ReturnIfAbrupt(nextValue) | ||
nextValue = next.value; | ||
// vii. If mapping is true, then | ||
// 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). | ||
// 2. If mappedValue is an abrupt completion, return | ||
// IteratorClose(iterator, mappedValue). | ||
// 3. Let mappedValue be mappedValue.[[value]]. | ||
// viii. Else, let mappedValue be nextValue. | ||
// ix. Let defineStatus be the result of | ||
// CreateDataPropertyOrThrow(A, Pk, mappedValue). | ||
// x. [TODO] If defineStatus is an abrupt completion, return | ||
// IteratorClose(iterator, defineStatus). | ||
if (mapFn) { | ||
A[k] = mapFn.call(T, nextValue, k); | ||
} | ||
else { | ||
A[k] = nextValue; | ||
} | ||
// xi. Increase k by 1. | ||
k++; | ||
} | ||
// 7. Assert: items is not an Iterable so assume it is | ||
// an array-like object. | ||
} else { | ||
// 8. Let arrayLike be ToObject(items). | ||
var arrayLike = Object(items); | ||
// 9. ReturnIfAbrupt(items). | ||
if (items == null) { | ||
throw new TypeError( | ||
'Array.from requires an array-like object - not null or undefined' | ||
); | ||
} | ||
// 10. Let len be ToLength(Get(arrayLike, "length")). | ||
// 11. ReturnIfAbrupt(len). | ||
var len = toLength(arrayLike.length); | ||
// 12. If IsConstructor(C) is true, then | ||
// a. Let A be Construct(C, «len»). | ||
// 13. Else | ||
// a. Let A be ArrayCreate(len). | ||
// 14. ReturnIfAbrupt(A). | ||
A = isCallable(C) ? Object(new C(len)) : new Array(len); | ||
// 15. Let k be 0. | ||
k = 0; | ||
// 16. Repeat, while k < len… (also steps a - h) | ||
var kValue; | ||
while (k < len) { | ||
kValue = arrayLike[k]; | ||
if (mapFn) { | ||
A[k] = mapFn.call(T, kValue, k); | ||
} | ||
else { | ||
A[k] = kValue; | ||
} | ||
k++; | ||
} | ||
// 17. Let setStatus be Set(A, "length", len, true). | ||
// 18. ReturnIfAbrupt(setStatus). | ||
A.length = len; | ||
// 19. Return A. | ||
} | ||
return A; | ||
}; | ||
})(); | ||
var index = (typeof Array.from === 'function' ? | ||
Array.from : | ||
polyfill | ||
); | ||
/** | ||
@@ -98,7 +313,36 @@ * isArray | ||
function indexOfElement(elements, element) { | ||
var isArray = Array.isArray; | ||
/** | ||
* toString | ||
*/ | ||
var str = Object.prototype.toString; | ||
/** | ||
* Whether or not the given `val` | ||
* is an array. | ||
* | ||
* example: | ||
* | ||
* isArray([]); | ||
* // > true | ||
* isArray(arguments); | ||
* // > false | ||
* isArray(''); | ||
* // > false | ||
* | ||
* @param {mixed} val | ||
* @return {bool} | ||
*/ | ||
var index$1 = isArray || function (val) { | ||
return !! val && '[object Array]' == str.call(val); | ||
}; | ||
function indexOfElement(elements, element){ | ||
element = resolveElement(element, true); | ||
if (!isElement(element)) { return -1; } | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === element) { | ||
if(!isElement(element)) { return -1; } | ||
for(var i=0; i<elements.length; i++){ | ||
if(elements[i] === element){ | ||
return i; | ||
@@ -110,21 +354,44 @@ } | ||
function hasElement(elements, element) { | ||
function hasElement(elements, element){ | ||
return -1 !== indexOfElement(elements, element); | ||
} | ||
function pushElements(elements, toAdd) { | ||
function domListOf(arr){ | ||
for (var i = 0; i < toAdd.length; i++) { | ||
if (!hasElement(elements, toAdd[i])) { elements.push(toAdd[i]); } | ||
if(!arr) { return []; } | ||
try{ | ||
if(typeof arr === 'string'){ | ||
return index(document.querySelectorAll(arr)); | ||
}else if(index$1(arr)){ | ||
return arr.map(resolveElement); | ||
}else{ | ||
if(typeof arr.length === 'undefined'){ | ||
return [resolveElement(arr)]; | ||
} | ||
return index(arr, resolveElement); | ||
} | ||
}catch(e){ | ||
throw new Error(e); | ||
} | ||
} | ||
function pushElements(elements, toAdd){ | ||
for(var i=0; i<toAdd.length; i++){ | ||
if(!hasElement(elements, toAdd[i])) | ||
{ elements.push(toAdd[i]); } | ||
} | ||
return toAdd; | ||
} | ||
function addElements(elements) { | ||
function addElements(elements){ | ||
var arguments$1 = arguments; | ||
for (var _len2 = arguments.length, toAdd = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
toAdd[_key2 - 1] = arguments$1[_key2]; | ||
} | ||
var toAdd = [], len = arguments.length - 1; | ||
while ( len-- > 0 ) { toAdd[ len ] = arguments$1[ len + 1 ]; } | ||
@@ -135,14 +402,14 @@ toAdd = toAdd.map(resolveElement); | ||
function removeElements(elements) { | ||
function removeElements(elements){ | ||
var arguments$1 = arguments; | ||
for (var _len3 = arguments.length, toRemove = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
toRemove[_key3 - 1] = arguments$1[_key3]; | ||
} | ||
var toRemove = [], len = arguments.length - 1; | ||
while ( len-- > 0 ) { toRemove[ len ] = arguments$1[ len + 1 ]; } | ||
return toRemove.map(resolveElement).reduce(function (last, e) { | ||
return toRemove.map(resolveElement).reduce(function (last, e){ | ||
var index$$1 = indexOfElement(elements, e); | ||
if (index$$1 !== -1) { return last.concat(elements.splice(index$$1, 1)); } | ||
if(index$$1 !== -1) | ||
{ return last.concat(elements.splice(index$$1, 1)); } | ||
return last; | ||
@@ -152,13 +419,14 @@ }, []); | ||
function resolveElement(element, noThrow) { | ||
if (typeof element === 'string') { | ||
try { | ||
function resolveElement(element, noThrow){ | ||
if(typeof element === 'string'){ | ||
try{ | ||
return document.querySelector(element); | ||
} catch (e) { | ||
}catch(e){ | ||
throw e; | ||
} | ||
} | ||
if (!isElement(element) && !noThrow) { | ||
throw new TypeError(element + ' is not a DOM element.'); | ||
if(!isElement(element) && !noThrow){ | ||
throw new TypeError((element + " is not a DOM element.")); | ||
} | ||
@@ -168,3 +436,3 @@ return element; | ||
var index$2 = function createPointCB(object, options){ | ||
function createPointCB(object, options) { | ||
@@ -183,11 +451,11 @@ // A persistent object (as opposed to returned object) is used to save memory | ||
var allowUpdate; | ||
var allowUpdate = boolean(options.allowUpdate, true); | ||
if(typeof options.allowUpdate === 'function'){ | ||
/*if(typeof options.allowUpdate === 'function'){ | ||
allowUpdate = options.allowUpdate; | ||
}else{ | ||
allowUpdate = function(){return true;}; | ||
} | ||
}*/ | ||
return function pointCB(event){ | ||
return function pointCB(event) { | ||
@@ -199,3 +467,3 @@ event = event || window.event; // IE-ism | ||
if(!allowUpdate(event)){ | ||
if (!allowUpdate(event)) { | ||
return; | ||
@@ -207,8 +475,10 @@ } | ||
if(event.targetTouches){ | ||
if (event.targetTouches) { | ||
object.x = event.targetTouches[0].clientX; | ||
object.y = event.targetTouches[0].clientY; | ||
object.pageX = event.pageX; | ||
object.pageY = event.pageY; | ||
}else{ | ||
object.pageX = event.targetTouches[0].pageX; | ||
object.pageY = event.targetTouches[0].pageY; | ||
object.screenX = event.targetTouches[0].screenX; | ||
object.screenY = event.targetTouches[0].screenY; | ||
} else { | ||
@@ -221,13 +491,9 @@ // If pageX/Y aren't available and clientX/Y are, | ||
if (event.pageX === null && event.clientX !== null) { | ||
var eventDoc = (event.target && event.target.ownerDocument) || document; | ||
var eventDoc = event.target && event.target.ownerDocument || document; | ||
var doc = eventDoc.documentElement; | ||
var body = eventDoc.body; | ||
object.pageX = event.clientX + | ||
(doc && doc.scrollLeft || body && body.scrollLeft || 0) - | ||
(doc && doc.clientLeft || body && body.clientLeft || 0); | ||
object.pageY = event.clientY + | ||
(doc && doc.scrollTop || body && body.scrollTop || 0) - | ||
(doc && doc.clientTop || body && body.clientTop || 0 ); | ||
}else{ | ||
object.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0); | ||
object.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0); | ||
} else { | ||
object.pageX = event.pageX; | ||
@@ -244,8 +510,13 @@ object.pageY = event.pageY; | ||
object.y = event.clientY; | ||
object.screenX = event.screenX; | ||
object.screenY = event.screenY; | ||
} | ||
object.clientX = object.x; | ||
object.clientY = object.y; | ||
}; | ||
//NOTE Remember accessibility, Aria roles, and labels. | ||
}; | ||
} | ||
@@ -442,3 +713,3 @@ function createWindowRect() { | ||
var point = {}, | ||
pointCB = index$2(point), | ||
pointCB = createPointCB(point), | ||
dispatcher = createDispatcher(), | ||
@@ -457,3 +728,3 @@ down = false; | ||
this.destroy = function() { | ||
this.destroy = function(forceCleanAnimation) { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -471,2 +742,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
elements = []; | ||
if(forceCleanAnimation){ | ||
cleanAnimation(); | ||
} | ||
}; | ||
@@ -555,6 +829,8 @@ | ||
down = false; | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
cleanAnimation(); | ||
} | ||
function cleanAnimation(){ | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
} | ||
function onMouseOut(){ | ||
@@ -561,0 +837,0 @@ down = false; |
@@ -1,1 +0,1 @@ | ||
var autoScroll=function(){"use strict";function e(e,n){return"undefined"==typeof e?"undefined"==typeof n?e:n:e}function n(n,t){return n=e(n,t),"function"==typeof n?function(){for(var e=arguments,t=arguments.length,o=Array(t),r=0;r<t;r++)o[r]=e[r];return!!n.apply(this,o)}:n?function(){return!0}:function(){return!1}}function t(e,n){if(n=a(n,!0),!E(n))return-1;for(var t=0;t<e.length;t++)if(e[t]===n)return t;return-1}function o(e,n){return-1!==t(e,n)}function r(e,n){for(var t=0;t<n.length;t++)o(e,n[t])||e.push(n[t]);return n}function i(e){for(var n=arguments,t=arguments.length,o=Array(t>1?t-1:0),i=1;i<t;i++)o[i-1]=n[i];return o=o.map(a),r(e,o)}function u(e){for(var n=arguments,o=arguments.length,r=Array(o>1?o-1:0),i=1;i<o;i++)r[i-1]=n[i];return r.map(a).reduce(function(n,o){var r=t(e,o);return r!==-1?n.concat(e.splice(r,1)):n},[])}function a(e,n){if("string"==typeof e)try{return document.querySelector(e)}catch(e){throw e}if(!E(e)&&!n)throw new TypeError(e+" is not a DOM element.");return e}function c(){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 l(e){if(e===window)return c();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 f(e,n){var t=l(n);return e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right}function d(e){function n(e){for(var n=0;n<T.length;n++)o[T[n]]=e[T[n]]}function t(){e&&e.removeEventListener("mousemove",n,!1),o=null}var o={screenX:0,screenY:0,clientX:0,clientY:0,ctrlKey:!1,shiftKey:!1,altKey:!1,metaKey:!1,button:0,buttons:1,relatedTarget:null,region:null};void 0!==e&&e.addEventListener("mousemove",n);var r=function(){return MouseEvent?function(e,n,t){var r=new MouseEvent("mousemove",m(o,n));return s(r,t),e.dispatchEvent(r)}:"function"==typeof document.createEvent?function(e,n,t){var r=m(o,n),i=document.createEvent("MouseEvents");return i.initMouseEvent("mousemove",!0,!0,window,0,r.screenX,r.screenY,r.clientX,r.clientY,r.ctrlKey,r.altKey,r.shiftKey,r.metaKey,r.button,r.relatedTarget),s(i,t),e.dispatchEvent(i)}:"function"==typeof document.createEventObject?function(e,n,t){var r=document.createEventObject(),i=m(o,n);for(var u in i)r[u]=i[u];return s(r,t),e.dispatchEvent(r)}:void 0}();return{destroy:t,dispatch:r}}function m(e,n){n=n||{};for(var t=X(e),o=0;o<T.length;o++)void 0!==n[T[o]]&&(t[T[o]]=n[T[o]]);return t}function s(e,n){console.log("data ",n),e.data=n||{},e.dispatched="mousemove"}function v(e,t){function r(n){for(var t=0;t<e.length;t++)if(e[t]===n.target){Y=!0;break}Y&&h(function(){return Y=!1})}function a(){S=!0}function c(){S=!1,y(K),y(j)}function f(){S=!1}function m(n){if(!n)return null;if(q===n)return n;if(o(e,n))return n;for(;n=n.parentNode;)if(o(e,n))return n;return null}function s(){for(var n=null,t=0;t<e.length;t++)p(O,e[t])&&(n=e[t]);return n}function v(e){if(X.autoScroll()&&!e.dispatched){var n=e.target,t=document.body;q&&!p(O,q)&&(X.scrollWhenOutside||(q=null)),n&&n.parentNode===t?n=s():(n=m(n),n||(n=s())),n&&n!==q&&(q=n),F&&(y(j),j=h(w)),q&&(y(K),K=h(g))}}function w(){b(F),y(j),j=h(w)}function g(){q&&(b(q),y(K),K=h(g))}function b(e){var n,t,o=l(e);n=O.x<o.left+X.margin?Math.floor(Math.max(-1,(O.x-o.left)/X.margin-1)*X.maxSpeed):O.x>o.right-X.margin?Math.ceil(Math.min(1,(O.x-o.right)/X.margin+1)*X.maxSpeed):0,t=O.y<o.top+X.margin?Math.floor(Math.max(-1,(O.y-o.top)/X.margin-1)*X.maxSpeed):O.y>o.bottom-X.margin?Math.ceil(Math.min(1,(O.y-o.bottom)/X.margin+1)*X.maxSpeed):0,X.syncMove()&&M.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&&x(e,n)})}function E(e,n){e===window?window.scrollTo(e.pageXOffset,e.pageYOffset+n):e.scrollTop+=n}function x(e,n){e===window?window.scrollTo(e.pageXOffset+n,e.pageYOffset):e.scrollLeft+=n}void 0===t&&(t={});var X=this,T=4,Y=!1;this.margin=t.margin||-1,this.scrollWhenOutside=t.scrollWhenOutside||!1;var O={},A=L(O),M=d(),S=!1;window.addEventListener("mousemove",A,!1),window.addEventListener("touchmove",A,!1),isNaN(t.maxSpeed)||(T=t.maxSpeed),this.autoScroll=n(t.autoScroll),this.syncMove=n(t.syncMove,!1),this.destroy=function(){window.removeEventListener("mousemove",A,!1),window.removeEventListener("touchmove",A,!1),window.removeEventListener("mousedown",a,!1),window.removeEventListener("touchstart",a,!1),window.removeEventListener("mouseup",c,!1),window.removeEventListener("touchend",c,!1),window.removeEventListener("mousemove",v,!1),window.removeEventListener("touchmove",v,!1),window.removeEventListener("scroll",r,!0),e=[]},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 u.apply(void 0,[e].concat(n))};var j,F=null;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(n){e=[],n.forEach(function(e){e===window?F=window:X.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return S}},maxSpeed:{get:function(){return T}},point:{get:function(){return O}},scrolling:{get:function(){return Y}}});var K,q=null;window.addEventListener("mousedown",a,!1),window.addEventListener("touchstart",a,!1),window.addEventListener("mouseup",c,!1),window.addEventListener("touchend",c,!1),window.addEventListener("mousemove",v,!1),window.addEventListener("touchmove",v,!1),window.addEventListener("mouseleave",f,!1),window.addEventListener("scroll",r,!0)}function w(e,n){return new v(e,n)}function p(e,n,t){return t?e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right:f(e,n)}var g=["webkit","moz","ms","o"],h=function(){for(var e=0,n=g.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[g[e]+"RequestAnimationFrame"];return window.requestAnimationFrame||!function(){var e=0;window.requestAnimationFrame=function(n){var t=(new Date).getTime(),o=Math.max(0,16-t-e),r=window.setTimeout(function(){return n(t+o)},o);return e=t+o,r}}(),window.requestAnimationFrame.bind(window)}(),y=function(){for(var e=0,n=g.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[g[e]+"CancelAnimationFrame"]||window[g[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}(),b="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},E=function(e){return null!=e&&"object"===("undefined"==typeof e?"undefined":b(e))&&1===e.nodeType&&"object"===b(e.style)&&"object"===b(e.ownerDocument)},L=function(e,n){n=n||{};var t;return t="function"==typeof n.allowUpdate?n.allowUpdate:function(){return!0},function(n){if(n=n||window.event,e.target=n.target||n.srcElement||n.originalTarget,e.element=this,e.type=n.type,t(n))if(n.targetTouches)e.x=n.targetTouches[0].clientX,e.y=n.targetTouches[0].clientY,e.pageX=n.pageX,e.pageY=n.pageY;else{if(null===n.pageX&&null!==n.clientX){var o=n.target&&n.target.ownerDocument||document,r=o.documentElement,i=o.body;e.pageX=n.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=n.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)}else e.pageX=n.pageX,e.pageY=n.pageY;e.x=n.clientX,e.y=n.clientY}}},x=void 0;x="function"!=typeof Object.create?function(e){var n=function(){};return function(t,o){if(t!==Object(t)&&null!==t)throw TypeError("Argument must be an object, or null");n.prototype=t||{};var r=new n;return n.prototype=null,o!==e&&Object.defineProperties(r,o),null===t&&(r.__proto__=null),r}}():Object.create;var X=x,T=["altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","offsetX","offsetY","pageX","pageY","region","relatedTarget","screenX","screenY","shiftKey","which","x","y"];return w}(); | ||
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),!T(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(!T(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<L.length;n++)r[L[n]]=e[L[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=Y(e),r=0;r<L.length;r++)void 0!==n[L[r]]&&(t[L[r]]=n[L[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&&y(function(){return A=!1})}function u(){M=!0}function l(){M=!1,d()}function d(){b(q),b(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++)p(O,e[t])&&(n=e[t]);return n}function h(e){if(Y.autoScroll()&&!e.dispatched){var n=e.target,t=document.body;N&&!p(O,N)&&(Y.scrollWhenOutside||(N=null)),n&&n.parentNode===t?n=w():(n=v(n))||(n=w()),n&&n!==N&&(N=n),K&&(b(F),F=y(g)),N&&(b(q),q=y(E))}}function g(){T(K),b(F),F=y(g)}function E(){N&&(T(N),b(q),q=y(E))}function T(e){var n,t,r=f(e);n=O.x<r.left+Y.margin?Math.floor(Math.max(-1,(O.x-r.left)/Y.margin-1)*Y.maxSpeed):O.x>r.right-Y.margin?Math.ceil(Math.min(1,(O.x-r.right)/Y.margin+1)*Y.maxSpeed):0,t=O.y<r.top+Y.margin?Math.floor(Math.max(-1,(O.y-r.top)/Y.margin-1)*Y.maxSpeed):O.y>r.bottom-Y.margin?Math.ceil(Math.min(1,(O.y-r.bottom)/Y.margin+1)*Y.maxSpeed):0,Y.syncMove()&&j.dispatch(e,{pageX:O.pageX+n,pageY:O.pageY+t,clientX:O.x+n,clientY:O.y+t}),setTimeout(function(){t&&x(e,t),n&&X(e,n)})}function x(e,n){e===window?window.scrollTo(e.pageXOffset,e.pageYOffset+n):e.scrollTop+=n}function X(e,n){e===window?window.scrollTo(e.pageXOffset+n,e.pageYOffset):e.scrollLeft+=n}void 0===t&&(t={});var Y=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("mousemove",h,!1),window.removeEventListener("touchmove",h,!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:Y.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("mousemove",h,!1),window.addEventListener("touchmove",h,!1),window.addEventListener("mouseleave",m,!1),window.addEventListener("scroll",o,!0)}function h(e,n){return new w(e,n)}function p(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 g=["webkit","moz","ms","o"],y=function(){for(var e=0,n=g.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[g[e]+"RequestAnimationFrame"];return window.requestAnimationFrame||function(){var e=0;window.requestAnimationFrame=function(n){var t=(new Date).getTime(),r=Math.max(0,16-t-e),o=window.setTimeout(function(){return n(t+r)},r);return e=t+r,o}}(),window.requestAnimationFrame.bind(window)}(),b=function(){for(var e=0,n=g.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[g[e]+"CancelAnimationFrame"]||window[g[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}(),E="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},T=function(e){return null!=e&&"object"===(void 0===e?"undefined":E(e))&&1===e.nodeType&&"object"===E(e.style)&&"object"===E(e.ownerDocument)},x=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 h=r(w.length);l=e(u)?Object(new u(h)):new Array(h),f=0;for(var p;f<h;)p=w[f],l[f]=c?c.call(t,p,f):p,f++;l.length=h}return l}}(),X=("function"==typeof Array.from&&Array.from,Array.isArray,Object.prototype.toString,void 0);X="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 Y=X,L=["altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","offsetX","offsetY","pageX","pageY","region","relatedTarget","screenX","screenY","shiftKey","which","x","y"];return h}(); |
{ | ||
"name": "dom-autoscroller", | ||
"version": "2.2.8", | ||
"version": "2.3.0", | ||
"description": "Auto scroll dom elements", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
@@ -241,5 +241,5 @@ dom-autoscroller | ||
### destroy | ||
### destroy(forceCleanAnimation) | ||
Remove all event listeners needed to be able track the pointer. | ||
Remove all event listeners needed to be able to track the pointer. If destroy Auto Scroller meanwhile scrolling then just call `.destroy(true)` to force to stop scrolling animation. Call `.destroy()` and `.destroy(false)` is the same behaviours. | ||
@@ -246,0 +246,0 @@ Undocumented methods |
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
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
157762
1350