|
| 1 | +<!-- Generate a nice TOC --> |
| 2 | +<script src="//code.jquery.com/jquery-1.12.4.min.js"></script> |
| 3 | +<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> |
| 4 | +<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.tocify/1.9.0/javascripts/jquery.tocify.min.js"></script> |
| 5 | +<!-- We do not need the tocify CSS because the asciidoc CSS already provides most of what we neeed --> |
| 6 | + |
| 7 | +<style> |
| 8 | +.tocify-header { |
| 9 | + font-style: normal; |
| 10 | + font-size: 90%; |
| 11 | +} |
| 12 | +.tocify-subheader { |
| 13 | + font-style: normal; |
| 14 | + font-size: 90%; |
| 15 | +} |
| 16 | +.tocify ul { |
| 17 | + margin: 0; |
| 18 | + } |
| 19 | +.tocify-focus { |
| 20 | + color: #7a2518; |
| 21 | + background-color: rgba(0, 0, 0, 0.1); |
| 22 | +} |
| 23 | +.tocify-focus > a { |
| 24 | + color: #7a2518; |
| 25 | +} |
| 26 | +</style> |
| 27 | + |
| 28 | +<script type="text/javascript"> |
| 29 | + $( document ).ready(function() { |
| 30 | + $('#project-bar').insertBefore('#header'); |
| 31 | + }); |
| 32 | + $(function () { |
| 33 | + // Add a new container for the tocify toc into the existing toc so we can re-use its |
| 34 | + // styling |
| 35 | + $("#toc").append("<div id='generated-toc'></div>"); |
| 36 | + $("#generated-toc").tocify({ |
| 37 | + extendPage: true, |
| 38 | + context: "#content", |
| 39 | + highlightOnScroll: true, |
| 40 | + showAndHide: true, |
| 41 | + hideEffect: "slideUp", |
| 42 | + showEffect: "slideDown", |
| 43 | + // Use the IDs that asciidoc already provides so that TOC links and intra-document |
| 44 | + // links are the same. Anything else might confuse users when they create bookmarks. |
| 45 | + hashGenerator: function(text, element) { |
| 46 | + return $(element).attr("id"); |
| 47 | + }, |
| 48 | + // Smooth scrolling doesn't work properly if we use the asciidoc IDs |
| 49 | + smoothScroll: false, |
| 50 | + // Set to 'none' to use the tocify classes |
| 51 | + theme: "none", |
| 52 | + // Handle book (may contain h1) and article (only h2 deeper) |
| 53 | + selectors: $( "#content" ).has( "h1" ).size() > 0 ? "h1,h2,h3,h4,h5" : "h2,h3,h4,h5", |
| 54 | + ignoreSelector: ".discrete" |
| 55 | + }); |
| 56 | + // Switch between static asciidoc toc and dynamic tocify toc based on browser size |
| 57 | + // This is set to match the media selectors in the asciidoc CSS |
| 58 | + // Without this, we keep the dynamic toc even if it is moved from the side to preamble |
| 59 | + // position which will cause odd scrolling behavior |
| 60 | + var handleTocOnResize = function() { |
| 61 | + if ($(document).width() < 768) { |
| 62 | + $("#generated-toc").hide(); |
| 63 | + $(".sectlevel0").show(); |
| 64 | + $(".sectlevel1").show(); |
| 65 | + } |
| 66 | + else { |
| 67 | + $("#generated-toc").show(); |
| 68 | + $(".sectlevel0").hide(); |
| 69 | + $(".sectlevel1").hide(); |
| 70 | + } |
| 71 | + } |
| 72 | + $(window).resize(handleTocOnResize); |
| 73 | + handleTocOnResize(); |
| 74 | + }); |
| 75 | +</script> |
0 commit comments