Browse Source

Fix Doks toc

pull/686/head
danpros 1 year ago
parent
commit
d9edbe55f8
2 changed files with 6 additions and 6 deletions
  1. +5
    -5
      themes/doks/js/toc.js
  2. +1
    -1
      themes/doks/layout--static.html.php

+ 5
- 5
themes/doks/js/toc.js View File

@ -25,15 +25,15 @@
* insert the anchor inside the heading * insert the anchor inside the heading
* fix browser not scrolling to the hash * 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 toc = documentRef.getElementById('toc');
var headings = [].slice.call(documentRef.body.querySelectorAll('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6')); var headings = [].slice.call(documentRef.body.querySelectorAll('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6'));
headings.forEach(function (heading, index) { 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'); 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; link.textContent = heading.textContent;
var div = documentRef.createElement('div'); var div = documentRef.createElement('div');
@ -42,7 +42,7 @@ function htmlTableOfContents (documentRef) {
div.appendChild(link); div.appendChild(link);
toc.appendChild(div); toc.appendChild(div);
}); });
if (window.location.hash) { if (window.location.hash) {
var hash = window.location.hash; var hash = window.location.hash;
scrollToHash(hash); scrollToHash(hash);


+ 1
- 1
themes/doks/layout--static.html.php View File

@ -11,7 +11,7 @@
<link rel="stylesheet" href="<?php echo theme_path();?>css/style.css"> <link rel="stylesheet" href="<?php echo theme_path();?>css/style.css">
<meta name="theme-color" content="#fff"> <meta name="theme-color" content="#fff">
</head> </head>
<body class="docs single" onload="htmlTableOfContents();">
<body class="docs single" <?php if (isset($is_page)):?>onload="htmlTableOfContents('.page-<?php echo $static->slug;?>');"<?php endif;?> <?php if (isset($is_subpage)):?>onload="htmlTableOfContents('.subpage-<?php echo $static->slug;?>');"<?php endif;?>>
<div class="header-bar fixed-top"></div> <div class="header-bar fixed-top"></div>
<?php if (facebook()) { echo facebook(); } ?> <?php if (facebook()) { echo facebook(); } ?>
<?php if (login()) { toolbar(); } ?> <?php if (login()) { toolbar(); } ?>


Loading…
Cancel
Save