dom-autoscroller
Advanced tools
Comparing version 2.2.7 to 2.2.8
@@ -7,8 +7,7 @@ import { boolean } from 'type-func'; | ||
function AutoScroller(elements) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function AutoScroller(elements, options){ | ||
if ( options === void 0 ) options = {}; | ||
var self = this; | ||
var maxSpeed = 4, | ||
scrolling = false; | ||
var maxSpeed = 4, scrolling = false; | ||
@@ -27,3 +26,3 @@ this.margin = options.margin || -1; | ||
if (!isNaN(options.maxSpeed)) { | ||
if(!isNaN(options.maxSpeed)){ | ||
maxSpeed = options.maxSpeed; | ||
@@ -35,3 +34,3 @@ } | ||
this.destroy = function () { | ||
this.destroy = function() { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -44,2 +43,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
window.removeEventListener('mousemove', onMove, false); | ||
window.removeEventListener('touchmove', onMove, false); | ||
window.removeEventListener('scroll', setScroll, true); | ||
@@ -49,63 +51,50 @@ elements = []; | ||
this.add = function () { | ||
for (var _len = arguments.length, element = Array(_len), _key = 0; _key < _len; _key++) { | ||
element[_key] = arguments[_key]; | ||
} | ||
this.add = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
addElements.apply(undefined, [elements].concat(element)); | ||
addElements.apply(void 0, [ elements ].concat( element )); | ||
return this; | ||
}; | ||
this.remove = function () { | ||
for (var _len2 = arguments.length, element = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
element[_key2] = arguments[_key2]; | ||
} | ||
this.remove = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
return removeElements.apply(undefined, [elements].concat(element)); | ||
return removeElements.apply(void 0, [ elements ].concat( element )); | ||
}; | ||
var hasWindow = null, | ||
windowAnimationFrame = void 0; | ||
var hasWindow = null, windowAnimationFrame; | ||
if (Object.prototype.toString.call(elements) !== '[object Array]') { | ||
if(Object.prototype.toString.call(elements) !== '[object Array]'){ | ||
elements = [elements]; | ||
} | ||
(function (temp) { | ||
(function(temp){ | ||
elements = []; | ||
temp.forEach(function (element) { | ||
if (element === window) { | ||
temp.forEach(function(element){ | ||
if(element === window){ | ||
hasWindow = window; | ||
} else { | ||
}else{ | ||
self.add(element); | ||
} | ||
}); | ||
})(elements); | ||
}(elements)); | ||
Object.defineProperties(this, { | ||
down: { | ||
get: function get() { | ||
return down; | ||
} | ||
get: function(){ return down; } | ||
}, | ||
maxSpeed: { | ||
get: function get() { | ||
return maxSpeed; | ||
} | ||
get: function(){ return maxSpeed; } | ||
}, | ||
point: { | ||
get: function get() { | ||
return point; | ||
} | ||
get: function(){ return point; } | ||
}, | ||
scrolling: { | ||
get: function get() { | ||
return scrolling; | ||
} | ||
get: function(){ return scrolling; } | ||
} | ||
}); | ||
var n = 0, | ||
current = null, | ||
animationFrame = void 0; | ||
var n = 0, current = null, animationFrame; | ||
@@ -124,6 +113,6 @@ window.addEventListener('mousedown', onDown, false); | ||
function setScroll(e) { | ||
function setScroll(e){ | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === e.target) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(elements[i] === e.target){ | ||
scrolling = true; | ||
@@ -134,14 +123,12 @@ break; | ||
if (scrolling) { | ||
requestAnimationFrame(function () { | ||
return scrolling = false; | ||
}); | ||
if(scrolling){ | ||
requestAnimationFrame(function (){ return scrolling = false; }); | ||
} | ||
} | ||
function onDown() { | ||
function onDown(){ | ||
down = true; | ||
} | ||
function onUp() { | ||
function onUp(){ | ||
down = false; | ||
@@ -152,21 +139,21 @@ cancelAnimationFrame(animationFrame); | ||
function onMouseOut() { | ||
function onMouseOut(){ | ||
down = false; | ||
} | ||
function getTarget(target) { | ||
if (!target) { | ||
function getTarget(target){ | ||
if(!target){ | ||
return null; | ||
} | ||
if (current === target) { | ||
if(current === target){ | ||
return target; | ||
} | ||
if (hasElement(elements, target)) { | ||
if(hasElement(elements, target)){ | ||
return target; | ||
} | ||
while (target = target.parentNode) { | ||
if (hasElement(elements, target)) { | ||
while(target = target.parentNode){ | ||
if(hasElement(elements, target)){ | ||
return target; | ||
@@ -179,7 +166,7 @@ } | ||
function getElementUnderPoint() { | ||
function getElementUnderPoint(){ | ||
var underPoint = null; | ||
for (var i = 0; i < elements.length; i++) { | ||
if (inside(point, elements[i])) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(inside(point, elements[i])){ | ||
underPoint = elements[i]; | ||
@@ -192,15 +179,13 @@ } | ||
function onMove(event) { | ||
if (!self.autoScroll()) return; | ||
function onMove(event){ | ||
if (event['dispatched']) { | ||
return; | ||
} | ||
if(!self.autoScroll()) { return; } | ||
var target = event.target, | ||
body = document.body; | ||
if(event['dispatched']){ return; } | ||
if (current && !inside(point, current)) { | ||
if (!self.scrollWhenOutside) { | ||
var target = event.target, body = document.body; | ||
if(current && !inside(point, current)){ | ||
if(!self.scrollWhenOutside){ | ||
current = null; | ||
@@ -210,9 +195,9 @@ } | ||
if (target && target.parentNode === body) { | ||
if(target && target.parentNode === body){ | ||
//The special condition to improve speed. | ||
target = getElementUnderPoint(); | ||
} else { | ||
}else{ | ||
target = getTarget(target); | ||
if (!target) { | ||
if(!target){ | ||
target = getElementUnderPoint(); | ||
@@ -222,7 +207,8 @@ } | ||
if (target && target !== current) { | ||
if(target && target !== current){ | ||
current = target; | ||
} | ||
if (hasWindow) { | ||
if(hasWindow){ | ||
cancelAnimationFrame(windowAnimationFrame); | ||
@@ -232,3 +218,4 @@ windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -241,3 +228,3 @@ } | ||
function scrollWindow() { | ||
function scrollWindow(){ | ||
autoScroll(hasWindow); | ||
@@ -249,5 +236,5 @@ | ||
function scrollTick() { | ||
function scrollTick(){ | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -260,26 +247,34 @@ } | ||
animationFrame = requestAnimationFrame(scrollTick); | ||
} | ||
function autoScroll(el) { | ||
var rect = getClientRect(el), | ||
scrollx = void 0, | ||
scrolly = void 0; | ||
if (point.x < rect.left + self.margin) { | ||
scrollx = Math.floor(Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.x > rect.right - self.margin) { | ||
scrollx = Math.ceil(Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
function autoScroll(el){ | ||
var rect = getClientRect(el), scrollx, scrolly; | ||
if(point.x < rect.left + self.margin){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrollx = 0; | ||
} | ||
if (point.y < rect.top + self.margin) { | ||
scrolly = Math.floor(Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.y > rect.bottom - self.margin) { | ||
scrolly = Math.ceil(Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
if(point.y < rect.top + self.margin){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrolly = 0; | ||
} | ||
if (self.syncMove()) { | ||
if(self.syncMove()){ | ||
/* | ||
@@ -299,18 +294,19 @@ Notes about mousemove event dispatch. | ||
setTimeout(function () { | ||
setTimeout(function (){ | ||
if (scrolly) { | ||
if(scrolly){ | ||
scrollY(el, scrolly); | ||
} | ||
if (scrollx) { | ||
if(scrollx){ | ||
scrollX(el, scrollx); | ||
} | ||
}); | ||
} | ||
function scrollY(el, amount) { | ||
if (el === window) { | ||
function scrollY(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset, el.pageYOffset + amount); | ||
} else { | ||
}else{ | ||
el.scrollTop += amount; | ||
@@ -320,20 +316,22 @@ } | ||
function scrollX(el, amount) { | ||
if (el === window) { | ||
function scrollX(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset + amount, el.pageYOffset); | ||
} else { | ||
}else{ | ||
el.scrollLeft += amount; | ||
} | ||
} | ||
} | ||
function AutoScrollerFactory(element, options) { | ||
function AutoScrollerFactory(element, options){ | ||
return new AutoScroller(element, options); | ||
} | ||
function inside(point, el, rect) { | ||
if (!rect) { | ||
function inside(point, el, rect){ | ||
if(!rect){ | ||
return pointInside(point, el); | ||
} else { | ||
return point.y > rect.top && point.y < rect.bottom && point.x > rect.left && point.x < rect.right; | ||
}else{ | ||
return (point.y > rect.top && point.y < rect.bottom && | ||
point.x > rect.left && point.x < rect.right); | ||
} | ||
@@ -340,0 +338,0 @@ } |
@@ -11,8 +11,7 @@ 'use strict'; | ||
function AutoScroller(elements) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function AutoScroller(elements, options){ | ||
if ( options === void 0 ) options = {}; | ||
var self = this; | ||
var maxSpeed = 4, | ||
scrolling = false; | ||
var maxSpeed = 4, scrolling = false; | ||
@@ -31,3 +30,3 @@ this.margin = options.margin || -1; | ||
if (!isNaN(options.maxSpeed)) { | ||
if(!isNaN(options.maxSpeed)){ | ||
maxSpeed = options.maxSpeed; | ||
@@ -39,3 +38,3 @@ } | ||
this.destroy = function () { | ||
this.destroy = function() { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -48,2 +47,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
window.removeEventListener('mousemove', onMove, false); | ||
window.removeEventListener('touchmove', onMove, false); | ||
window.removeEventListener('scroll', setScroll, true); | ||
@@ -53,63 +55,50 @@ elements = []; | ||
this.add = function () { | ||
for (var _len = arguments.length, element = Array(_len), _key = 0; _key < _len; _key++) { | ||
element[_key] = arguments[_key]; | ||
} | ||
this.add = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
domSet.addElements.apply(undefined, [elements].concat(element)); | ||
domSet.addElements.apply(void 0, [ elements ].concat( element )); | ||
return this; | ||
}; | ||
this.remove = function () { | ||
for (var _len2 = arguments.length, element = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
element[_key2] = arguments[_key2]; | ||
} | ||
this.remove = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
return domSet.removeElements.apply(undefined, [elements].concat(element)); | ||
return domSet.removeElements.apply(void 0, [ elements ].concat( element )); | ||
}; | ||
var hasWindow = null, | ||
windowAnimationFrame = void 0; | ||
var hasWindow = null, windowAnimationFrame; | ||
if (Object.prototype.toString.call(elements) !== '[object Array]') { | ||
if(Object.prototype.toString.call(elements) !== '[object Array]'){ | ||
elements = [elements]; | ||
} | ||
(function (temp) { | ||
(function(temp){ | ||
elements = []; | ||
temp.forEach(function (element) { | ||
if (element === window) { | ||
temp.forEach(function(element){ | ||
if(element === window){ | ||
hasWindow = window; | ||
} else { | ||
}else{ | ||
self.add(element); | ||
} | ||
}); | ||
})(elements); | ||
}(elements)); | ||
Object.defineProperties(this, { | ||
down: { | ||
get: function get() { | ||
return down; | ||
} | ||
get: function(){ return down; } | ||
}, | ||
maxSpeed: { | ||
get: function get() { | ||
return maxSpeed; | ||
} | ||
get: function(){ return maxSpeed; } | ||
}, | ||
point: { | ||
get: function get() { | ||
return point; | ||
} | ||
get: function(){ return point; } | ||
}, | ||
scrolling: { | ||
get: function get() { | ||
return scrolling; | ||
} | ||
get: function(){ return scrolling; } | ||
} | ||
}); | ||
var n = 0, | ||
current = null, | ||
animationFrame = void 0; | ||
var n = 0, current = null, animationFrame; | ||
@@ -128,6 +117,6 @@ window.addEventListener('mousedown', onDown, false); | ||
function setScroll(e) { | ||
function setScroll(e){ | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === e.target) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(elements[i] === e.target){ | ||
scrolling = true; | ||
@@ -138,14 +127,12 @@ break; | ||
if (scrolling) { | ||
animationFramePolyfill.requestAnimationFrame(function () { | ||
return scrolling = false; | ||
}); | ||
if(scrolling){ | ||
animationFramePolyfill.requestAnimationFrame(function (){ return scrolling = false; }); | ||
} | ||
} | ||
function onDown() { | ||
function onDown(){ | ||
down = true; | ||
} | ||
function onUp() { | ||
function onUp(){ | ||
down = false; | ||
@@ -156,21 +143,21 @@ animationFramePolyfill.cancelAnimationFrame(animationFrame); | ||
function onMouseOut() { | ||
function onMouseOut(){ | ||
down = false; | ||
} | ||
function getTarget(target) { | ||
if (!target) { | ||
function getTarget(target){ | ||
if(!target){ | ||
return null; | ||
} | ||
if (current === target) { | ||
if(current === target){ | ||
return target; | ||
} | ||
if (domSet.hasElement(elements, target)) { | ||
if(domSet.hasElement(elements, target)){ | ||
return target; | ||
} | ||
while (target = target.parentNode) { | ||
if (domSet.hasElement(elements, target)) { | ||
while(target = target.parentNode){ | ||
if(domSet.hasElement(elements, target)){ | ||
return target; | ||
@@ -183,7 +170,7 @@ } | ||
function getElementUnderPoint() { | ||
function getElementUnderPoint(){ | ||
var underPoint = null; | ||
for (var i = 0; i < elements.length; i++) { | ||
if (inside(point, elements[i])) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(inside(point, elements[i])){ | ||
underPoint = elements[i]; | ||
@@ -196,15 +183,13 @@ } | ||
function onMove(event) { | ||
if (!self.autoScroll()) return; | ||
function onMove(event){ | ||
if (event['dispatched']) { | ||
return; | ||
} | ||
if(!self.autoScroll()) { return; } | ||
var target = event.target, | ||
body = document.body; | ||
if(event['dispatched']){ return; } | ||
if (current && !inside(point, current)) { | ||
if (!self.scrollWhenOutside) { | ||
var target = event.target, body = document.body; | ||
if(current && !inside(point, current)){ | ||
if(!self.scrollWhenOutside){ | ||
current = null; | ||
@@ -214,9 +199,9 @@ } | ||
if (target && target.parentNode === body) { | ||
if(target && target.parentNode === body){ | ||
//The special condition to improve speed. | ||
target = getElementUnderPoint(); | ||
} else { | ||
}else{ | ||
target = getTarget(target); | ||
if (!target) { | ||
if(!target){ | ||
target = getElementUnderPoint(); | ||
@@ -226,7 +211,8 @@ } | ||
if (target && target !== current) { | ||
if(target && target !== current){ | ||
current = target; | ||
} | ||
if (hasWindow) { | ||
if(hasWindow){ | ||
animationFramePolyfill.cancelAnimationFrame(windowAnimationFrame); | ||
@@ -236,3 +222,4 @@ windowAnimationFrame = animationFramePolyfill.requestAnimationFrame(scrollWindow); | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -245,3 +232,3 @@ } | ||
function scrollWindow() { | ||
function scrollWindow(){ | ||
autoScroll(hasWindow); | ||
@@ -253,5 +240,5 @@ | ||
function scrollTick() { | ||
function scrollTick(){ | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -264,26 +251,34 @@ } | ||
animationFrame = animationFramePolyfill.requestAnimationFrame(scrollTick); | ||
} | ||
function autoScroll(el) { | ||
var rect = domPlane.getClientRect(el), | ||
scrollx = void 0, | ||
scrolly = void 0; | ||
if (point.x < rect.left + self.margin) { | ||
scrollx = Math.floor(Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.x > rect.right - self.margin) { | ||
scrollx = Math.ceil(Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
function autoScroll(el){ | ||
var rect = domPlane.getClientRect(el), scrollx, scrolly; | ||
if(point.x < rect.left + self.margin){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrollx = 0; | ||
} | ||
if (point.y < rect.top + self.margin) { | ||
scrolly = Math.floor(Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.y > rect.bottom - self.margin) { | ||
scrolly = Math.ceil(Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
if(point.y < rect.top + self.margin){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrolly = 0; | ||
} | ||
if (self.syncMove()) { | ||
if(self.syncMove()){ | ||
/* | ||
@@ -303,18 +298,19 @@ Notes about mousemove event dispatch. | ||
setTimeout(function () { | ||
setTimeout(function (){ | ||
if (scrolly) { | ||
if(scrolly){ | ||
scrollY(el, scrolly); | ||
} | ||
if (scrollx) { | ||
if(scrollx){ | ||
scrollX(el, scrollx); | ||
} | ||
}); | ||
} | ||
function scrollY(el, amount) { | ||
if (el === window) { | ||
function scrollY(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset, el.pageYOffset + amount); | ||
} else { | ||
}else{ | ||
el.scrollTop += amount; | ||
@@ -324,20 +320,22 @@ } | ||
function scrollX(el, amount) { | ||
if (el === window) { | ||
function scrollX(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset + amount, el.pageYOffset); | ||
} else { | ||
}else{ | ||
el.scrollLeft += amount; | ||
} | ||
} | ||
} | ||
function AutoScrollerFactory(element, options) { | ||
function AutoScrollerFactory(element, options){ | ||
return new AutoScroller(element, options); | ||
} | ||
function inside(point, el, rect) { | ||
if (!rect) { | ||
function inside(point, el, rect){ | ||
if(!rect){ | ||
return domPlane.pointInside(point, el); | ||
} else { | ||
return point.y > rect.top && point.y < rect.bottom && point.x > rect.left && point.x < rect.right; | ||
}else{ | ||
return (point.y > rect.top && point.y < rect.bottom && | ||
point.x > rect.left && point.x < rect.right); | ||
} | ||
@@ -344,0 +342,0 @@ } |
@@ -17,4 +17,6 @@ var autoScroll = (function () { | ||
return function f() { | ||
var arguments$1 = arguments; | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
args[_key] = arguments$1[_key]; | ||
} | ||
@@ -77,7 +79,3 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
@@ -96,208 +94,3 @@ /** | ||
// 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$1 = typeof Array.from === 'function' ? Array.from : polyfill; | ||
/** | ||
@@ -307,34 +100,5 @@ * isArray | ||
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$2 = isArray || function (val) { | ||
return !!val && '[object Array]' == str.call(val); | ||
}; | ||
function indexOfElement(elements, element) { | ||
element = resolveElement(element, true); | ||
if (!isElement(element)) return -1; | ||
if (!isElement(element)) { return -1; } | ||
for (var i = 0; i < elements.length; i++) { | ||
@@ -352,27 +116,6 @@ if (elements[i] === element) { | ||
function domListOf(arr) { | ||
if (!arr) return []; | ||
try { | ||
if (typeof arr === 'string') { | ||
return index$1(document.querySelectorAll(arr)); | ||
} else if (index$2(arr)) { | ||
return arr.map(resolveElement); | ||
} else { | ||
if (typeof arr.length === 'undefined') { | ||
return [resolveElement(arr)]; | ||
} | ||
return index$1(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]); | ||
if (!hasElement(elements, toAdd[i])) { elements.push(toAdd[i]); } | ||
} | ||
@@ -384,4 +127,6 @@ | ||
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[_key2]; | ||
toAdd[_key2 - 1] = arguments$1[_key2]; | ||
} | ||
@@ -394,4 +139,6 @@ | ||
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[_key3]; | ||
toRemove[_key3 - 1] = arguments$1[_key3]; | ||
} | ||
@@ -401,5 +148,5 @@ | ||
var index = indexOfElement(elements, e); | ||
var index$$1 = indexOfElement(elements, e); | ||
if (index !== -1) return last.concat(elements.splice(index, 1)); | ||
if (index$$1 !== -1) { return last.concat(elements.splice(index$$1, 1)); } | ||
return last; | ||
@@ -424,3 +171,3 @@ }, []); | ||
var index$3 = function createPointCB(object, options) { | ||
var index$2 = function createPointCB(object, options){ | ||
@@ -441,11 +188,9 @@ // A persistent object (as opposed to returned object) is used to save memory | ||
if (typeof options.allowUpdate === 'function') { | ||
if(typeof options.allowUpdate === 'function'){ | ||
allowUpdate = options.allowUpdate; | ||
} else { | ||
allowUpdate = function () { | ||
return true; | ||
}; | ||
}else{ | ||
allowUpdate = function(){return true;}; | ||
} | ||
return function pointCB(event) { | ||
return function pointCB(event){ | ||
@@ -457,3 +202,3 @@ event = event || window.event; // IE-ism | ||
if (!allowUpdate(event)) { | ||
if(!allowUpdate(event)){ | ||
return; | ||
@@ -465,3 +210,3 @@ } | ||
if (event.targetTouches) { | ||
if(event.targetTouches){ | ||
object.x = event.targetTouches[0].clientX; | ||
@@ -471,3 +216,3 @@ object.y = event.targetTouches[0].clientY; | ||
object.pageY = event.pageY; | ||
} else { | ||
}else{ | ||
@@ -480,9 +225,13 @@ // 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; | ||
@@ -500,2 +249,3 @@ object.pageY = event.pageY; | ||
} | ||
}; | ||
@@ -551,24 +301,24 @@ | ||
if (typeof Object.create != 'function') { | ||
objectCreate = function (undefined) { | ||
var Temp = function Temp() {}; | ||
return function (prototype, propertiesObject) { | ||
if (prototype !== Object(prototype) && prototype !== null) { | ||
throw TypeError('Argument must be an object, or null'); | ||
} | ||
Temp.prototype = prototype || {}; | ||
var result = new Temp(); | ||
Temp.prototype = null; | ||
if (propertiesObject !== undefined) { | ||
Object.defineProperties(result, propertiesObject); | ||
} | ||
objectCreate = function (undefined) { | ||
var Temp = function Temp() {}; | ||
return function (prototype, propertiesObject) { | ||
if (prototype !== Object(prototype) && prototype !== null) { | ||
throw TypeError('Argument must be an object, or null'); | ||
} | ||
Temp.prototype = prototype || {}; | ||
var result = new Temp(); | ||
Temp.prototype = null; | ||
if (propertiesObject !== undefined) { | ||
Object.defineProperties(result, propertiesObject); | ||
} | ||
// to imitate the case of Object.create(null) | ||
if (prototype === null) { | ||
result.__proto__ = null; | ||
} | ||
return result; | ||
}; | ||
}(); | ||
// to imitate the case of Object.create(null) | ||
if (prototype === null) { | ||
result.__proto__ = null; | ||
} | ||
return result; | ||
}; | ||
}(); | ||
} else { | ||
objectCreate = Object.create; | ||
objectCreate = Object.create; | ||
} | ||
@@ -660,3 +410,3 @@ | ||
function destroy() { | ||
if (element) element.removeEventListener('mousemove', onMove, false); | ||
if (element) { element.removeEventListener('mousemove', onMove, false); } | ||
defaultSettings = null; | ||
@@ -675,3 +425,3 @@ } | ||
for (var i = 0; i < mouseEventProps.length; i++) { | ||
if (initMove[mouseEventProps[i]] !== undefined) settings[mouseEventProps[i]] = initMove[mouseEventProps[i]]; | ||
if (initMove[mouseEventProps[i]] !== undefined) { settings[mouseEventProps[i]] = initMove[mouseEventProps[i]]; } | ||
} | ||
@@ -688,8 +438,7 @@ | ||
function AutoScroller(elements) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function AutoScroller(elements, options){ | ||
if ( options === void 0 ) options = {}; | ||
var self = this; | ||
var maxSpeed = 4, | ||
scrolling = false; | ||
var maxSpeed = 4, scrolling = false; | ||
@@ -701,3 +450,3 @@ this.margin = options.margin || -1; | ||
var point = {}, | ||
pointCB = index$3(point), | ||
pointCB = index$2(point), | ||
dispatcher = createDispatcher(), | ||
@@ -709,3 +458,3 @@ down = false; | ||
if (!isNaN(options.maxSpeed)) { | ||
if(!isNaN(options.maxSpeed)){ | ||
maxSpeed = options.maxSpeed; | ||
@@ -717,3 +466,3 @@ } | ||
this.destroy = function () { | ||
this.destroy = function() { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
@@ -726,2 +475,5 @@ window.removeEventListener('touchmove', pointCB, false); | ||
window.removeEventListener('mousemove', onMove, false); | ||
window.removeEventListener('touchmove', onMove, false); | ||
window.removeEventListener('scroll', setScroll, true); | ||
@@ -731,63 +483,50 @@ elements = []; | ||
this.add = function () { | ||
for (var _len = arguments.length, element = Array(_len), _key = 0; _key < _len; _key++) { | ||
element[_key] = arguments[_key]; | ||
} | ||
this.add = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
addElements.apply(undefined, [elements].concat(element)); | ||
addElements.apply(void 0, [ elements ].concat( element )); | ||
return this; | ||
}; | ||
this.remove = function () { | ||
for (var _len2 = arguments.length, element = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
element[_key2] = arguments[_key2]; | ||
} | ||
this.remove = function(){ | ||
var element = [], len = arguments.length; | ||
while ( len-- ) element[ len ] = arguments[ len ]; | ||
return removeElements.apply(undefined, [elements].concat(element)); | ||
return removeElements.apply(void 0, [ elements ].concat( element )); | ||
}; | ||
var hasWindow = null, | ||
windowAnimationFrame = void 0; | ||
var hasWindow = null, windowAnimationFrame; | ||
if (Object.prototype.toString.call(elements) !== '[object Array]') { | ||
if(Object.prototype.toString.call(elements) !== '[object Array]'){ | ||
elements = [elements]; | ||
} | ||
(function (temp) { | ||
(function(temp){ | ||
elements = []; | ||
temp.forEach(function (element) { | ||
if (element === window) { | ||
temp.forEach(function(element){ | ||
if(element === window){ | ||
hasWindow = window; | ||
} else { | ||
}else{ | ||
self.add(element); | ||
} | ||
}); | ||
})(elements); | ||
}(elements)); | ||
Object.defineProperties(this, { | ||
down: { | ||
get: function get() { | ||
return down; | ||
} | ||
get: function(){ return down; } | ||
}, | ||
maxSpeed: { | ||
get: function get() { | ||
return maxSpeed; | ||
} | ||
get: function(){ return maxSpeed; } | ||
}, | ||
point: { | ||
get: function get() { | ||
return point; | ||
} | ||
get: function(){ return point; } | ||
}, | ||
scrolling: { | ||
get: function get() { | ||
return scrolling; | ||
} | ||
get: function(){ return scrolling; } | ||
} | ||
}); | ||
var n = 0, | ||
current = null, | ||
animationFrame = void 0; | ||
var n = 0, current = null, animationFrame; | ||
@@ -806,6 +545,6 @@ window.addEventListener('mousedown', onDown, false); | ||
function setScroll(e) { | ||
function setScroll(e){ | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === e.target) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(elements[i] === e.target){ | ||
scrolling = true; | ||
@@ -816,14 +555,12 @@ break; | ||
if (scrolling) { | ||
requestAnimationFrame(function () { | ||
return scrolling = false; | ||
}); | ||
if(scrolling){ | ||
requestAnimationFrame(function (){ return scrolling = false; }); | ||
} | ||
} | ||
function onDown() { | ||
function onDown(){ | ||
down = true; | ||
} | ||
function onUp() { | ||
function onUp(){ | ||
down = false; | ||
@@ -834,21 +571,21 @@ cancelAnimationFrame(animationFrame); | ||
function onMouseOut() { | ||
function onMouseOut(){ | ||
down = false; | ||
} | ||
function getTarget(target) { | ||
if (!target) { | ||
function getTarget(target){ | ||
if(!target){ | ||
return null; | ||
} | ||
if (current === target) { | ||
if(current === target){ | ||
return target; | ||
} | ||
if (hasElement(elements, target)) { | ||
if(hasElement(elements, target)){ | ||
return target; | ||
} | ||
while (target = target.parentNode) { | ||
if (hasElement(elements, target)) { | ||
while(target = target.parentNode){ | ||
if(hasElement(elements, target)){ | ||
return target; | ||
@@ -861,7 +598,7 @@ } | ||
function getElementUnderPoint() { | ||
function getElementUnderPoint(){ | ||
var underPoint = null; | ||
for (var i = 0; i < elements.length; i++) { | ||
if (inside(point, elements[i])) { | ||
for(var i=0; i<elements.length; i++){ | ||
if(inside(point, elements[i])){ | ||
underPoint = elements[i]; | ||
@@ -874,15 +611,13 @@ } | ||
function onMove(event) { | ||
if (!self.autoScroll()) return; | ||
function onMove(event){ | ||
if (event['dispatched']) { | ||
return; | ||
} | ||
if(!self.autoScroll()) { return; } | ||
var target = event.target, | ||
body = document.body; | ||
if(event['dispatched']){ return; } | ||
if (current && !inside(point, current)) { | ||
if (!self.scrollWhenOutside) { | ||
var target = event.target, body = document.body; | ||
if(current && !inside(point, current)){ | ||
if(!self.scrollWhenOutside){ | ||
current = null; | ||
@@ -892,9 +627,9 @@ } | ||
if (target && target.parentNode === body) { | ||
if(target && target.parentNode === body){ | ||
//The special condition to improve speed. | ||
target = getElementUnderPoint(); | ||
} else { | ||
}else{ | ||
target = getTarget(target); | ||
if (!target) { | ||
if(!target){ | ||
target = getElementUnderPoint(); | ||
@@ -904,7 +639,8 @@ } | ||
if (target && target !== current) { | ||
if(target && target !== current){ | ||
current = target; | ||
} | ||
if (hasWindow) { | ||
if(hasWindow){ | ||
cancelAnimationFrame(windowAnimationFrame); | ||
@@ -914,3 +650,4 @@ windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -923,3 +660,3 @@ } | ||
function scrollWindow() { | ||
function scrollWindow(){ | ||
autoScroll(hasWindow); | ||
@@ -931,5 +668,5 @@ | ||
function scrollTick() { | ||
function scrollTick(){ | ||
if (!current) { | ||
if(!current){ | ||
return; | ||
@@ -942,26 +679,34 @@ } | ||
animationFrame = requestAnimationFrame(scrollTick); | ||
} | ||
function autoScroll(el) { | ||
var rect = getClientRect(el), | ||
scrollx = void 0, | ||
scrolly = void 0; | ||
if (point.x < rect.left + self.margin) { | ||
scrollx = Math.floor(Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.x > rect.right - self.margin) { | ||
scrollx = Math.ceil(Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
function autoScroll(el){ | ||
var rect = getClientRect(el), scrollx, scrolly; | ||
if(point.x < rect.left + self.margin){ | ||
scrollx = Math.floor( | ||
Math.max(-1, (point.x - rect.left) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.x > rect.right - self.margin){ | ||
scrollx = Math.ceil( | ||
Math.min(1, (point.x - rect.right) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrollx = 0; | ||
} | ||
if (point.y < rect.top + self.margin) { | ||
scrolly = Math.floor(Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed); | ||
} else if (point.y > rect.bottom - self.margin) { | ||
scrolly = Math.ceil(Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed); | ||
} else { | ||
if(point.y < rect.top + self.margin){ | ||
scrolly = Math.floor( | ||
Math.max(-1, (point.y - rect.top) / self.margin - 1) * self.maxSpeed | ||
); | ||
}else if(point.y > rect.bottom - self.margin){ | ||
scrolly = Math.ceil( | ||
Math.min(1, (point.y - rect.bottom) / self.margin + 1) * self.maxSpeed | ||
); | ||
}else{ | ||
scrolly = 0; | ||
} | ||
if (self.syncMove()) { | ||
if(self.syncMove()){ | ||
/* | ||
@@ -981,18 +726,19 @@ Notes about mousemove event dispatch. | ||
setTimeout(function () { | ||
setTimeout(function (){ | ||
if (scrolly) { | ||
if(scrolly){ | ||
scrollY(el, scrolly); | ||
} | ||
if (scrollx) { | ||
if(scrollx){ | ||
scrollX(el, scrollx); | ||
} | ||
}); | ||
} | ||
function scrollY(el, amount) { | ||
if (el === window) { | ||
function scrollY(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset, el.pageYOffset + amount); | ||
} else { | ||
}else{ | ||
el.scrollTop += amount; | ||
@@ -1002,20 +748,22 @@ } | ||
function scrollX(el, amount) { | ||
if (el === window) { | ||
function scrollX(el, amount){ | ||
if(el === window){ | ||
window.scrollTo(el.pageXOffset + amount, el.pageYOffset); | ||
} else { | ||
}else{ | ||
el.scrollLeft += amount; | ||
} | ||
} | ||
} | ||
function AutoScrollerFactory(element, options) { | ||
function AutoScrollerFactory(element, options){ | ||
return new AutoScroller(element, options); | ||
} | ||
function inside(point, el, rect) { | ||
if (!rect) { | ||
function inside(point, el, rect){ | ||
if(!rect){ | ||
return pointInside(point, el); | ||
} else { | ||
return point.y > rect.top && point.y < rect.bottom && point.x > rect.left && point.x < rect.right; | ||
}else{ | ||
return (point.y > rect.top && point.y < rect.bottom && | ||
point.x > rect.left && point.x < rect.right); | ||
} | ||
@@ -1022,0 +770,0 @@ } |
@@ -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.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return!!n.apply(this,t)}:n?function(){return!0}:function(){return!1}}function t(e,n){if(n=u(n,!0),!E(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.length,t=Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t=t.map(u),o(e,t)}function a(e){for(var n=arguments.length,r=Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.map(u).reduce(function(n,r){var o=t(e,r);return o!==-1?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(!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<O.length;n++)r[O[n]]=e[O[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};void 0!==e&&e.addEventListener("mousemove",n);var o=function(){return MouseEvent?function(e,n,t){var o=new MouseEvent("mousemove",m(r,n));return s(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),s(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 s(o,t),e.dispatchEvent(o)}:void 0}();return{destroy:t,dispatch:o}}function m(e,n){n=n||{};for(var t=L(e),r=0;r<O.length;r++)void 0!==n[O[r]]&&(t[O[r]]=n[O[r]]);return t}function s(e,n){console.log("data ",n),e.data=n||{},e.dispatched="mousemove"}function v(e){function t(n){for(var t=0;t<e.length;t++)if(e[t]===n.target){O=!0;break}O&&h(function(){return O=!1})}function o(){M=!0}function u(){M=!1,g(q),g(F)}function c(){M=!1}function f(n){if(!n)return null;if(K===n)return n;if(r(e,n))return n;for(;n=n.parentNode;)if(r(e,n))return n;return null}function m(){for(var n=null,t=0;t<e.length;t++)p(X,e[t])&&(n=e[t]);return n}function s(e){if(T.autoScroll()&&!e.dispatched){var n=e.target,t=document.body;K&&!p(X,K)&&(T.scrollWhenOutside||(K=null)),n&&n.parentNode===t?n=m():(n=f(n),n||(n=m())),n&&n!==K&&(K=n),Y&&(g(F),F=h(v)),K&&(g(q),q=h(w))}}function v(){y(Y),g(F),F=h(v)}function w(){K&&(y(K),g(q),q=h(w))}function y(e){var n=l(e),t=void 0,r=void 0;t=X.x<n.left+T.margin?Math.floor(Math.max(-1,(X.x-n.left)/T.margin-1)*T.maxSpeed):X.x>n.right-T.margin?Math.ceil(Math.min(1,(X.x-n.right)/T.margin+1)*T.maxSpeed):0,r=X.y<n.top+T.margin?Math.floor(Math.max(-1,(X.y-n.top)/T.margin-1)*T.maxSpeed):X.y>n.bottom-T.margin?Math.ceil(Math.min(1,(X.y-n.bottom)/T.margin+1)*T.maxSpeed):0,T.syncMove()&&j.dispatch(e,{pageX:X.pageX+t,pageY:X.pageY+r,clientX:X.x+t,clientY:X.y+r}),setTimeout(function(){r&&b(e,r),t&&E(e,t)})}function b(e,n){e===window?window.scrollTo(e.pageXOffset,e.pageYOffset+n):e.scrollTop+=n}function E(e,n){e===window?window.scrollTo(e.pageXOffset+n,e.pageYOffset):e.scrollLeft+=n}var x=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},T=this,L=4,O=!1;this.margin=x.margin||-1,this.scrollWhenOutside=x.scrollWhenOutside||!1;var X={},S=A(X),j=d(),M=!1;window.addEventListener("mousemove",S,!1),window.addEventListener("touchmove",S,!1),isNaN(x.maxSpeed)||(L=x.maxSpeed),this.autoScroll=n(x.autoScroll),this.syncMove=n(x.syncMove,!1),this.destroy=function(){window.removeEventListener("mousemove",S,!1),window.removeEventListener("touchmove",S,!1),window.removeEventListener("mousedown",o,!1),window.removeEventListener("touchstart",o,!1),window.removeEventListener("mouseup",u,!1),window.removeEventListener("touchend",u,!1),window.removeEventListener("scroll",t,!0),e=[]},this.add=function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];return i.apply(void 0,[e].concat(t)),this},this.remove=function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];return a.apply(void 0,[e].concat(t))};var Y=null,F=void 0;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(n){e=[],n.forEach(function(e){e===window?Y=window:T.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return M}},maxSpeed:{get:function(){return L}},point:{get:function(){return X}},scrolling:{get:function(){return O}}});var K=null,q=void 0;window.addEventListener("mousedown",o,!1),window.addEventListener("touchstart",o,!1),window.addEventListener("mouseup",u,!1),window.addEventListener("touchend",u,!1),window.addEventListener("mousemove",s,!1),window.addEventListener("touchmove",s,!1),window.addEventListener("mouseleave",c,!1),window.addEventListener("scroll",t,!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 y=["webkit","moz","ms","o"],h=function(){for(var e=0,n=y.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[y[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)}(),g=function(){for(var e=0,n=y.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[y[e]+"CancelAnimationFrame"]||window[y[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)},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(),t=Boolean(n.done);return!t&&n};return function(n){var t,u=this,c=arguments.length>1?arguments[1]:void 0;if("undefined"!=typeof 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 m=d.call(n);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),!s)return l.length=f,l;v=s.value,c?l[f]=c.call(t,v,f):l[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 y;f<p;)y=w[f],c?l[f]=c.call(t,y,f):l[f]=y,f++;l.length=p}return l}}(),A=("function"==typeof Array.from?Array.from:x,Array.isArray,Object.prototype.toString,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 r=n.target&&n.target.ownerDocument||document,o=r.documentElement,i=r.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}}}),T=void 0;T="function"!=typeof Object.create?function(e){var n=function(){};return function(t,r){if(t!==Object(t)&&null!==t)throw TypeError("Argument must be an object, or null");n.prototype=t||{};var o=new n;return n.prototype=null,r!==e&&Object.defineProperties(o,r),null===t&&(o.__proto__=null),o}}():Object.create;var L=T,O=["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"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}(); |
{ | ||
"name": "dom-autoscroller", | ||
"version": "2.2.7", | ||
"version": "2.2.8", | ||
"description": "Auto scroll dom elements", | ||
@@ -14,5 +14,2 @@ "main": "dist/bundle.js", | ||
}, | ||
"pre-commit": [ | ||
"build" | ||
], | ||
"keywords": [ | ||
@@ -33,7 +30,6 @@ "scrolling", | ||
"devDependencies": { | ||
"babel-preset-es2015-rollup": "^1.2.0", | ||
"dragula": "^3.7.2", | ||
"minifyify": "^7.3.3", | ||
"precommit-hook": "^3.0.0", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"rollup": "^0.41.4", | ||
"rollup-plugin-buble": "^0.15.0", | ||
"rollup-plugin-commonjs": "^5.0.5", | ||
@@ -40,0 +36,0 @@ "rollup-plugin-node-resolve": "^2.0.0", |
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
8
141787
1096