Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Elastic.Markdown/Assets/pages-nav.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {$, $$} from "select-dom";
import {initHighlight} from "./hljs";
import {initCopyButton} from "./copybutton";
import {initTabs} from "./tabs";
import {initTocNav} from "./toc-nav";

type NavExpandState = {
current:string,
Expand Down Expand Up @@ -109,6 +113,34 @@ export function initNav() {
keepNavStateCallback();
keepNavPositionCallback();
}, true);

$$('a', pagesNav).forEach(a => {
a.addEventListener('click', (e) => {
e.preventDefault();
history.pushState(null, '', a.href);
const markdownContentContainer = $('.markdown-content');
markdownContentContainer.innerHTML = 'loading...';
const url = a.href;
fetch(url)
.then(response => response.text())
.then(text => {
const doc = new DOMParser().parseFromString(text, 'text/html')
const markdownContent = $('.markdown-content', doc);
const toc = $('#toc-nav', doc);
const tocContainer = $('#toc-nav');
if (toc && tocContainer) {
tocContainer.innerHTML = toc.innerHTML;
}
if (markdownContent && markdownContentContainer) {
markdownContentContainer.innerHTML = markdownContent.innerHTML;
initHighlight();
initCopyButton();
initTabs();
initTocNav();
}
});
});
});
}

initNav();
1 change: 0 additions & 1 deletion src/Elastic.Markdown/Slices/Layout/_PagesNav.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
data-current-page-parent-ids="@(string.Join(",",Model.ParentIds))"
@* used to invalidate session storage *@
data-current-navigation="@LayoutViewModel.CurrentNavigationId">

@(new HtmlString(Model.NavigationHtml))
</nav>
<script src="@Model.Static("pages-nav.js")"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/Slices/Layout/_TocTree.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inherits RazorSlice<NavigationViewModel>
<div class="pt-6 pb-20">
<div class="font-bold">Elastic Docs</div>
<ul class="block w-full">
<ul class="block">
@await RenderPartialAsync(_TocTreeNav.Create(new NavigationTreeItem
{
Level = Model.Tree.Depth,
Expand Down
Loading