mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-04 13:10:33 +01:00
30 lines
921 B
JavaScript
30 lines
921 B
JavaScript
|
import * as Turbo from 'https://cdn.jsdelivr.net/npm/@hotwired/turbo@7.3.0/+esm';
|
||
|
|
||
|
(() => {
|
||
|
if (!window.scrollPositions) {
|
||
|
window.scrollPositions = {};
|
||
|
}
|
||
|
|
||
|
function preserveScroll() {
|
||
|
document.querySelectorAll('[data-preserve-scroll').forEach(element => {
|
||
|
scrollPositions[element.id] = element.scrollTop;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function restoreScroll(event) {
|
||
|
document.querySelectorAll('[data-preserve-scroll').forEach(element => {
|
||
|
element.scrollTop = scrollPositions[element.id];
|
||
|
});
|
||
|
|
||
|
if (event.detail && event.detail.newBody) {
|
||
|
event.detail.newBody.querySelectorAll('[data-preserve-scroll').forEach(element => {
|
||
|
element.scrollTop = scrollPositions[element.id];
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.addEventListener('turbo:before-cache', preserveScroll);
|
||
|
window.addEventListener('turbo:before-render', restoreScroll);
|
||
|
window.addEventListener('turbo:render', restoreScroll);
|
||
|
})();
|