Skip to content

Commit

Permalink
Improvement: Add prefixes to the sessionStorage keys in the scrollspy…
Browse files Browse the repository at this point in the history
… implementation, resolves #598.
  • Loading branch information
abias committed Mar 18, 2024
1 parent 1e48934 commit 1171b24
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ moodle-theme_boost_union
Changes
-------

### Unreleased

* 2024-03-18 - Improvement: Add prefixes to the sessionStorage keys in the scrollspy implementation, resolves #598.

### v4.3-r9

* 2024-03-13 - Improvement: In smart menus, dynamic courses can now pick up the courses from all subcategories, resolves #395.
Expand Down
2 changes: 1 addition & 1 deletion amd/build/scrollspy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/scrollspy.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions amd/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const initScrollSpy = () => {
}
editToggle.addEventListener('click', () => {

window.sessionStorage.setItem('edittoggled', true);
window.sessionStorage.setItem('theme_boost_union_scrollspy_edittoggled', true);

let viewporttop = window.scrollY;
let closest = null;
Expand All @@ -61,14 +61,14 @@ const initScrollSpy = () => {
}
});

window.sessionStorage.setItem('closestid', closest.id);
window.sessionStorage.setItem('closestdelta', viewporttop - closest.offsetTop);
window.sessionStorage.setItem('theme_boost_union_scrollspy_closestid', closest.id);
window.sessionStorage.setItem('theme_boost_union_scrollspy_closestdelta', viewporttop - closest.offsetTop);
});
let edittoggled = window.sessionStorage.getItem('edittoggled');
let edittoggled = window.sessionStorage.getItem('theme_boost_union_scrollspy_edittoggled');
if (edittoggled) {

let closestid = window.sessionStorage.getItem('closestid');
let closestdelta = window.sessionStorage.getItem('closestdelta');
let closestid = window.sessionStorage.getItem('theme_boost_union_scrollspy_closestid');
let closestdelta = window.sessionStorage.getItem('theme_boost_union_scrollspy_closestdelta');

if (closestid && closestdelta) {
let closest = document.getElementById(closestid);
Expand All @@ -77,9 +77,9 @@ const initScrollSpy = () => {
window.scrollTo(0, y);
}

window.sessionStorage.removeItem('edittoggled');
window.sessionStorage.removeItem('closestid');
window.sessionStorage.removeItem('closestdelta');
window.sessionStorage.removeItem('theme_boost_union_scrollspy_edittoggled');
window.sessionStorage.removeItem('theme_boost_union_scrollspy_closestid');
window.sessionStorage.removeItem('theme_boost_union_scrollspy_closestdelta');
}
}
};
Expand Down

0 comments on commit 1171b24

Please sign in to comment.