tocbot.html 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. {{- if .Params.toc }}
  2. <script defer src="/tocbot/tocbot.min.js"></script>
  3. <script>
  4. function docReady(fn) {
  5. // see if DOM is already available
  6. if (document.readyState === "complete" || document.readyState === "interactive") {
  7. // call on next available tick
  8. setTimeout(fn, 1);
  9. } else {
  10. document.addEventListener("DOMContentLoaded", fn);
  11. }
  12. }
  13. docReady(function () {
  14. var head = document.getElementsByTagName("head")[0], script;
  15. // Load table of contents
  16. function initToc(fn) {
  17. window.tocbot.init({
  18. // Where to render the table of contents.
  19. tocSelector: '.js-toc',
  20. // Where to grab the headings to build the table of contents.
  21. contentSelector: '.js-toc-content',
  22. // Which headings to grab inside of the contentSelector element.
  23. headingSelector: 'h1, h2, h3'
  24. });
  25. }
  26. initToc();
  27. });
  28. </script>
  29. {{- end }}