mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 06:30:59 +01:00
054d124afe
Many thanks to all the other developers who made this possible, especially Shoelace
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);
|
|
})();
|