1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add scroll manager with base functionality

This commit is contained in:
Dmitry Lyzo 2019-10-19 23:36:59 +03:00
parent 3419230e89
commit c0783dbe8e
4 changed files with 382 additions and 2 deletions

View file

@ -0,0 +1,39 @@
// Polyfill to add support for preventScroll by focus function
if (HTMLElement.prototype.nativeFocus === undefined) {
(function () {
var supportsPreventScrollOption = false;
try {
var focusElem = document.createElement("div");
focusElem.addEventListener("focus", function(event) {
event.preventDefault();
event.stopPropagation();
}, true);
var opts = Object.defineProperty({}, "preventScroll", {
get: function () {
supportsPreventScrollOption = true;
}
});
focusElem.focus(opts);
} catch(e) {}
if (!supportsPreventScrollOption) {
HTMLElement.prototype.nativeFocus = HTMLElement.prototype.focus;
HTMLElement.prototype.focus = function(options) {
var scrollX = window.scrollX;
var scrollY = window.scrollY;
this.nativeFocus();
// Restore window scroll if preventScroll
if (options && options.preventScroll) {
window.scroll(scrollX, scrollY);
}
};
}
})();
}