Skip to content

Commit 29607ec

Browse files
committed
Prettify
1 parent 0c3ab5c commit 29607ec

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/Elastic.Documentation.Site/Assets/open-details-with-anchor.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,37 @@ export function initOpenDetailsWithAnchor() {
3838
window.addEventListener('hashchange', openDetailsWithAnchor)
3939

4040
// Handle dropdown URL updates
41-
document.addEventListener('click', (event) => {
42-
const target = event.target as HTMLElement
43-
const dropdown = target.closest('details.dropdown') as HTMLDetailsElement
44-
if (dropdown) {
45-
const initialState = dropdown.open
46-
47-
// Check state after toggle completes
48-
setTimeout(() => {
49-
const finalState = dropdown.open
50-
const stateChanged = initialState !== finalState
51-
52-
// If dropdown opened and doesn't have open-default flag, push URL
53-
if (stateChanged && finalState && !dropdown.dataset.openDefault) {
54-
window.history.pushState(null, '', `#${dropdown.id}`)
55-
}
56-
57-
// Remove open-default flag after first interaction
58-
if (dropdown.dataset.openDefault === 'true') {
59-
delete dropdown.dataset.openDefault
60-
}
61-
}, 10)
62-
}
63-
}, true)
41+
document.addEventListener(
42+
'click',
43+
(event) => {
44+
const target = event.target as HTMLElement
45+
const dropdown = target.closest(
46+
'details.dropdown'
47+
) as HTMLDetailsElement
48+
if (dropdown) {
49+
const initialState = dropdown.open
50+
51+
// Check state after toggle completes
52+
setTimeout(() => {
53+
const finalState = dropdown.open
54+
const stateChanged = initialState !== finalState
55+
56+
// If dropdown opened and doesn't have open-default flag, push URL
57+
if (
58+
stateChanged &&
59+
finalState &&
60+
!dropdown.dataset.openDefault
61+
) {
62+
window.history.pushState(null, '', `#${dropdown.id}`)
63+
}
64+
65+
// Remove open-default flag after first interaction
66+
if (dropdown.dataset.openDefault === 'true') {
67+
delete dropdown.dataset.openDefault
68+
}
69+
}, 10)
70+
}
71+
},
72+
true
73+
)
6474
}

0 commit comments

Comments
 (0)