diff --git a/public/themes/custom/hdbt_subtheme/dist/js/updatingNewsTableOfContents.min.js b/public/themes/custom/hdbt_subtheme/dist/js/updatingNewsTableOfContents.min.js index fdd64be8b..b001dfb0b 100644 --- a/public/themes/custom/hdbt_subtheme/dist/js/updatingNewsTableOfContents.min.js +++ b/public/themes/custom/hdbt_subtheme/dist/js/updatingNewsTableOfContents.min.js @@ -1 +1 @@ -!function(){"use strict";!function(Drupal,e){Drupal.behaviors.updating_news_table_of_contents={attach:function(){const t=document.getElementById("helfi-toc-table-of-contents-news-updates");if(!t)return;const n=document.querySelector("#helfi-toc-table-of-contents-list > ul"),o=document.querySelector("main.layout-main-wrapper");document.querySelectorAll("[id]").forEach((function(e){Drupal.tableOfContents.reservedIds.push(e.id)}));let a=Drupal.tableOfContents.exclusions();a+=":not(.components--upper *):not(.component--remote-video *):not(.component--paragraph-text *):not(.component--banner *):not(.component--image *):not(.block--news-of-interest *):not(#helfi-toc-table-of-contents-news-updates *)",e("updating-news-table-of-contents",Drupal.tableOfContents.titleComponents(a).join(","),o).forEach((function(e){const{nodeName:o,anchorName:a}=Drupal.tableOfContents.createTableOfContentElements(e,[]);let l="";if(t&&e.nextSibling&&"TIME"===e.nextElementSibling.nodeName){let t=new Date(e.nextElementSibling.dateTime);l=`${t.getDate()}.${t.getMonth()+1}.${t.getFullYear()}`}if(n&&"h2"===o){let t=document.createElement("li");if(t.classList.add("table-of-contents__item"),l){let n=document.createElement("time");n.dateTime=e.nextElementSibling.dateTime,n.textContent=l,t.appendChild(n)}let o=document.createElement("a");o.classList.add("table-of-contents__link"),o.href=`#${a}`,o.textContent=e.textContent.trim(),t.appendChild(o),n.appendChild(t)}})),t&&Drupal.tableOfContents.updateTOC(t)}}}(Drupal,once)}(); \ No newline at end of file +!function(){"use strict";!function(Drupal,e){Drupal.behaviors.updating_news_table_of_contents={attach:function(){const t=document.getElementById("helfi-toc-table-of-contents-news-updates");if(!t)return;const n=document.querySelector("#helfi-toc-table-of-contents-list > ul"),o=document.querySelector("main.layout-main-wrapper");document.querySelectorAll("[id]").forEach((function(e){Drupal.tableOfContents.reservedIds.push(e.id)}));const l=Drupal.tableOfContents.titleComponents(".component__title").map((e=>".component--news-update "+e));e("updating-news-table-of-contents",l.join(","),o).forEach((function(e){const{nodeName:o,anchorName:l}=Drupal.tableOfContents.createTableOfContentElements(e,[]);let a="";if(t&&e.nextSibling&&"TIME"===e.nextElementSibling.nodeName){let t=new Date(e.nextElementSibling.dateTime);a=`${t.getDate()}.${t.getMonth()+1}.${t.getFullYear()}`}if(n&&"h2"===o){let t=document.createElement("li");if(t.classList.add("table-of-contents__item"),a){let n=document.createElement("time");n.dateTime=e.nextElementSibling.dateTime,n.textContent=a,t.appendChild(n)}let o=document.createElement("a");o.classList.add("table-of-contents__link"),o.href=`#${l}`,o.textContent=e.textContent.trim(),t.appendChild(o),n.appendChild(t)}})),t&&Drupal.tableOfContents.updateTOC(t)}}}(Drupal,once)}(); \ No newline at end of file diff --git a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.libraries.yml b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.libraries.yml index ef35eb84b..bb6d88f70 100644 --- a/public/themes/custom/hdbt_subtheme/hdbt_subtheme.libraries.yml +++ b/public/themes/custom/hdbt_subtheme/hdbt_subtheme.libraries.yml @@ -7,7 +7,7 @@ global-styling: updating-news-table-of-contents: js: dist/js/updatingNewsTableOfContents.min.js: {} - version: 1.0 + version: 1.0.1 dependencies: - core/once - helfi_toc/table_of_contents diff --git a/public/themes/custom/hdbt_subtheme/src/js/updatingNewsTableOfContents.js b/public/themes/custom/hdbt_subtheme/src/js/updatingNewsTableOfContents.js index ad376ec74..a97b3c7ac 100644 --- a/public/themes/custom/hdbt_subtheme/src/js/updatingNewsTableOfContents.js +++ b/public/themes/custom/hdbt_subtheme/src/js/updatingNewsTableOfContents.js @@ -17,21 +17,13 @@ reservedElems.forEach(function (elem) { Drupal.tableOfContents.reservedIds.push(elem.id); }); - let exclusions = Drupal.tableOfContents.exclusions(); - // Add exclusions for the news updates table of contents. NOTICE: The text paragraph is the only one that - // has paragraph as a prefix, so it might look a bit silly compared to the other selectors. - exclusions += - ':not(.components--upper *)' + - ':not(.component--remote-video *)' + - ':not(.component--paragraph-text *)' + - ':not(.component--banner *)' + - ':not(.component--image *)' + - ':not(.block--news-of-interest *)' + - ':not(#helfi-toc-table-of-contents-news-updates *)'; + // Instead of targeting all headings on page, lets focus on only news update headings. + // This will generate selector like: .component--news-update h2.component__title, .component--news-update h3.component__title... + const titleComponents = Drupal.tableOfContents.titleComponents('.component__title').map(el => '.component--news-update ' + el); // Craft table of contents for news item. - once('updating-news-table-of-contents', Drupal.tableOfContents.titleComponents(exclusions).join(','), mainContent) + once('updating-news-table-of-contents', titleComponents.join(','), mainContent) .forEach(function (content) { const { nodeName, anchorName} = Drupal.tableOfContents.createTableOfContentElements(content, []);