toc.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <aside class="toc-wrapper">
  2. <a href="https://materialize.com/s/chat" class="btn-ghost"
  3. ><svg
  4. width="21"
  5. height="21"
  6. viewBox="0 0 21 21"
  7. fill="currentColor"
  8. xmlns="http://www.w3.org/2000/svg"
  9. >
  10. <path
  11. d="M4.31717 13.238C4.31717 14.4012 3.37517 15.3432 2.21199 15.3432C1.04881 15.3432 0.106812 14.4012 0.106812 13.238C0.106812 12.0748 1.04881 11.1328 2.21199 11.1328H4.31717V13.238Z"
  12. ></path>
  13. <path
  14. d="M5.37042 13.238C5.37042 12.0748 6.31242 11.1328 7.4756 11.1328C8.63878 11.1328 9.58078 12.0748 9.58078 13.238V18.5017C9.58078 19.6649 8.63878 20.6069 7.4756 20.6069C6.31242 20.6069 5.37042 19.6649 5.37042 18.5017V13.238Z"
  15. ></path>
  16. <path
  17. d="M7.4756 4.81729C6.31242 4.81729 5.37042 3.87529 5.37042 2.71211C5.37042 1.54893 6.31242 0.606934 7.4756 0.606934C8.63878 0.606934 9.58078 1.54893 9.58078 2.71211V4.81729H7.4756Z"
  18. ></path>
  19. <path
  20. d="M7.47574 5.87061C8.63891 5.87061 9.58091 6.81261 9.58091 7.97578C9.58091 9.13896 8.63891 10.081 7.47574 10.081H2.21199C1.04881 10.081 0.106812 9.13737 0.106812 7.97578C0.106812 6.8142 1.04881 5.87061 2.21199 5.87061H7.47574Z"
  21. ></path>
  22. <path
  23. d="M15.8955 7.97578C15.8955 6.81261 16.8375 5.87061 18.0007 5.87061C19.1639 5.87061 20.1059 6.81261 20.1059 7.97578C20.1059 9.13896 19.1639 10.081 18.0007 10.081H15.8955V7.97578Z"
  24. ></path>
  25. <path
  26. d="M14.8423 7.97586C14.8423 9.13904 13.9003 10.081 12.7372 10.081C11.574 10.081 10.632 9.13904 10.632 7.97586V2.71211C10.632 1.54893 11.574 0.606934 12.7372 0.606934C13.9003 0.606934 14.8423 1.54893 14.8423 2.71211V7.97586Z"
  27. ></path>
  28. <path
  29. d="M12.7371 16.3967C13.9003 16.3967 14.8423 17.3387 14.8423 18.5019C14.8423 19.6651 13.9003 20.6071 12.7371 20.6071C11.574 20.6071 10.632 19.6651 10.632 18.5019V16.3967H12.7371Z"
  30. ></path>
  31. <path
  32. d="M12.7372 15.3432C11.574 15.3432 10.632 14.4012 10.632 13.238C10.632 12.0748 11.574 11.1328 12.7372 11.1328H18.0009C19.1641 11.1328 20.1061 12.0748 20.1061 13.238C20.1061 14.4012 19.1641 15.3432 18.0009 15.3432H12.7372Z"
  33. ></path></svg
  34. >Join The Community</a
  35. >
  36. {{ if not (.Params.disable_toc) }}
  37. <div class="toc">
  38. <h2 class="gradient_text dark">On this page</h2>
  39. {{ .TableOfContents }}
  40. </div>
  41. {{end}}
  42. </aside>
  43. <script>
  44. // A custom "scrollspy" plugin that highlights the TOC link for the
  45. // currently-visible section.
  46. /// Computes the absolute offset of each heading from the top of the page.
  47. /// Offsets are massaged so that headings beyond the maximum scroll offset
  48. /// of the page are reassigned a reasonable and unique offset within the
  49. /// page's scroll boundaries. This makes it possible to distinguish headings
  50. /// that would otherwise all require scrolling to the very end of the
  51. /// viewport.
  52. /// The header now has a fixed position. The _base.scss defines header height.
  53. function headingOffsets() {
  54. const SLOP = 100;
  55. const headings = $(".content h2, .content h3");
  56. let offsets = headings.toArray().map((h) => ({
  57. id: h.id,
  58. offset: h.offsetTop - 65, // 75 if banner is displayed, 65 otherwise
  59. }));
  60. const cutoff = $(document).height() - $(window).height() - SLOP;
  61. const firstBad = offsets.findIndex((o) => o.offset > cutoff);
  62. if (firstBad === -1 || firstBad === offsets.length - 1) return offsets;
  63. const allotment = SLOP / (offsets.length - firstBad);
  64. for (var i = firstBad; i < offsets.length; i++)
  65. offsets[i].offset = cutoff + (i - firstBad + 1) * allotment;
  66. return offsets;
  67. }
  68. // Update the active TOC link on every scroll event.
  69. $(window).scroll(() => {
  70. const scroll = $(window).scrollTop();
  71. const offsets = headingOffsets();
  72. let activeId = null;
  73. if (offsets.length > 0 ) {
  74. activeId = scroll == 0 ? null : offsets[offsets.length - 1].id;
  75. }
  76. for (let i = 0; i < offsets.length && scroll > 0 ; i++) {
  77. if (offsets[i].offset > scroll) {
  78. activeId = offsets[i].id;
  79. break;
  80. }
  81. }
  82. $(".toc .active").removeClass("active");
  83. if (activeId) $(`.toc [href="#${activeId}"]`).addClass("active");
  84. });
  85. // Scroll to our massaged offsets on a hashchange event, to override the
  86. // browser's automatic scroll to the unmassaged offset.
  87. $(window).on("hashchange", function () {
  88. $(window).trigger("scroll");
  89. });
  90. // Trigger an initial hash change event to handle scrolling to the page's
  91. // initial hash.
  92. $(() => $(window).trigger("hashchange"));
  93. // Prevent double clicking on a TOC link from scrolling the page if we're
  94. // already on that TOC link's section, as we won't get a hashchange event
  95. // to fix up the scroll offset.
  96. $(".toc a").click(function (e) {
  97. console.log($(this).attr("href"), window.location.hash);
  98. if ($(this).attr("href") == window.location.hash) e.preventDefault();
  99. });
  100. </script>