134 lines
16 KiB
JavaScript
134 lines
16 KiB
JavaScript
|
let scrollSensitivity;
|
||
|
let scrollSpeed;
|
||
|
const intervalDuration = 50;
|
||
|
let gridsterElement;
|
||
|
let resizeEvent;
|
||
|
let resizeEventType;
|
||
|
let intervalE;
|
||
|
let intervalW;
|
||
|
let intervalN;
|
||
|
let intervalS;
|
||
|
export function scroll(gridster, left, top, width, height, event, lastMouse, calculateItemPosition, resize, resizeEventScrollType) {
|
||
|
scrollSensitivity = gridster.$options.scrollSensitivity;
|
||
|
scrollSpeed = gridster.$options.scrollSpeed;
|
||
|
gridsterElement = gridster.el;
|
||
|
resizeEvent = resize;
|
||
|
resizeEventType = resizeEventScrollType;
|
||
|
const offsetWidth = gridsterElement.offsetWidth;
|
||
|
const offsetHeight = gridsterElement.offsetHeight;
|
||
|
const offsetLeft = gridsterElement.scrollLeft;
|
||
|
const offsetTop = gridsterElement.scrollTop;
|
||
|
const elemTopOffset = top - offsetTop;
|
||
|
const elemBottomOffset = offsetHeight + offsetTop - top - height;
|
||
|
const { clientX, clientY } = event;
|
||
|
if (!gridster.$options.disableScrollVertical) {
|
||
|
if (lastMouse.clientY < clientY && elemBottomOffset < scrollSensitivity) {
|
||
|
cancelN();
|
||
|
if ((resizeEvent && resizeEventType && !resizeEventType.south) ||
|
||
|
intervalS) {
|
||
|
return;
|
||
|
}
|
||
|
intervalS = startVertical(1, calculateItemPosition, lastMouse);
|
||
|
}
|
||
|
else if (lastMouse.clientY > clientY &&
|
||
|
offsetTop > 0 &&
|
||
|
elemTopOffset < scrollSensitivity) {
|
||
|
cancelS();
|
||
|
if ((resizeEvent && resizeEventType && !resizeEventType.north) ||
|
||
|
intervalN) {
|
||
|
return;
|
||
|
}
|
||
|
intervalN = startVertical(-1, calculateItemPosition, lastMouse);
|
||
|
}
|
||
|
else if (lastMouse.clientY !== clientY) {
|
||
|
cancelVertical();
|
||
|
}
|
||
|
}
|
||
|
const elemRightOffset = offsetLeft + offsetWidth - left - width;
|
||
|
const elemLeftOffset = left - offsetLeft;
|
||
|
if (!gridster.$options.disableScrollHorizontal) {
|
||
|
if (lastMouse.clientX < clientX && elemRightOffset <= scrollSensitivity) {
|
||
|
cancelW();
|
||
|
if ((resizeEvent && resizeEventType && !resizeEventType.east) ||
|
||
|
intervalE) {
|
||
|
return;
|
||
|
}
|
||
|
intervalE = startHorizontal(1, calculateItemPosition, lastMouse);
|
||
|
}
|
||
|
else if (lastMouse.clientX > clientX &&
|
||
|
offsetLeft > 0 &&
|
||
|
elemLeftOffset < scrollSensitivity) {
|
||
|
cancelE();
|
||
|
if ((resizeEvent && resizeEventType && !resizeEventType.west) ||
|
||
|
intervalW) {
|
||
|
return;
|
||
|
}
|
||
|
intervalW = startHorizontal(-1, calculateItemPosition, lastMouse);
|
||
|
}
|
||
|
else if (lastMouse.clientX !== clientX) {
|
||
|
cancelHorizontal();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
function startVertical(sign, calculateItemPosition, lastMouse) {
|
||
|
let clientY = lastMouse.clientY;
|
||
|
return window.setInterval(() => {
|
||
|
if (!gridsterElement ||
|
||
|
(sign === -1 && gridsterElement.scrollTop - scrollSpeed < 0)) {
|
||
|
cancelVertical();
|
||
|
}
|
||
|
gridsterElement.scrollTop += sign * scrollSpeed;
|
||
|
clientY += sign * scrollSpeed;
|
||
|
calculateItemPosition({ clientX: lastMouse.clientX, clientY });
|
||
|
}, intervalDuration);
|
||
|
}
|
||
|
function startHorizontal(sign, calculateItemPosition, lastMouse) {
|
||
|
let clientX = lastMouse.clientX;
|
||
|
return window.setInterval(() => {
|
||
|
if (!gridsterElement ||
|
||
|
(sign === -1 && gridsterElement.scrollLeft - scrollSpeed < 0)) {
|
||
|
cancelHorizontal();
|
||
|
}
|
||
|
gridsterElement.scrollLeft += sign * scrollSpeed;
|
||
|
clientX += sign * scrollSpeed;
|
||
|
calculateItemPosition({ clientX, clientY: lastMouse.clientY });
|
||
|
}, intervalDuration);
|
||
|
}
|
||
|
export function cancelScroll() {
|
||
|
cancelHorizontal();
|
||
|
cancelVertical();
|
||
|
gridsterElement = null;
|
||
|
}
|
||
|
function cancelHorizontal() {
|
||
|
cancelE();
|
||
|
cancelW();
|
||
|
}
|
||
|
function cancelVertical() {
|
||
|
cancelN();
|
||
|
cancelS();
|
||
|
}
|
||
|
function cancelE() {
|
||
|
if (intervalE) {
|
||
|
clearInterval(intervalE);
|
||
|
intervalE = 0;
|
||
|
}
|
||
|
}
|
||
|
function cancelW() {
|
||
|
if (intervalW) {
|
||
|
clearInterval(intervalW);
|
||
|
intervalW = 0;
|
||
|
}
|
||
|
}
|
||
|
function cancelS() {
|
||
|
if (intervalS) {
|
||
|
clearInterval(intervalS);
|
||
|
intervalS = 0;
|
||
|
}
|
||
|
}
|
||
|
function cancelN() {
|
||
|
if (intervalN) {
|
||
|
clearInterval(intervalN);
|
||
|
intervalN = 0;
|
||
|
}
|
||
|
}
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZHN0ZXJTY3JvbGwuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL2FuZ3VsYXItZ3JpZHN0ZXIyL3NyYy9saWIvZ3JpZHN0ZXJTY3JvbGwuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxJQUFJLGlCQUF5QixDQUFDO0FBQzlCLElBQUksV0FBbUIsQ0FBQztBQUN4QixNQUFNLGdCQUFnQixHQUFHLEVBQUUsQ0FBQztBQUM1QixJQUFJLGVBQW1DLENBQUM7QUFDeEMsSUFBSSxXQUFnQyxDQUFDO0FBQ3JDLElBQUksZUFBb0QsQ0FBQztBQUN6RCxJQUFJLFNBQWlCLENBQUM7QUFDdEIsSUFBSSxTQUFpQixDQUFDO0FBQ3RCLElBQUksU0FBaUIsQ0FBQztBQUN0QixJQUFJLFNBQWlCLENBQUM7QUFNdEIsT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