dom-autoscroller
Advanced tools
Comparing version 2.2.1 to 2.2.2
import { boolean } from 'type-func'; | ||
import { requestAnimationFrame, cancelAnimationFrame } from 'animation-frame-polyfill'; | ||
import { hasElement, removeElements, addElements } from 'dom-set'; | ||
import { getClientRect, createPointCB, pointInside } from 'dom-plane'; | ||
import { cancelAnimationFrame, requestAnimationFrame } from 'animation-frame-polyfill'; | ||
import { addElements, hasElement, removeElements } from 'dom-set'; | ||
import { createPointCB, getClientRect, pointInside } from 'dom-plane'; | ||
@@ -6,0 +6,0 @@ function AutoScroller(elements) { |
var autoScroll = (function () { | ||
'use strict'; | ||
'use strict'; | ||
function getDef(f, d) { | ||
if (typeof f === 'undefined') { | ||
return typeof d === 'undefined' ? f : d; | ||
} | ||
function getDef(f, d) { | ||
if (typeof f === 'undefined') { | ||
return typeof d === 'undefined' ? f : d; | ||
} | ||
return f; | ||
return f; | ||
} | ||
function boolean(func, def) { | ||
func = getDef(func, def); | ||
if (typeof func === 'function') { | ||
return function f() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return !!func.apply(this, args); | ||
}; | ||
} | ||
return !!func ? function () { | ||
return true; | ||
} : function () { | ||
return false; | ||
}; | ||
} | ||
var prefix = ['webkit', 'moz', 'ms', 'o']; | ||
var requestAnimationFrame = function () { | ||
for (var i = 0, limit = prefix.length; i < limit && !window.requestAnimationFrame; ++i) { | ||
window.requestAnimationFrame = window[prefix[i] + 'RequestAnimationFrame']; | ||
} | ||
function boolean(func, def) { | ||
func = getDef(func, def); | ||
if (!window.requestAnimationFrame) { | ||
(function () { | ||
var lastTime = 0; | ||
if (typeof func === 'function') { | ||
return function f() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
window.requestAnimationFrame = function (callback) { | ||
var now = new Date().getTime(); | ||
var ttc = Math.max(0, 16 - now - lastTime); | ||
var timer = window.setTimeout(function () { | ||
return callback(now + ttc); | ||
}, ttc); | ||
return !!func.apply(this, args); | ||
}; | ||
} | ||
lastTime = now + ttc; | ||
return !!func ? function () { | ||
return true; | ||
} : function () { | ||
return false; | ||
return timer; | ||
}; | ||
})(); | ||
} | ||
var prefix = ['webkit', 'moz', 'ms', 'o']; | ||
return window.requestAnimationFrame.bind(window); | ||
}(); | ||
var requestAnimationFrame = function () { | ||
var cancelAnimationFrame = function () { | ||
for (var i = 0, limit = prefix.length; i < limit && !window.requestAnimationFrame; ++i) { | ||
window.requestAnimationFrame = window[prefix[i] + 'RequestAnimationFrame']; | ||
} | ||
for (var i = 0, limit = prefix.length; i < limit && !window.cancelAnimationFrame; ++i) { | ||
window.cancelAnimationFrame = window[prefix[i] + 'CancelAnimationFrame'] || window[prefix[i] + 'CancelRequestAnimationFrame']; | ||
} | ||
if (!window.requestAnimationFrame) { | ||
(function () { | ||
var lastTime = 0; | ||
if (!window.cancelAnimationFrame) { | ||
window.cancelAnimationFrame = function (timer) { | ||
window.clearTimeout(timer); | ||
}; | ||
} | ||
window.requestAnimationFrame = function (callback) { | ||
var now = new Date().getTime(); | ||
var ttc = Math.max(0, 16 - now - lastTime); | ||
var timer = window.setTimeout(function () { | ||
return callback(now + ttc); | ||
}, ttc); | ||
return window.cancelAnimationFrame.bind(window); | ||
}(); | ||
lastTime = now + ttc; | ||
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; | ||
}; | ||
return timer; | ||
}; | ||
})(); | ||
/** | ||
* Returns `true` if provided input is Element. | ||
* @name isElement | ||
* @param {*} [input] | ||
* @returns {boolean} | ||
*/ | ||
var isElement = function (input) { | ||
return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.nodeType === 1 && _typeof(input.style) === 'object' && _typeof(input.ownerDocument) === 'object'; | ||
}; | ||
// Production steps of ECMA-262, Edition 6, 22.1.2.1 | ||
// 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; | ||
}; | ||
return window.requestAnimationFrame.bind(window); | ||
}(); | ||
// The length property of the from method is 1. | ||
return function from(items /*, mapFn, thisArg */) { | ||
'use strict'; | ||
var cancelAnimationFrame = function () { | ||
// 1. Let C be the this value. | ||
for (var i = 0, limit = prefix.length; i < limit && !window.cancelAnimationFrame; ++i) { | ||
window.cancelAnimationFrame = window[prefix[i] + 'CancelAnimationFrame'] || window[prefix[i] + 'CancelRequestAnimationFrame']; | ||
} | ||
var C = this; | ||
if (!window.cancelAnimationFrame) { | ||
window.cancelAnimationFrame = function (timer) { | ||
window.clearTimeout(timer); | ||
}; | ||
// 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) | ||
} | ||
return window.cancelAnimationFrame.bind(window); | ||
}(); | ||
var A, k; | ||
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; | ||
}; | ||
// 4. Let usingIterator be GetMethod(items, @@iterator). | ||
// 5. ReturnIfAbrupt(usingIterator). | ||
var usingIterator = getMethod(items, iteratorProp(items)); | ||
/** | ||
* Returns `true` if provided input is Element. | ||
* @name isElement | ||
* @param {*} [input] | ||
* @returns {boolean} | ||
*/ | ||
function isElement (input) { | ||
return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.nodeType === 1 && _typeof(input.style) === 'object' && _typeof(input.ownerDocument) === 'object'; | ||
} | ||
// 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()) : []; | ||
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) { | ||
return i; | ||
} | ||
// 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'); | ||
} | ||
return -1; | ||
} | ||
function hasElement(elements, element) { | ||
return -1 !== indexOfElement(elements, element); | ||
} | ||
// f. Let k be 0. | ||
k = 0; | ||
function pushElements(elements, toAdd) { | ||
// 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); | ||
for (var i = 0; i < toAdd.length; i++) { | ||
if (!hasElement(elements, toAdd[i])) elements.push(toAdd[i]); | ||
// 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 { | ||
return toAdd; | ||
} | ||
// 8. Let arrayLike be ToObject(items). | ||
var arrayLike = Object(items); | ||
function addElements(elements) { | ||
for (var _len2 = arguments.length, toAdd = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
toAdd[_key2 - 1] = arguments[_key2]; | ||
// 9. ReturnIfAbrupt(items). | ||
if (items == null) { | ||
throw new TypeError('Array.from requires an array-like object - not null or undefined'); | ||
} | ||
toAdd = toAdd.map(resolveElement); | ||
return pushElements(elements, toAdd); | ||
} | ||
// 10. Let len be ToLength(Get(arrayLike, "length")). | ||
// 11. ReturnIfAbrupt(len). | ||
var len = toLength(arrayLike.length); | ||
function removeElements(elements) { | ||
for (var _len3 = arguments.length, toRemove = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
toRemove[_key3 - 1] = arguments[_key3]; | ||
// 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; | ||
}; | ||
}(); | ||
return toRemove.map(resolveElement).reduce(function (last, e) { | ||
var index$1 = typeof Array.from === 'function' ? Array.from : polyfill; | ||
var index = indexOfElement(elements, e); | ||
/** | ||
* isArray | ||
*/ | ||
if (index !== -1) return last.concat(elements.splice(index, 1)); | ||
return last; | ||
}, []); | ||
} | ||
var isArray = Array.isArray; | ||
function resolveElement(element, noThrow) { | ||
if (typeof element === 'string') { | ||
try { | ||
return document.querySelector(element); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
/** | ||
* toString | ||
*/ | ||
if (!isElement(element) && !noThrow) { | ||
throw new TypeError(element + ' is not a DOM element.'); | ||
} | ||
return element; | ||
} | ||
var str = Object.prototype.toString; | ||
var index$2 = function createPointCB(object) { | ||
/** | ||
* Whether or not the given `val` | ||
* is an array. | ||
* | ||
* example: | ||
* | ||
* isArray([]); | ||
* // > true | ||
* isArray(arguments); | ||
* // > false | ||
* isArray(''); | ||
* // > false | ||
* | ||
* @param {mixed} val | ||
* @return {bool} | ||
*/ | ||
// A persistent object (as opposed to returned object) is used to save memory | ||
// This is good to prevent layout thrashing, or for games, and such | ||
var index$2 = isArray || function (val) { | ||
return !!val && '[object Array]' == str.call(val); | ||
}; | ||
// NOTE | ||
// This uses IE fixes which should be OK to remove some day. :) | ||
// Some speed will be gained by removal of these. | ||
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) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
// pointCB should be saved in a variable on return | ||
// This allows the usage of element.removeEventListener | ||
function hasElement(elements, element) { | ||
return -1 !== indexOfElement(elements, element); | ||
} | ||
return function pointCB(event) { | ||
function domListOf(arr) { | ||
event = event || window.event; // IE-ism | ||
object.target = event.target || event.srcElement || event.originalTarget; | ||
object.element = this; | ||
object.type = event.type; | ||
if (!arr) return []; | ||
// Support touch | ||
// http://www.creativebloq.com/javascript/make-your-site-work-touch-devices-51411644 | ||
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)]; | ||
} | ||
if (event.targetTouches) { | ||
object.x = event.targetTouches[0].clientX; | ||
object.y = event.targetTouches[0].clientY; | ||
object.pageX = event.pageX; | ||
object.pageY = event.pageY; | ||
} else { | ||
return index$1(arr, resolveElement); | ||
} | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
} | ||
// If pageX/Y aren't available and clientX/Y are, | ||
// calculate pageX/Y - logic taken from jQuery. | ||
// (This is to support old IE) | ||
// NOTE Hopefully this can be removed soon. | ||
function pushElements(elements, toAdd) { | ||
if (event.pageX === null && event.clientX !== null) { | ||
var eventDoc = event.target && event.target.ownerDocument || document; | ||
var doc = eventDoc.documentElement; | ||
var body = eventDoc.body; | ||
for (var i = 0; i < toAdd.length; i++) { | ||
if (!hasElement(elements, toAdd[i])) elements.push(toAdd[i]); | ||
} | ||
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; | ||
object.pageY = event.pageY; | ||
} | ||
return toAdd; | ||
} | ||
// pageX, and pageY change with page scroll | ||
// so we're not going to use those for x, and y. | ||
// NOTE Most browsers also alias clientX/Y with x/y | ||
// so that's something to consider down the road. | ||
function addElements(elements) { | ||
for (var _len2 = arguments.length, toAdd = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
toAdd[_key2 - 1] = arguments[_key2]; | ||
} | ||
object.x = event.clientX; | ||
object.y = event.clientY; | ||
} | ||
}; | ||
toAdd = toAdd.map(resolveElement); | ||
return pushElements(elements, toAdd); | ||
} | ||
//NOTE Remember accessibility, Aria roles, and labels. | ||
}; | ||
function removeElements(elements) { | ||
for (var _len3 = arguments.length, toRemove = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
toRemove[_key3 - 1] = arguments[_key3]; | ||
} | ||
function createWindowRect() { | ||
var props = { | ||
top: { value: 0, enumerable: true }, | ||
left: { value: 0, enumerable: true }, | ||
right: { value: window.innerWidth, enumerable: true }, | ||
bottom: { value: window.innerHeight, enumerable: true }, | ||
width: { value: window.innerWidth, enumerable: true }, | ||
height: { value: window.innerHeight, enumerable: true }, | ||
x: { value: 0, enumerable: true }, | ||
y: { value: 0, enumerable: true } | ||
}; | ||
return toRemove.map(resolveElement).reduce(function (last, e) { | ||
if (Object.create) { | ||
return Object.create({}, props); | ||
} else { | ||
var rect = {}; | ||
Object.defineProperties(rect, props); | ||
return rect; | ||
} | ||
} | ||
var index = indexOfElement(elements, e); | ||
function getClientRect(el) { | ||
if (el === window) { | ||
return createWindowRect(); | ||
} else { | ||
try { | ||
var rect = el.getBoundingClientRect(); | ||
if (rect.x === undefined) { | ||
rext.x = rect.left; | ||
rect.y = rect.top; | ||
} | ||
return rect; | ||
} catch (e) { | ||
throw new TypeError("Can't call getBoundingClientRect on " + el); | ||
} | ||
} | ||
} | ||
if (index !== -1) return last.concat(elements.splice(index, 1)); | ||
return last; | ||
}, []); | ||
} | ||
function pointInside(point, el) { | ||
var rect = getClientRect(el); | ||
return point.y > rect.top && point.y < rect.bottom && point.x > rect.left && point.x < rect.right; | ||
} | ||
function resolveElement(element, noThrow) { | ||
if (typeof element === 'string') { | ||
try { | ||
return document.querySelector(element); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
function AutoScroller(elements) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!isElement(element) && !noThrow) { | ||
throw new TypeError(element + ' is not a DOM element.'); | ||
} | ||
return element; | ||
} | ||
var self = this; | ||
var maxSpeed = 4, | ||
scrolling = false; | ||
var index$3 = function createPointCB(object, options) { | ||
this.margin = options.margin || -1; | ||
//this.scrolling = false; | ||
this.scrollWhenOutside = options.scrollWhenOutside || false; | ||
// A persistent object (as opposed to returned object) is used to save memory | ||
// This is good to prevent layout thrashing, or for games, and such | ||
var point = {}, | ||
pointCB = index$2(point), | ||
down = false; | ||
// NOTE | ||
// This uses IE fixes which should be OK to remove some day. :) | ||
// Some speed will be gained by removal of these. | ||
window.addEventListener('mousemove', pointCB, false); | ||
window.addEventListener('touchmove', pointCB, false); | ||
// pointCB should be saved in a variable on return | ||
// This allows the usage of element.removeEventListener | ||
if (!isNaN(options.maxSpeed)) { | ||
maxSpeed = options.maxSpeed; | ||
} | ||
options = options || {}; | ||
this.autoScroll = boolean(options.autoScroll); | ||
var allowUpdate; | ||
this.destroy = function () { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
window.removeEventListener('touchmove', pointCB, false); | ||
window.removeEventListener('mousedown', onDown, false); | ||
window.removeEventListener('touchstart', onDown, false); | ||
window.removeEventListener('mouseup', onUp, false); | ||
window.removeEventListener('touchend', onUp, false); | ||
if (typeof options.allowUpdate === 'function') { | ||
allowUpdate = options.allowUpdate; | ||
} else { | ||
allowUpdate = function () { | ||
return true; | ||
}; | ||
} | ||
window.removeEventListener('scroll', setScroll, true); | ||
elements = []; | ||
}; | ||
return function pointCB(event) { | ||
this.add = function () { | ||
for (var _len = arguments.length, element = Array(_len), _key = 0; _key < _len; _key++) { | ||
element[_key] = arguments[_key]; | ||
} | ||
event = event || window.event; // IE-ism | ||
object.target = event.target || event.srcElement || event.originalTarget; | ||
object.element = this; | ||
object.type = event.type; | ||
addElements.apply(undefined, [elements].concat(element)); | ||
return this; | ||
}; | ||
if (!allowUpdate(event)) { | ||
return; | ||
} | ||
this.remove = function () { | ||
for (var _len2 = arguments.length, element = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
element[_key2] = arguments[_key2]; | ||
} | ||
// Support touch | ||
// http://www.creativebloq.com/javascript/make-your-site-work-touch-devices-51411644 | ||
return removeElements.apply(undefined, [elements].concat(element)); | ||
}; | ||
if (event.targetTouches) { | ||
object.x = event.targetTouches[0].clientX; | ||
object.y = event.targetTouches[0].clientY; | ||
object.pageX = event.pageX; | ||
object.pageY = event.pageY; | ||
} else { | ||
var hasWindow = null, | ||
windowAnimationFrame = void 0; | ||
// If pageX/Y aren't available and clientX/Y are, | ||
// calculate pageX/Y - logic taken from jQuery. | ||
// (This is to support old IE) | ||
// NOTE Hopefully this can be removed soon. | ||
if (Object.prototype.toString.call(elements) !== '[object Array]') { | ||
elements = [elements]; | ||
} | ||
if (event.pageX === null && event.clientX !== null) { | ||
var eventDoc = event.target && event.target.ownerDocument || document; | ||
var doc = eventDoc.documentElement; | ||
var body = eventDoc.body; | ||
(function (temp) { | ||
elements = []; | ||
temp.forEach(function (element) { | ||
if (element === window) { | ||
hasWindow = window; | ||
} else { | ||
self.add(element); | ||
} | ||
}); | ||
})(elements); | ||
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; | ||
object.pageY = event.pageY; | ||
} | ||
Object.defineProperties(this, { | ||
down: { | ||
get: function get() { | ||
return down; | ||
} | ||
}, | ||
maxSpeed: { | ||
get: function get() { | ||
return maxSpeed; | ||
} | ||
}, | ||
point: { | ||
get: function get() { | ||
return point; | ||
} | ||
}, | ||
scrolling: { | ||
get: function get() { | ||
return scrolling; | ||
} | ||
} | ||
}); | ||
// pageX, and pageY change with page scroll | ||
// so we're not going to use those for x, and y. | ||
// NOTE Most browsers also alias clientX/Y with x/y | ||
// so that's something to consider down the road. | ||
var n = 0, | ||
current = null, | ||
animationFrame = void 0; | ||
object.x = event.clientX; | ||
object.y = event.clientY; | ||
} | ||
}; | ||
window.addEventListener('mousedown', onDown, false); | ||
window.addEventListener('touchstart', onDown, false); | ||
window.addEventListener('mouseup', onUp, false); | ||
window.addEventListener('touchend', onUp, false); | ||
//NOTE Remember accessibility, Aria roles, and labels. | ||
}; | ||
window.addEventListener('mousemove', onMove, false); | ||
window.addEventListener('touchmove', onMove, false); | ||
function createWindowRect() { | ||
var props = { | ||
top: { value: 0, enumerable: true }, | ||
left: { value: 0, enumerable: true }, | ||
right: { value: window.innerWidth, enumerable: true }, | ||
bottom: { value: window.innerHeight, enumerable: true }, | ||
width: { value: window.innerWidth, enumerable: true }, | ||
height: { value: window.innerHeight, enumerable: true }, | ||
x: { value: 0, enumerable: true }, | ||
y: { value: 0, enumerable: true } | ||
}; | ||
window.addEventListener('mouseleave', onMouseOut, false); | ||
if (Object.create) { | ||
return Object.create({}, props); | ||
} else { | ||
var rect = {}; | ||
Object.defineProperties(rect, props); | ||
return rect; | ||
} | ||
} | ||
window.addEventListener('scroll', setScroll, true); | ||
function getClientRect(el) { | ||
if (el === window) { | ||
return createWindowRect(); | ||
} else { | ||
try { | ||
var rect = el.getBoundingClientRect(); | ||
if (rect.x === undefined) { | ||
rext.x = rect.left; | ||
rect.y = rect.top; | ||
} | ||
return rect; | ||
} catch (e) { | ||
throw new TypeError("Can't call getBoundingClientRect on " + el); | ||
} | ||
} | ||
} | ||
function setScroll(e) { | ||
function pointInside(point, el) { | ||
var rect = getClientRect(el); | ||
return point.y > rect.top && point.y < rect.bottom && point.x > rect.left && point.x < rect.right; | ||
} | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === e.target) { | ||
scrolling = true; | ||
break; | ||
} | ||
} | ||
function AutoScroller(elements) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (scrolling) { | ||
requestAnimationFrame(function () { | ||
return scrolling = false; | ||
}); | ||
} | ||
} | ||
var self = this; | ||
var maxSpeed = 4, | ||
scrolling = false; | ||
function onDown() { | ||
down = true; | ||
} | ||
this.margin = options.margin || -1; | ||
//this.scrolling = false; | ||
this.scrollWhenOutside = options.scrollWhenOutside || false; | ||
function onUp() { | ||
down = false; | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
} | ||
var point = {}, | ||
pointCB = index$3(point), | ||
down = false; | ||
function onMouseOut() { | ||
down = false; | ||
} | ||
window.addEventListener('mousemove', pointCB, false); | ||
window.addEventListener('touchmove', pointCB, false); | ||
function getTarget(target) { | ||
if (!target) { | ||
return null; | ||
} | ||
if (!isNaN(options.maxSpeed)) { | ||
maxSpeed = options.maxSpeed; | ||
} | ||
if (current === target) { | ||
return target; | ||
} | ||
this.autoScroll = boolean(options.autoScroll); | ||
if (hasElement(elements, target)) { | ||
return target; | ||
} | ||
this.destroy = function () { | ||
window.removeEventListener('mousemove', pointCB, false); | ||
window.removeEventListener('touchmove', pointCB, false); | ||
window.removeEventListener('mousedown', onDown, false); | ||
window.removeEventListener('touchstart', onDown, false); | ||
window.removeEventListener('mouseup', onUp, false); | ||
window.removeEventListener('touchend', onUp, false); | ||
while (target = target.parentNode) { | ||
if (hasElement(elements, target)) { | ||
return target; | ||
} | ||
} | ||
window.removeEventListener('scroll', setScroll, true); | ||
elements = []; | ||
}; | ||
return null; | ||
} | ||
this.add = function () { | ||
for (var _len = arguments.length, element = Array(_len), _key = 0; _key < _len; _key++) { | ||
element[_key] = arguments[_key]; | ||
} | ||
function getElementUnderPoint() { | ||
var underPoint = null; | ||
addElements.apply(undefined, [elements].concat(element)); | ||
return this; | ||
}; | ||
for (var i = 0; i < elements.length; i++) { | ||
if (inside(point, elements[i])) { | ||
underPoint = elements[i]; | ||
} | ||
} | ||
this.remove = function () { | ||
for (var _len2 = arguments.length, element = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
element[_key2] = arguments[_key2]; | ||
} | ||
return underPoint; | ||
} | ||
return removeElements.apply(undefined, [elements].concat(element)); | ||
}; | ||
function onMove(event) { | ||
var hasWindow = null, | ||
windowAnimationFrame = void 0; | ||
if (!self.autoScroll()) return; | ||
var target = event.target, | ||
body = document.body; | ||
if (Object.prototype.toString.call(elements) !== '[object Array]') { | ||
elements = [elements]; | ||
} | ||
if (current && !inside(point, current)) { | ||
if (!self.scrollWhenOutside) { | ||
current = null; | ||
} | ||
} | ||
(function (temp) { | ||
elements = []; | ||
temp.forEach(function (element) { | ||
if (element === window) { | ||
hasWindow = window; | ||
} else { | ||
self.add(element); | ||
} | ||
}); | ||
})(elements); | ||
if (target && target.parentNode === body) { | ||
//The special condition to improve speed. | ||
target = getElementUnderPoint(); | ||
} else { | ||
target = getTarget(target); | ||
Object.defineProperties(this, { | ||
down: { | ||
get: function get() { | ||
return down; | ||
} | ||
}, | ||
maxSpeed: { | ||
get: function get() { | ||
return maxSpeed; | ||
} | ||
}, | ||
point: { | ||
get: function get() { | ||
return point; | ||
} | ||
}, | ||
scrolling: { | ||
get: function get() { | ||
return scrolling; | ||
} | ||
} | ||
}); | ||
if (!target) { | ||
target = getElementUnderPoint(); | ||
} | ||
} | ||
var n = 0, | ||
current = null, | ||
animationFrame = void 0; | ||
if (target && target !== current) { | ||
current = target; | ||
} | ||
window.addEventListener('mousedown', onDown, false); | ||
window.addEventListener('touchstart', onDown, false); | ||
window.addEventListener('mouseup', onUp, false); | ||
window.addEventListener('touchend', onUp, false); | ||
if (hasWindow) { | ||
cancelAnimationFrame(windowAnimationFrame); | ||
windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
} | ||
window.addEventListener('mousemove', onMove, false); | ||
window.addEventListener('touchmove', onMove, false); | ||
if (!current) { | ||
return; | ||
} | ||
window.addEventListener('mouseleave', onMouseOut, false); | ||
cancelAnimationFrame(animationFrame); | ||
animationFrame = requestAnimationFrame(scrollTick); | ||
} | ||
window.addEventListener('scroll', setScroll, true); | ||
function scrollWindow() { | ||
autoScroll(hasWindow); | ||
function setScroll(e) { | ||
cancelAnimationFrame(windowAnimationFrame); | ||
windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
} | ||
for (var i = 0; i < elements.length; i++) { | ||
if (elements[i] === e.target) { | ||
scrolling = true; | ||
break; | ||
} | ||
} | ||
function scrollTick() { | ||
if (scrolling) { | ||
requestAnimationFrame(function () { | ||
return scrolling = false; | ||
}); | ||
} | ||
} | ||
if (!current) { | ||
return; | ||
} | ||
function onDown() { | ||
down = true; | ||
} | ||
autoScroll(current); | ||
function onUp() { | ||
down = false; | ||
cancelAnimationFrame(animationFrame); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
} | ||
cancelAnimationFrame(animationFrame); | ||
animationFrame = requestAnimationFrame(scrollTick); | ||
} | ||
function onMouseOut() { | ||
down = false; | ||
} | ||
function autoScroll(el) { | ||
var rect = getClientRect(el), | ||
scrollx = void 0, | ||
scrolly = void 0; | ||
function getTarget(target) { | ||
if (!target) { | ||
return null; | ||
} | ||
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 (current === target) { | ||
return target; | ||
} | ||
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 (hasElement(elements, target)) { | ||
return target; | ||
} | ||
setTimeout(function () { | ||
while (target = target.parentNode) { | ||
if (hasElement(elements, target)) { | ||
return target; | ||
} | ||
} | ||
if (scrolly) { | ||
scrollY(el, scrolly); | ||
} | ||
return null; | ||
} | ||
if (scrollx) { | ||
scrollX(el, scrollx); | ||
} | ||
}); | ||
} | ||
function getElementUnderPoint() { | ||
var underPoint = null; | ||
function scrollY(el, amount) { | ||
if (el === window) { | ||
window.scrollTo(el.pageXOffset, el.pageYOffset + amount); | ||
} else { | ||
el.scrollTop += amount; | ||
} | ||
} | ||
for (var i = 0; i < elements.length; i++) { | ||
if (inside(point, elements[i])) { | ||
underPoint = elements[i]; | ||
} | ||
} | ||
function scrollX(el, amount) { | ||
if (el === window) { | ||
window.scrollTo(el.pageXOffset + amount, el.pageYOffset); | ||
} else { | ||
el.scrollLeft += amount; | ||
} | ||
} | ||
} | ||
return underPoint; | ||
} | ||
function AutoScrollerFactory(element, options) { | ||
return new AutoScroller(element, options); | ||
} | ||
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; | ||
} | ||
} | ||
function onMove(event) { | ||
/* | ||
git remote add origin https://github.com/hollowdoor/dom_autoscroller.git | ||
git push -u origin master | ||
*/ | ||
if (!self.autoScroll()) return; | ||
var target = event.target, | ||
body = document.body; | ||
return AutoScrollerFactory; | ||
if (current && !inside(point, current)) { | ||
if (!self.scrollWhenOutside) { | ||
current = null; | ||
} | ||
} | ||
if (target && target.parentNode === body) { | ||
//The special condition to improve speed. | ||
target = getElementUnderPoint(); | ||
} else { | ||
target = getTarget(target); | ||
if (!target) { | ||
target = getElementUnderPoint(); | ||
} | ||
} | ||
if (target && target !== current) { | ||
current = target; | ||
} | ||
if (hasWindow) { | ||
cancelAnimationFrame(windowAnimationFrame); | ||
windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
} | ||
if (!current) { | ||
return; | ||
} | ||
cancelAnimationFrame(animationFrame); | ||
animationFrame = requestAnimationFrame(scrollTick); | ||
} | ||
function scrollWindow() { | ||
autoScroll(hasWindow); | ||
cancelAnimationFrame(windowAnimationFrame); | ||
windowAnimationFrame = requestAnimationFrame(scrollWindow); | ||
} | ||
function scrollTick() { | ||
if (!current) { | ||
return; | ||
} | ||
autoScroll(current); | ||
cancelAnimationFrame(animationFrame); | ||
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 { | ||
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 { | ||
scrolly = 0; | ||
} | ||
setTimeout(function () { | ||
if (scrolly) { | ||
scrollY(el, scrolly); | ||
} | ||
if (scrollx) { | ||
scrollX(el, scrollx); | ||
} | ||
}); | ||
} | ||
function scrollY(el, amount) { | ||
if (el === window) { | ||
window.scrollTo(el.pageXOffset, el.pageYOffset + amount); | ||
} else { | ||
el.scrollTop += amount; | ||
} | ||
} | ||
function scrollX(el, amount) { | ||
if (el === window) { | ||
window.scrollTo(el.pageXOffset + amount, el.pageYOffset); | ||
} else { | ||
el.scrollLeft += amount; | ||
} | ||
} | ||
} | ||
function AutoScrollerFactory(element, options) { | ||
return new AutoScroller(element, options); | ||
} | ||
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; | ||
} | ||
} | ||
/* | ||
git remote add origin https://github.com/hollowdoor/dom_autoscroller.git | ||
git push -u origin master | ||
*/ | ||
return AutoScrollerFactory; | ||
}()); | ||
//# sourceMappingURL=dom-autoscroller.js.map |
@@ -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),o=0;o<e;o++)t[o]=arguments[o];return!!n.apply(this,t)}:n?function(){return!0}:function(){return!1}}function t(e){return null!=e&&"object"===("undefined"==typeof e?"undefined":h(e))&&1===e.nodeType&&"object"===h(e.style)&&"object"===h(e.ownerDocument)}function o(e,n){if(n=c(n,!0),!t(n))return-1;for(var o=0;o<e.length;o++)if(e[o]===n)return o;return-1}function r(e,n){return-1!==o(e,n)}function i(e,n){for(var t=0;t<n.length;t++)r(e,n[t])||e.push(n[t]);return n}function a(e){for(var n=arguments.length,t=Array(n>1?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];return t=t.map(c),i(e,t)}function u(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.map(c).reduce(function(n,t){var r=o(e,t);return r!==-1?n.concat(e.splice(r,1)):n},[])}function c(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 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 d(e){if(e===window)return l();try{var n=e.getBoundingClientRect();return void 0===n.x&&(rext.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=d(n);return e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right}function m(e){function t(n){for(var t=0;t<e.length;t++)if(e[t]===n.target){T=!0;break}T&&g(function(){return T=!1})}function o(){O=!0}function i(){O=!1,p(j),p(M)}function c(){O=!1}function l(n){if(!n)return null;if(Y===n)return n;if(r(e,n))return n;for(;n=n.parentNode;)if(r(e,n))return n;return null}function f(){for(var n=null,t=0;t<e.length;t++)s(S,e[t])&&(n=e[t]);return n}function m(e){if(L.autoScroll()){var n=e.target,t=document.body;Y&&!s(S,Y)&&(L.scrollWhenOutside||(Y=null)),n&&n.parentNode===t?n=f():(n=l(n),n||(n=f())),n&&n!==Y&&(Y=n),X&&(p(M),M=g(w)),Y&&(p(j),j=g(v))}}function w(){h(X),p(M),M=g(w)}function v(){Y&&(h(Y),p(j),j=g(v))}function h(e){var n=d(e),t=void 0,o=void 0;t=S.x<n.left+L.margin?Math.floor(Math.max(-1,(S.x-n.left)/L.margin-1)*L.maxSpeed):S.x>n.right-L.margin?Math.ceil(Math.min(1,(S.x-n.right)/L.margin+1)*L.maxSpeed):0,o=S.y<n.top+L.margin?Math.floor(Math.max(-1,(S.y-n.top)/L.margin-1)*L.maxSpeed):S.y>n.bottom-L.margin?Math.ceil(Math.min(1,(S.y-n.bottom)/L.margin+1)*L.maxSpeed):0,setTimeout(function(){o&&b(e,o),t&&x(e,t)})}function b(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}var E=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},L=this,A=4,T=!1;this.margin=E.margin||-1,this.scrollWhenOutside=E.scrollWhenOutside||!1;var S={},F=y(S),O=!1;window.addEventListener("mousemove",F,!1),window.addEventListener("touchmove",F,!1),isNaN(E.maxSpeed)||(A=E.maxSpeed),this.autoScroll=n(E.autoScroll),this.destroy=function(){window.removeEventListener("mousemove",F,!1),window.removeEventListener("touchmove",F,!1),window.removeEventListener("mousedown",o,!1),window.removeEventListener("touchstart",o,!1),window.removeEventListener("mouseup",i,!1),window.removeEventListener("touchend",i,!1),window.removeEventListener("scroll",t,!0),e=[]},this.add=function(){for(var n=arguments.length,t=Array(n),o=0;o<n;o++)t[o]=arguments[o];return a.apply(void 0,[e].concat(t)),this},this.remove=function(){for(var n=arguments.length,t=Array(n),o=0;o<n;o++)t[o]=arguments[o];return u.apply(void 0,[e].concat(t))};var X=null,M=void 0;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(n){e=[],n.forEach(function(e){e===window?X=window:L.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return O}},maxSpeed:{get:function(){return A}},point:{get:function(){return S}},scrolling:{get:function(){return T}}});var Y=null,j=void 0;window.addEventListener("mousedown",o,!1),window.addEventListener("touchstart",o,!1),window.addEventListener("mouseup",i,!1),window.addEventListener("touchend",i,!1),window.addEventListener("mousemove",m,!1),window.addEventListener("touchmove",m,!1),window.addEventListener("mouseleave",c,!1),window.addEventListener("scroll",t,!0)}function w(e,n){return new m(e,n)}function s(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 v=["webkit","moz","ms","o"],g=function(){for(var e=0,n=v.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[v[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)}(),p=function(){for(var e=0,n=v.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[v[e]+"CancelAnimationFrame"]||window[v[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}(),h="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},y=function(e){return function(n){if(n=n||window.event,e.target=n.target||n.srcElement||n.originalTarget,e.element=this,e.type=n.type,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 t=n.target&&n.target.ownerDocument||document,o=t.documentElement,r=t.body;e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)}else e.pageX=n.pageX,e.pageY=n.pageY;e.x=n.clientX,e.y=n.clientY}}};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.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),!y(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(!y(e)&&!n)throw new TypeError(e+" is not a DOM element.");return e}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 c(e){if(e===window)return l();try{var n=e.getBoundingClientRect();return void 0===n.x&&(rext.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=c(n);return e.y>t.top&&e.y<t.bottom&&e.x>t.left&&e.x<t.right}function d(e){function t(n){for(var t=0;t<e.length;t++)if(e[t]===n.target){L=!0;break}L&&v(function(){return L=!1})}function o(){j=!0}function u(){j=!1,p(q),p(F)}function l(){j=!1}function f(n){if(!n)return null;if(X===n)return n;if(r(e,n))return n;for(;n=n.parentNode;)if(r(e,n))return n;return null}function d(){for(var n=null,t=0;t<e.length;t++)w(T,e[t])&&(n=e[t]);return n}function m(e){if(E.autoScroll()){var n=e.target,t=document.body;X&&!w(T,X)&&(E.scrollWhenOutside||(X=null)),n&&n.parentNode===t?n=d():(n=f(n),n||(n=d())),n&&n!==X&&(X=n),M&&(p(F),F=v(s)),X&&(p(q),q=v(h))}}function s(){y(M),p(F),F=v(s)}function h(){X&&(y(X),p(q),q=v(h))}function y(e){var n=c(e),t=void 0,r=void 0;t=T.x<n.left+E.margin?Math.floor(Math.max(-1,(T.x-n.left)/E.margin-1)*E.maxSpeed):T.x>n.right-E.margin?Math.ceil(Math.min(1,(T.x-n.right)/E.margin+1)*E.maxSpeed):0,r=T.y<n.top+E.margin?Math.floor(Math.max(-1,(T.y-n.top)/E.margin-1)*E.maxSpeed):T.y>n.bottom-E.margin?Math.ceil(Math.min(1,(T.y-n.bottom)/E.margin+1)*E.maxSpeed):0,setTimeout(function(){r&&g(e,r),t&&x(e,t)})}function g(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}var A=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},E=this,S=4,L=!1;this.margin=A.margin||-1,this.scrollWhenOutside=A.scrollWhenOutside||!1;var T={},O=b(T),j=!1;window.addEventListener("mousemove",O,!1),window.addEventListener("touchmove",O,!1),isNaN(A.maxSpeed)||(S=A.maxSpeed),this.autoScroll=n(A.autoScroll),this.destroy=function(){window.removeEventListener("mousemove",O,!1),window.removeEventListener("touchmove",O,!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 M=null,F=void 0;"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),function(n){e=[],n.forEach(function(e){e===window?M=window:E.add(e)})}(e),Object.defineProperties(this,{down:{get:function(){return j}},maxSpeed:{get:function(){return S}},point:{get:function(){return T}},scrolling:{get:function(){return L}}});var X=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",m,!1),window.addEventListener("touchmove",m,!1),window.addEventListener("mouseleave",l,!1),window.addEventListener("scroll",t,!0)}function m(e,n){return new d(e,n)}function w(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 s=["webkit","moz","ms","o"],v=function(){for(var e=0,n=s.length;e<n&&!window.requestAnimationFrame;++e)window.requestAnimationFrame=window[s[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)}(),p=function(){for(var e=0,n=s.length;e<n&&!window.cancelAnimationFrame;++e)window.cancelAnimationFrame=window[s[e]+"CancelAnimationFrame"]||window[s[e]+"CancelRequestAnimationFrame"];return window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){window.clearTimeout(e)}),window.cancelAnimationFrame.bind(window)}(),h="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},y=function(e){return null!=e&&"object"===("undefined"==typeof e?"undefined":h(e))&&1===e.nodeType&&"object"===h(e.style)&&"object"===h(e.ownerDocument)},g=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,l=arguments.length>1?arguments[1]:void 0;if("undefined"!=typeof l){if(!e(l))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(t=arguments[2])}var c,f,d=i(n,o(n));if(void 0!==d){c=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 w,s;;){if(w=a(m),!w)return c.length=f,c;s=w.value,l?c[f]=l.call(t,s,f):c[f]=s,f++}}else{var v=Object(n);if(null==n)throw new TypeError("Array.from requires an array-like object - not null or undefined");var p=r(v.length);c=e(u)?Object(new u(p)):new Array(p),f=0;for(var h;f<p;)h=v[f],l?c[f]=l.call(t,h,f):c[f]=h,f++;c.length=p}return c}}(),b=("function"==typeof Array.from?Array.from:g,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}}});return m}(); |
{ | ||
"name": "dom-autoscroller", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Auto scroll dom elements", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
Sorry, the diff of this file is not supported yet
127847
1173