2019-10-19 23:36:59 +03:00
|
|
|
define(["dom", "browser", "layoutManager"], function (dom, browser, layoutManager) {
|
|
|
|
"use strict";
|
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
/**
|
|
|
|
* Scroll time in ms.
|
|
|
|
*/
|
|
|
|
var ScrollTime = 270;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Epsilon for comparing values.
|
|
|
|
*/
|
|
|
|
var Epsilon = 1e-6;
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-10-19 23:36:59 +03:00
|
|
|
// FIXME: Need to scroll to top of page to fully show the top menu. This can be solved by some marker of top most elements or their containers
|
|
|
|
var _minimumScrollY = 0;
|
|
|
|
/**
|
|
|
|
* Returns minimum vertical scroll.
|
|
|
|
* Scroll less than that value will be zeroed.
|
|
|
|
*
|
|
|
|
* @return {number} minimum vertical scroll
|
|
|
|
*/
|
|
|
|
function minimumScrollY() {
|
|
|
|
if (_minimumScrollY === 0) {
|
|
|
|
var topMenu = document.querySelector(".headerTop");
|
|
|
|
if (topMenu) {
|
|
|
|
_minimumScrollY = topMenu.clientHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _minimumScrollY;
|
|
|
|
}
|
|
|
|
|
|
|
|
var supportsSmoothScroll = "scrollBehavior" in document.documentElement.style;
|
|
|
|
|
|
|
|
var supportsScrollToOptions = false;
|
|
|
|
try {
|
|
|
|
var elem = document.createElement("div");
|
|
|
|
|
|
|
|
var opts = Object.defineProperty({}, "behavior", {
|
|
|
|
get: function () {
|
|
|
|
supportsScrollToOptions = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
elem.scrollTo(opts);
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns value clamped by range [min, max].
|
|
|
|
*
|
|
|
|
* @param {number} value clamped value
|
|
|
|
* @param {number} min begining of range
|
|
|
|
* @param {number} max ending of range
|
|
|
|
* @return {number} clamped value
|
|
|
|
*/
|
|
|
|
function clamp(value, min, max) {
|
|
|
|
return value <= min ? min : value >= max ? max : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the required delta to fit range 1 into range 2.
|
|
|
|
* In case of range 1 is bigger than range 2 returns delta to fit most out of range part.
|
|
|
|
*
|
|
|
|
* @param {number} begin1 begining of range 1
|
|
|
|
* @param {number} end1 ending of range 1
|
|
|
|
* @param {number} begin2 begining of range 2
|
|
|
|
* @param {number} end2 ending of range 2
|
|
|
|
* @return {number} delta: <0 move range1 to the left, >0 - to the right
|
|
|
|
*/
|
|
|
|
function fitRange(begin1, end1, begin2, end2) {
|
|
|
|
var delta1 = begin1 - begin2;
|
|
|
|
var delta2 = end2 - end1;
|
|
|
|
if (delta1 < 0 && delta1 < delta2) {
|
|
|
|
return -delta1;
|
|
|
|
} else if (delta2 < 0) {
|
|
|
|
return delta2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
/**
|
|
|
|
* Ease value.
|
|
|
|
*
|
|
|
|
* @param {number} t value in range [0, 1]
|
|
|
|
* @return {number} eased value in range [0, 1]
|
|
|
|
*/
|
|
|
|
function ease(t) {
|
|
|
|
return t*(2 - t); // easeOutQuad === ease-out
|
|
|
|
}
|
|
|
|
|
2019-10-24 21:28:14 +03:00
|
|
|
/**
|
|
|
|
* Document scroll wrapper helps to unify scrolling and fix issues of some browsers.
|
|
|
|
*
|
|
|
|
* webOS 2 Browser: scrolls documentElement (and window), but body has a scroll size
|
|
|
|
*
|
|
|
|
* webOS 3 Browser: scrolls body (and window)
|
|
|
|
*
|
|
|
|
* webOS 4 Native: scrolls body (and window); has a document.scrollingElement
|
|
|
|
*
|
|
|
|
* Tizen 4 Browser/Native: scrolls body (and window); has a document.scrollingElement
|
|
|
|
*
|
|
|
|
* Tizen 5 Browser/Native: scrolls documentElement (and window); has a document.scrollingElement
|
|
|
|
*/
|
|
|
|
function DocumentScroller() {
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentScroller.prototype = {
|
|
|
|
get scrollLeft() {
|
|
|
|
return window.pageXOffset;
|
|
|
|
},
|
|
|
|
set scrollLeft(val) {
|
|
|
|
window.scroll(val, window.pageYOffset);
|
|
|
|
},
|
|
|
|
|
|
|
|
get scrollTop() {
|
|
|
|
return window.pageYOffset;
|
|
|
|
},
|
|
|
|
set scrollTop(val) {
|
|
|
|
window.scroll(window.pageXOffset, val);
|
|
|
|
},
|
|
|
|
|
|
|
|
get scrollWidth() {
|
|
|
|
return Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
|
|
|
|
},
|
|
|
|
|
|
|
|
get scrollHeight() {
|
|
|
|
return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
|
|
|
|
},
|
|
|
|
|
|
|
|
get clientWidth() {
|
|
|
|
return Math.min(document.documentElement.clientWidth, document.body.clientWidth);
|
|
|
|
},
|
|
|
|
|
|
|
|
get clientHeight() {
|
|
|
|
return Math.min(document.documentElement.clientHeight, document.body.clientHeight);
|
|
|
|
},
|
|
|
|
|
|
|
|
getBoundingClientRect: function() {
|
|
|
|
// Make valid viewport coordinates: documentElement.getBoundingClientRect returns rect of entire document relative to viewport
|
|
|
|
return {
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
width: this.clientWidth,
|
|
|
|
height: this.clientHeight
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollTo: function() {
|
|
|
|
window.scrollTo.apply(window, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var documentScroller = new DocumentScroller();
|
|
|
|
|
2019-10-19 23:36:59 +03:00
|
|
|
/**
|
|
|
|
* Returns parent element that can be scrolled. If no such, returns documentElement.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} element element for which parent is being searched
|
|
|
|
* @param {boolean} vertical search for vertical scrollable parent
|
|
|
|
*/
|
|
|
|
function getScrollableParent(element, vertical) {
|
|
|
|
if (element) {
|
|
|
|
var parent = element.parentElement;
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
if ((!vertical && parent.scrollWidth > parent.clientWidth && parent.classList.contains("scrollX")) ||
|
|
|
|
(vertical && parent.scrollHeight > parent.clientHeight) && parent.classList.contains("scrollY")) {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent.parentElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 21:28:14 +03:00
|
|
|
return documentScroller;
|
2019-10-19 23:36:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Object} ScrollerData
|
|
|
|
* @property {number} scrollPos current scroll position
|
|
|
|
* @property {number} scrollSize scroll size
|
|
|
|
* @property {number} clientSize client size
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns scroll data for specified orientation.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} scroller scroller
|
|
|
|
* @param {boolean} vertical vertical scroll data
|
|
|
|
* @return {ScrollerData} scroll data
|
|
|
|
*/
|
|
|
|
function getScrollerData(scroller, vertical) {
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
if (!vertical) {
|
|
|
|
data.scrollPos = scroller.scrollLeft;
|
|
|
|
data.scrollSize = scroller.scrollWidth;
|
|
|
|
data.clientSize = scroller.clientWidth;
|
|
|
|
} else {
|
|
|
|
data.scrollPos = scroller.scrollTop;
|
|
|
|
data.scrollSize = scroller.scrollHeight;
|
|
|
|
data.clientSize = scroller.clientHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns position of child of scroller for specified orientation.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} scroller scroller
|
|
|
|
* @param {HTMLElement} element child of scroller
|
|
|
|
* @param {boolean} vertical vertical scroll
|
|
|
|
* @return {number} child position
|
|
|
|
*/
|
|
|
|
function getScrollerChildPos(scroller, element, vertical) {
|
|
|
|
var elementRect = element.getBoundingClientRect();
|
|
|
|
var scrollerRect = scroller.getBoundingClientRect();
|
|
|
|
|
|
|
|
if (!vertical) {
|
2019-10-24 21:28:14 +03:00
|
|
|
return scroller.scrollLeft + elementRect.left - scrollerRect.left;
|
2019-10-19 23:36:59 +03:00
|
|
|
} else {
|
2019-10-24 21:28:14 +03:00
|
|
|
return scroller.scrollTop + elementRect.top - scrollerRect.top;
|
2019-10-19 23:36:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns scroll position for element.
|
|
|
|
*
|
|
|
|
* @param {ScrollerData} scrollerData scroller data
|
|
|
|
* @param {number} elementPos child element position
|
|
|
|
* @param {number} elementSize child element size
|
|
|
|
* @param {boolean} centered scroll to center
|
|
|
|
* @return {number} scroll position
|
|
|
|
*/
|
|
|
|
function calcScroll(scrollerData, elementPos, elementSize, centered) {
|
|
|
|
var maxScroll = scrollerData.scrollSize - scrollerData.clientSize;
|
|
|
|
|
|
|
|
var scroll;
|
|
|
|
|
|
|
|
if (centered) {
|
|
|
|
scroll = elementPos + (elementSize - scrollerData.clientSize) / 2;
|
|
|
|
} else {
|
|
|
|
var delta = fitRange(elementPos, elementPos + elementSize - 1, scrollerData.scrollPos, scrollerData.scrollPos + scrollerData.clientSize - 1);
|
|
|
|
scroll = scrollerData.scrollPos - delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
return clamp(Math.round(scroll), 0, maxScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls scrollTo function in proper way.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} scroller scroller
|
|
|
|
* @param {ScrollToOptions} options scroll options
|
|
|
|
*/
|
|
|
|
function scrollToHelper(scroller, options) {
|
|
|
|
if ("scrollTo" in scroller) {
|
|
|
|
if (!supportsScrollToOptions) {
|
|
|
|
var scrollX = (options.left !== undefined ? options.left : scroller.scrollLeft);
|
|
|
|
var scrollY = (options.top !== undefined ? options.top : scroller.scrollTop);
|
|
|
|
scroller.scrollTo(scrollX, scrollY);
|
|
|
|
} else {
|
|
|
|
scroller.scrollTo(options);
|
|
|
|
}
|
|
|
|
} else if ("scrollLeft" in scroller) {
|
|
|
|
if (options.left !== undefined) {
|
|
|
|
scroller.scrollLeft = options.left;
|
|
|
|
}
|
|
|
|
if (options.top !== undefined) {
|
|
|
|
scroller.scrollTop = options.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 22:35:45 +03:00
|
|
|
/**
|
|
|
|
* Performs built-in scroll.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} xScroller horizontal scroller
|
|
|
|
* @param {number} scrollX horizontal coordinate
|
|
|
|
* @param {HTMLElement} yScroller vertical scroller
|
|
|
|
* @param {number} scrollY vertical coordinate
|
|
|
|
* @param {boolean} smooth smooth scrolling
|
|
|
|
*/
|
|
|
|
function builtinScroll(xScroller, scrollX, yScroller, scrollY, smooth) {
|
|
|
|
var scrollBehavior = smooth ? "smooth" : "instant";
|
|
|
|
|
|
|
|
if (xScroller !== yScroller) {
|
|
|
|
scrollToHelper(xScroller, {left: scrollX, behavior: scrollBehavior});
|
|
|
|
scrollToHelper(yScroller, {top: scrollY, behavior: scrollBehavior});
|
|
|
|
} else {
|
|
|
|
scrollToHelper(xScroller, {left: scrollX, top: scrollY, behavior: scrollBehavior});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-20 14:53:12 +03:00
|
|
|
var scrollTimer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets scroll timer to stop scrolling.
|
|
|
|
*/
|
|
|
|
function resetScrollTimer() {
|
|
|
|
cancelAnimationFrame(scrollTimer);
|
|
|
|
scrollTimer = undefined;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:36:59 +03:00
|
|
|
/**
|
2019-10-22 22:19:43 +03:00
|
|
|
* Performs animated scroll.
|
2019-10-19 23:36:59 +03:00
|
|
|
*
|
|
|
|
* @param {HTMLElement} xScroller horizontal scroller
|
|
|
|
* @param {number} scrollX horizontal coordinate
|
|
|
|
* @param {HTMLElement} yScroller vertical scroller
|
|
|
|
* @param {number} scrollY vertical coordinate
|
|
|
|
*/
|
2019-10-22 22:19:43 +03:00
|
|
|
function animateScroll(xScroller, scrollX, yScroller, scrollY) {
|
2019-11-10 23:36:04 +03:00
|
|
|
|
|
|
|
var ox = xScroller.scrollLeft;
|
|
|
|
var oy = yScroller.scrollTop;
|
|
|
|
var dx = scrollX - ox;
|
|
|
|
var dy = scrollY - oy;
|
|
|
|
|
|
|
|
if (Math.abs(dx) < Epsilon && Math.abs(dy) < Epsilon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
var start;
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
function scrollAnim(currentTimestamp) {
|
2019-11-10 23:36:04 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
start = start || currentTimestamp;
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
var k = Math.min(1, (currentTimestamp - start) / ScrollTime);
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
if (k === 1) {
|
2019-10-22 22:19:43 +03:00
|
|
|
resetScrollTimer();
|
|
|
|
xScroller.scrollLeft = scrollX;
|
|
|
|
yScroller.scrollTop = scrollY;
|
|
|
|
return;
|
|
|
|
}
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
k = ease(k);
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
var x = ox + dx*k;
|
|
|
|
var y = oy + dy*k;
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-11-10 23:36:04 +03:00
|
|
|
builtinScroll(xScroller, x, yScroller, y, false);
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
scrollTimer = requestAnimationFrame(scrollAnim);
|
|
|
|
};
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
scrollTimer = requestAnimationFrame(scrollAnim);
|
|
|
|
}
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
/**
|
|
|
|
* Performs scroll.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} xScroller horizontal scroller
|
|
|
|
* @param {number} scrollX horizontal coordinate
|
|
|
|
* @param {HTMLElement} yScroller vertical scroller
|
|
|
|
* @param {number} scrollY vertical coordinate
|
|
|
|
* @param {boolean} smooth smooth scrolling
|
|
|
|
*/
|
|
|
|
function doScroll(xScroller, scrollX, yScroller, scrollY, smooth) {
|
2019-10-20 14:53:12 +03:00
|
|
|
|
2019-10-22 22:19:43 +03:00
|
|
|
resetScrollTimer();
|
|
|
|
|
|
|
|
if (smooth && useAnimatedScroll()) {
|
|
|
|
animateScroll(xScroller, scrollX, yScroller, scrollY);
|
2019-10-19 23:36:59 +03:00
|
|
|
} else {
|
2019-10-23 22:35:45 +03:00
|
|
|
builtinScroll(xScroller, scrollX, yScroller, scrollY, smooth);
|
2019-10-19 23:36:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if smooth scroll must be used.
|
|
|
|
*/
|
|
|
|
function useSmoothScroll() {
|
|
|
|
|
|
|
|
if (browser.tizen) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2019-10-20 14:53:12 +03:00
|
|
|
/**
|
|
|
|
* Returns true if animated implementation of smooth scroll must be used.
|
|
|
|
*/
|
|
|
|
function useAnimatedScroll() {
|
|
|
|
// Add block to force using (or not) of animated implementation
|
|
|
|
|
|
|
|
return !supportsSmoothScroll;
|
|
|
|
};
|
|
|
|
|
2019-10-19 23:36:59 +03:00
|
|
|
/**
|
|
|
|
* Returns true if scroll manager is enabled.
|
|
|
|
*/
|
|
|
|
var isEnabled = function() {
|
|
|
|
|
|
|
|
if (!layoutManager.tv) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser.tizen) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser.web0s) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-10-22 23:46:21 +03:00
|
|
|
* Scrolls the document to a given position.
|
2019-10-19 23:36:59 +03:00
|
|
|
*
|
2019-10-22 23:46:21 +03:00
|
|
|
* @param {number} scrollX horizontal coordinate
|
|
|
|
* @param {number} scrollY vertical coordinate
|
|
|
|
* @param {boolean} [smooth=false] smooth scrolling
|
2019-10-19 23:36:59 +03:00
|
|
|
*/
|
2019-10-22 23:46:21 +03:00
|
|
|
var scrollTo = function(scrollX, scrollY, smooth) {
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
smooth = !!smooth;
|
2019-10-19 23:36:59 +03:00
|
|
|
|
|
|
|
// Scroller is document itself by default
|
2019-10-22 23:46:21 +03:00
|
|
|
var scroller = getScrollableParent(null, false);
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var xScrollerData = getScrollerData(scroller, false);
|
|
|
|
var yScrollerData = getScrollerData(scroller, true);
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
scrollX = clamp(Math.round(scrollX), 0, xScrollerData.scrollSize - xScrollerData.clientSize);
|
|
|
|
scrollY = clamp(Math.round(scrollY), 0, yScrollerData.scrollSize - yScrollerData.clientSize);
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
doScroll(scroller, scrollX, scroller, scrollY, smooth);
|
|
|
|
}
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
/**
|
|
|
|
* Scrolls the document to a given element.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} element target element of scroll task
|
|
|
|
* @param {boolean} [smooth=false] smooth scrolling
|
|
|
|
*/
|
|
|
|
var scrollToElement = function(element, smooth) {
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
smooth = !!smooth;
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var scrollCenterX = true;
|
|
|
|
var scrollCenterY = true;
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var offsetParent = element.offsetParent;
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-23 22:38:01 +03:00
|
|
|
// In Firefox offsetParent.offsetParent is BODY
|
|
|
|
var isFixed = offsetParent && (!offsetParent.offsetParent || window.getComputedStyle(offsetParent).position === "fixed");
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
// Scroll fixed elements to nearest edge (or do not scroll at all)
|
|
|
|
if (isFixed) {
|
|
|
|
scrollCenterX = scrollCenterY = false;
|
|
|
|
}
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var xScroller = getScrollableParent(element, false);
|
|
|
|
var yScroller = getScrollableParent(element, true);
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var elementRect = element.getBoundingClientRect();
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
var xScrollerData = getScrollerData(xScroller, false);
|
|
|
|
var yScrollerData = getScrollerData(yScroller, true);
|
|
|
|
|
|
|
|
var xPos = getScrollerChildPos(xScroller, element, false);
|
|
|
|
var yPos = getScrollerChildPos(yScroller, element, true);
|
|
|
|
|
|
|
|
var scrollX = calcScroll(xScrollerData, xPos, elementRect.width, scrollCenterX);
|
|
|
|
var scrollY = calcScroll(yScrollerData, yPos, elementRect.height, scrollCenterY);
|
|
|
|
|
|
|
|
// HACK: Scroll to top for top menu because it is hidden
|
|
|
|
// FIXME: Need a marker to scroll top/bottom
|
|
|
|
if (isFixed && elementRect.bottom < 0) {
|
|
|
|
scrollY = 0;
|
|
|
|
}
|
2019-10-19 23:36:59 +03:00
|
|
|
|
2019-10-22 23:46:21 +03:00
|
|
|
// HACK: Ensure we are at the top
|
|
|
|
// FIXME: Need a marker to scroll top/bottom
|
|
|
|
if (scrollY < minimumScrollY()) {
|
|
|
|
scrollY = 0;
|
2019-10-19 23:36:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
doScroll(xScroller, scrollX, yScroller, scrollY, smooth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEnabled()) {
|
|
|
|
dom.addEventListener(window, "focusin", function(e) {
|
|
|
|
setTimeout(function() {
|
2019-10-22 23:46:21 +03:00
|
|
|
scrollToElement(e.target, useSmoothScroll());
|
2019-10-19 23:36:59 +03:00
|
|
|
}, 0);
|
|
|
|
}, {capture: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
isEnabled: isEnabled,
|
2019-10-22 23:46:21 +03:00
|
|
|
scrollTo: scrollTo,
|
|
|
|
scrollToElement: scrollToElement
|
2019-10-19 23:36:59 +03:00
|
|
|
};
|
|
|
|
});
|