From b988102265e0a917f7ada910023eb4db43318ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Wed, 12 Jun 2024 10:35:20 +0300 Subject: [PATCH] Moved the table of contents check to a later part of the script to retain the heading ids. --- modules/helfi_toc/assets/js/tableOfContents.js | 11 ++++++----- modules/helfi_toc/helfi_toc.libraries.yml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/helfi_toc/assets/js/tableOfContents.js b/modules/helfi_toc/assets/js/tableOfContents.js index d5b8246a7..c9250c596 100644 --- a/modules/helfi_toc/assets/js/tableOfContents.js +++ b/modules/helfi_toc/assets/js/tableOfContents.js @@ -202,11 +202,6 @@ attach: function attach() { const tableOfContents = document.getElementById('helfi-toc-table-of-contents'); - // Bail if table of contents is not enabled. - if (!tableOfContents) { - return; - } - const tableOfContentsList = document.querySelector('#helfi-toc-table-of-contents-list > ul'); const mainContent = document.querySelector('main.layout-main-wrapper'); const reservedElems = document.querySelectorAll('[id]'); @@ -220,6 +215,12 @@ const { nodeName, anchorName} = Drupal.tableOfContents.createTableOfContentElements(content, []); + // Bail if table of contents is not enabled, + // but retain the heading element id. + if (!tableOfContents) { + return; + } + // Create table of contents if component is enabled. if (tableOfContentsList && nodeName === 'h2') { let listItem = document.createElement('li'); diff --git a/modules/helfi_toc/helfi_toc.libraries.yml b/modules/helfi_toc/helfi_toc.libraries.yml index 12d83f7fb..3c1c73fa5 100644 --- a/modules/helfi_toc/helfi_toc.libraries.yml +++ b/modules/helfi_toc/helfi_toc.libraries.yml @@ -1,5 +1,5 @@ table_of_contents: - version: 1.0.2 + version: 1.0.3 js: assets/js/tableOfContents.js: {} dependencies: