Skip to content

Commit 22a9b6f

Browse files
committed
Make expanders work with URL IDs
1 parent 2948aef commit 22a9b6f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

js/javascript.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ document.addEventListener('DOMContentLoaded', function () {
1414
markActivePage();
1515
resizeAllTextAreas();
1616
setupExpanders();
17+
18+
const hash = window.location.hash;
19+
if (hash) {
20+
const id = hash.substring(1);
21+
openExpanderForID(id);
22+
}
1723
});
1824
window.onscroll = updateProgressBarAndFadeIn;
1925

@@ -66,7 +72,7 @@ function setupExpanders() {
6672
expanders.forEach((expander, index) => {
6773
// Skip if already has an ID
6874
if (expander.id)
69-
return;
75+
return;
7076

7177
// Remove any existing ID
7278
const oldId = expander.id;
@@ -115,6 +121,19 @@ function expandCard(thisObj, $open, $dontReset) {
115121
}
116122
}
117123

124+
// Opens an expander that CONTAINS (not is) the ID
125+
function openExpanderForID(id) {
126+
const object = document.getElementById(id);
127+
const expander = object.closest('.expander-bottom');
128+
if (expander) {
129+
const expanderTop = expander.previousElementSibling;
130+
if (expanderTop) {
131+
expandCard(expanderTop, expander, true);
132+
expander.scrollIntoView({ behavior: 'smooth', block: 'start' });
133+
}
134+
}
135+
}
136+
118137
function resizeAllTextAreas() {
119138
if (autoSizeAreas && autoSizeAreas.length > 0) {
120139
for (var i = 0; i < autoSizeAreas.length; i++) {

0 commit comments

Comments
 (0)