Skip to content

Commit a781b29

Browse files
committed
Fine tuning
1 parent 578334d commit a781b29

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/Elastic.Markdown/Assets/main.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,45 @@ hljs.registerLanguage('apiheader', function() {
1818
hljs.addPlugin(mergeHTMLPlugin);
1919
hljs.highlightAll();
2020

21-
type NavState = { [key: string]: boolean };
22-
const PAGE_NAV_STATE_KEY = 'pagesNavState';
23-
const sessionState = JSON.parse(sessionStorage.getItem(PAGE_NAV_STATE_KEY)) as NavState
21+
type NavExpandState = { [key: string]: boolean };
22+
const PAGE_NAV_EXPAND_STATE_KEY = 'pagesNavState';
23+
const navState = JSON.parse(localStorage.getItem(PAGE_NAV_EXPAND_STATE_KEY)) as NavExpandState
2424

2525
function keepNavState(nav: HTMLElement) {
2626
const inputs = $$('input[type="checkbox"]', nav);
27-
if (sessionState) {
27+
if (navState) {
2828
inputs.forEach(input => {
2929
const key = input.id;
3030
if (input.dataset['shouldExpand'] === 'true') {
3131
input.checked = true;
3232
} else {
33-
input.checked = sessionState[key];
33+
input.checked = navState[key];
3434
}
3535
});
3636
}
3737
window.addEventListener('beforeunload', () => {
3838
const inputs = $$('input[type="checkbox"]', nav);
39-
const state: NavState = inputs.reduce((state: NavState, input) => {
39+
const state: NavExpandState = inputs.reduce((state: NavExpandState, input) => {
4040
const key = input.id;
4141
const value = input.checked;
4242
return { ...state, [key]: value};
4343
}, {});
44-
sessionStorage.setItem(PAGE_NAV_STATE_KEY, JSON.stringify(state));
44+
localStorage.setItem(PAGE_NAV_EXPAND_STATE_KEY, JSON.stringify(state));
4545
});
4646
}
4747

48+
type NavScrollPosition = number;
4849
const PAGE_NAV_SCROLL_POSITION_KEY = 'pagesNavScrollPosition';
49-
const scrollPosition = sessionStorage.getItem(PAGE_NAV_SCROLL_POSITION_KEY);
50+
const pagesNavScrollPosition: NavScrollPosition = parseInt(
51+
localStorage.getItem(PAGE_NAV_SCROLL_POSITION_KEY)
52+
);
5053

5154
function keepNavPosition(nav: HTMLElement) {
52-
if (scrollPosition) {
53-
nav.scrollTop = parseInt(scrollPosition);
55+
if (pagesNavScrollPosition) {
56+
nav.scrollTop = pagesNavScrollPosition;
5457
}
5558
window.addEventListener('beforeunload', () => {
56-
sessionStorage.setItem(PAGE_NAV_SCROLL_POSITION_KEY, nav.scrollTop.toString());
59+
localStorage.setItem(PAGE_NAV_SCROLL_POSITION_KEY, nav.scrollTop.toString());
5760
});
5861
}
5962

@@ -75,8 +78,8 @@ function isElementInViewport(el: HTMLElement): boolean {
7578
);
7679
}
7780

78-
7981
const pagesNav = $('#pages-nav');
80-
keepNavPosition(pagesNav);
8182
keepNavState(pagesNav);
83+
keepNavPosition(pagesNav);
84+
pagesNav.style.opacity = '1';
8285
scrollCurrentNaviItemIntoView(pagesNav, 100);

src/Elastic.Markdown/Slices/Layout/_TocTree.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@if (Model.IsRedesign)
44
{
5-
<div class="pt-6 pb-20 sticky">
5+
<div class="pt-6 pb-20">
66
<ul class="block w-full">
77
@await RenderPartialAsync(_TocTreeNav.Create(new NavigationTreeItem
88
{

src/Elastic.Markdown/Slices/Layout/_TocTreeNav.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="w-5">
1515
</div>
1616
<a
17-
class="block w-full py-1 text-sm leading-[1.2em] tracking-[-0.02em] hover:font-semibold @(isCurrent ? "font-bold text-blue-elastic" : string.Empty)"
17+
class="block py-1 text-sm leading-[1.2em] tracking-[-0.02em] hover:text-ink-dark @(isCurrent ? "text-blue-elastic!" : string.Empty)"
1818
href="@f.Url">
1919
@f.NavigationTitle
2020
</a>
@@ -50,7 +50,7 @@
5050
</label>
5151
<a
5252
href="@g.Index?.Url"
53-
class="block py-1 grow text-sm leading-[1.2em] tracking-[-0.02em] hover:font-semibold @(isCurrent ? "current font-bold text-blue-elastic" : string.Empty) ">
53+
class="block py-1 text-sm leading-[1.2em] tracking-[-0.02em] hover:text-ink-dark @(containsCurrent && g.Depth == 1 ? "font-bold" : string.Empty) @(isCurrent ? "current text-blue-elastic!" : string.Empty) ">
5454
@g.Index?.NavigationTitle
5555
</a>
5656
@if (g.NavigationItems.Count > 0)

src/Elastic.Markdown/Slices/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
@* <nav id="pages-nav-2" class="sticky top-22 w-60 overflow-x-hidden z-10 max-h-[calc(100vh-var(--spacing)*22)] overflow-y-auto"> *@
7171
@* @(new HtmlString(Model.NavigationHtml)) *@
7272
@* </nav> *@
73+
hello
7374
</aside>
7475
</div>
7576
<script src="@Model.Static("main.js")"></script>

0 commit comments

Comments
 (0)