From d9edbe55f84aa66407ac345514276474834bab20 Mon Sep 17 00:00:00 2001 From: danpros Date: Fri, 23 Feb 2024 15:31:00 +0700 Subject: [PATCH] Fix Doks toc --- themes/doks/js/toc.js | 10 +++++----- themes/doks/layout--static.html.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/doks/js/toc.js b/themes/doks/js/toc.js index 81ae07f..d9dd498 100644 --- a/themes/doks/js/toc.js +++ b/themes/doks/js/toc.js @@ -25,15 +25,15 @@ * insert the anchor inside the heading * fix browser not scrolling to the hash */ -function htmlTableOfContents (documentRef) { - var documentRef = documentRef || document; +function htmlTableOfContents (id) { + var documentRef = document; var toc = documentRef.getElementById('toc'); var headings = [].slice.call(documentRef.body.querySelectorAll('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6')); headings.forEach(function (heading, index) { - heading.setAttribute('id', 'toc-' + heading.textContent.replace(/\s+/g, '-').toLowerCase()); + heading.setAttribute('id', heading.textContent.replace(/\s+/g, '-').toLowerCase() + id); var link = documentRef.createElement('a'); - link.setAttribute('href', '#toc-' + heading.textContent.replace(/\s+/g, '-').toLowerCase()); + link.setAttribute('href', '#' + heading.textContent.replace(/\s+/g, '-').toLowerCase() + id); link.textContent = heading.textContent; var div = documentRef.createElement('div'); @@ -42,7 +42,7 @@ function htmlTableOfContents (documentRef) { div.appendChild(link); toc.appendChild(div); }); - + if (window.location.hash) { var hash = window.location.hash; scrollToHash(hash); diff --git a/themes/doks/layout--static.html.php b/themes/doks/layout--static.html.php index def94b4..e381294 100644 --- a/themes/doks/layout--static.html.php +++ b/themes/doks/layout--static.html.php @@ -11,7 +11,7 @@ - +onload="htmlTableOfContents('.page-slug;?>');" onload="htmlTableOfContents('.subpage-slug;?>');">