Skip to content

Commit

Permalink
js: Also preserve scroll-y upon auto-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd authored and nilmerg committed May 19, 2023
1 parent e0e2ff7 commit a323555
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions public/js/icinga/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,13 +1234,22 @@
if (autorefresh || autoSubmit) {
if ($container.css('display') === 'flex' && $container.is('.container')) {
var $scrollableContent = $container.children('.content');
scrollPos = $scrollableContent.scrollTop();
scrollPos = {
x: $scrollableContent.scrollTop(),
y: $scrollableContent.scrollLeft()
};
scrollTarget = _this.icinga.utils.getCSSPath($scrollableContent);
} else {
scrollPos = $container.scrollTop();
scrollPos = {
x: $container.scrollTop(),
y: $container.scrollLeft()
};
}
} else {
scrollPos = 0;
scrollPos = {
x: 0,
y: 0
}
}
}

Expand Down Expand Up @@ -1314,14 +1323,16 @@

if (scrollPos !== false) {
var $scrollTarget = $(scrollTarget);
$scrollTarget.scrollTop(scrollPos);

// Fallback for browsers without support for focus({preventScroll: true})
setTimeout(function () {
if ($scrollTarget.scrollTop() !== scrollPos) {
$scrollTarget.scrollTop(scrollPos);
requestAnimationFrame(() => {
if ($scrollTarget.scrollTop() !== scrollPos.x) {
$scrollTarget.scrollTop(scrollPos.x);
}
}, 0);
if ($scrollTarget.scrollLeft() !== scrollPos.y) {
$scrollTarget.scrollLeft(scrollPos.y);
}
});
}

// Re-enable all click events (disabled as of performance reasons)
Expand Down

0 comments on commit a323555

Please sign in to comment.