diff --git a/assets/js/modules/toc.ts b/assets/js/modules/toc.ts index 7e579f6d..c7b67924 100644 --- a/assets/js/modules/toc.ts +++ b/assets/js/modules/toc.ts @@ -190,7 +190,7 @@ export class TocModule implements TocService { return // Copy TOC to target containers - const targets = ['toc-content-drawer', 'toc-content-static', 'toc-content-auto'] + const targets = ['toc-content-static', 'toc-content-auto', 'toc-content-drawer'] for (const id of targets) { const $container = document.getElementById(id) if ($container && !$container.querySelector('nav')) { @@ -222,6 +222,19 @@ export class TocModule implements TocService { }, false) } + /** Initialize the mobile TOC drawer dialog and its open/close handlers. */ + initTocDialogLink() { + const dialog = document.querySelector('#toc-dialog') + if (!dialog) + return + document.querySelectorAll('#toc-content-drawer a[href^="#"]').forEach(($link) => { + if ($link.dataset.tocDialogCloseBound === 'true') + return + $link.addEventListener('click', () => dialog.close()) + $link.dataset.tocDialogCloseBound = 'true' + }) + } + /** Initialize the mobile TOC drawer dialog and its open/close handlers. */ initTocDialog() { const dialog = document.querySelector('#toc-dialog') @@ -239,9 +252,6 @@ export class TocModule implements TocService { this.scrollActiveTocLinkIntoView($dialogTocRoot, this.activeTocId!, $dialogTocRoot) ;(document.activeElement as HTMLElement)?.blur() }) - document.querySelectorAll('#toc-content-drawer a[href^="#"]').forEach(($link) => { - $link.addEventListener('click', () => dialog.close()) - }) dialog.addEventListener('close', () => { openButton.setAttribute('aria-expanded', 'false') }) @@ -263,12 +273,14 @@ export class TocModule implements TocService { this.syncTocLayout() this.initTocListener() this.initTocDialog() + this.initTocDialogLink() this.fixTocScroll() eventBus.on('fixit:resize', () => this.syncTocLayout()) eventBus.on('fixit:scroll', () => this.syncTocActiveState()) eventBus.on('fixit:decrypted', () => { this.initToc() this.syncTocLayout() + this.initTocDialogLink() }) } } diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 10ac8a25..ab24695a 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v1.0.0-mr4ox9ps" -}} +{{- hugo.Store.Set "version" "v1.0.0-mr84fuvo" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}