Merge pull request #5859 from dfsmania/parse-data-attr-on-treeview

pull/5869/head
Aigars Silkalns 2025-06-22 19:07:22 +03:00 committed by GitHub
commit e634d5e000
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -119,13 +119,24 @@ onDOMContentLoaded(() => {
const target = event.target as HTMLElement
const targetItem = target.closest(SELECTOR_NAV_ITEM) as HTMLElement | undefined
const targetLink = target.closest(SELECTOR_NAV_LINK) as HTMLAnchorElement | undefined
const lteToggleElement = event.currentTarget as HTMLElement
if (target?.getAttribute('href') === '#' || targetLink?.getAttribute('href') === '#') {
event.preventDefault()
}
if (targetItem) {
const data = new Treeview(targetItem, Default)
// Read data attributes
const accordionAttr = lteToggleElement.dataset.accordion
const animationSpeedAttr = lteToggleElement.dataset.animationSpeed
// Build config from data attributes, fallback to Default
const config: Config = {
accordion: accordionAttr === undefined ? Default.accordion : accordionAttr === 'true',
animationSpeed: animationSpeedAttr === undefined ? Default.animationSpeed : Number(animationSpeedAttr)
}
const data = new Treeview(targetItem, config)
data.toggle()
}
})