diff --git a/input/Search.cshtml b/input/Search.cshtml index 42bb5e5..09ee144 100644 --- a/input/Search.cshtml +++ b/input/Search.cshtml @@ -10,76 +10,3 @@ ShowInNavigation: false
- -@section Scripts -{ - -} diff --git a/input/_Layout.cshtml b/input/_Layout.cshtml index aeaafbe..96efb3d 100644 --- a/input/_Layout.cshtml +++ b/input/_Layout.cshtml @@ -36,6 +36,7 @@ + @if (Context.GetBool(WebKeys.GenerateSearchIndex)) @@ -43,6 +44,7 @@ + } @await RenderSectionAsync(SectionNames.Head, false) @@ -231,126 +233,6 @@ - - - @await RenderSectionAsync(SectionNames.Scripts, false) @await Html.PartialAsync("_Scripts") diff --git a/input/assets/js/docable.js b/input/assets/js/docable.js new file mode 100644 index 0000000..a8f2c9a --- /dev/null +++ b/input/assets/js/docable.js @@ -0,0 +1,116 @@ +$(document).ready(function() { + quicklink.listen(); + + // Bootstrap tooltips + $('[data-toggle="tooltip"]').tooltip(); + + // Keeps the sidebars in view on wider viewports + let left = null; + let leftParent = null; + let right = null; + let rightParent = null; + function stickSidebars() + { + if (left == null) { + left = $('#left-sidebar'); + right = $('#right-sidebar'); + } + if (left.length) { + if (window.innerWidth >= 768) { + if (leftParent == null) { + leftParent = left.parent()[0]; + } + if (leftParent) { + let leftRect = leftParent.getBoundingClientRect(); + stickSidebar(left, leftRect); + } + } else { + left.css('position', 'relative'); + if (left.css('bottom') != 0) { + left.css('bottom', '0'); + } + } + } + if (right.length) { + if (window.innerWidth >= 768) { + if (rightParent == null) { + rightParent = right.parent()[0]; + } + if (rightParent) { + let rightRect = rightParent.getBoundingClientRect(); + stickSidebar(right, rightRect); + } + } else { + right.css('position', 'relative'); + if (right.css('bottom') != 0) { + right.css('bottom', '0'); + } + } + } + } + function stickSidebar(sidebar, rect) { + // Bottom + if (rect.bottom > window.innerHeight) { + sidebar.css('bottom', rect.bottom - window.innerHeight + "px"); + } else { + sidebar.css('bottom', 0); + } + // Top + if (rect.top < 0) { + sidebar.css('position', 'sticky'); + } else { + sidebar.css('position', 'absolute'); + } + } + $(window).on("load", function() { + stickSidebars(); + }); + $(window).scroll(function() { + stickSidebars(); + }); + $(window).resize(function() { + stickSidebars(); + }) + + // Mermaid diagrams + mermaid.initialize( + { + flowchart: + { + useMaxWidth: false + }, + startOnLoad: false, + cloneCssStyles: false + }); + mermaid.init(undefined, ".mermaid"); + + // Remove the max-width setting that Mermaid sets + var mermaidSvg = $('.mermaid svg'); + mermaidSvg.addClass('img-fluid'); + mermaidSvg.css('max-width', ''); + + // Make it scrollable + var target = document.querySelector(".mermaid svg"); + if(target !== null) + { + var panZoom = window.panZoom = svgPanZoom(target, { + zoomEnabled: true, + controlIconsEnabled: true, + fit: true, + center: true, + maxZoom: 20, + zoomScaleSensitivity: 0.6 + }); + + // Do the reset once right away to fit the diagram + panZoom.resize(); + panZoom.fit(); + panZoom.center(); + + $(window).resize(function(){ + panZoom.resize(); + panZoom.fit(); + panZoom.center(); + }); + } +}); diff --git a/input/assets/js/search.js b/input/assets/js/search.js new file mode 100644 index 0000000..2dd6ce0 --- /dev/null +++ b/input/assets/js/search.js @@ -0,0 +1,71 @@ +function runSearch(query) { + // Clear previous search results + $("#search-results").empty(); + + // If the search term is less than 2 characters, wait until the user types some more stuff + if (query.length < 2) + { + return; + } + + // Update the URL so that the user can come back to these results + var url = new URL(window.location.href); + url.searchParams.set("query", query); + window.history.replaceState(url.href, "", url.href); + + // Tell Lunr to run the search + search.search(query, function(results) + { + // Set up for scroll to text fragment on results links + // https://github.com/WICG/scroll-to-text-fragment + var highlight = "#:~:" + query.split(" ").map(term => { + if(term.includes("^")) + term = term.slice(0, term.indexOf("^")); + if(term.includes("~")) + term = term.slice(0, term.indexOf("~")); + if(term.includes(":")) + term = term.slice(term.indexOf(":")+1); + return "text=" + term.replace("*", "").replace("+", "").replace("-", ""); + }).join("&"); + + // Prepare output formatting + var listHtml = "