Skip to content

Commit 790e4f9

Browse files
Dan doc nav no scroll (#1388)
1 parent c0fdeb0 commit 790e4f9

File tree

6 files changed

+126
-36
lines changed

6 files changed

+126
-36
lines changed

pgml-dashboard/src/components/cms/index_link/template.html

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
<%
2+
let turbo_action_level_1 = r#"data-action="click->navigation-left-nav-docs#onNavigateManageLevel1" "#;
3+
let turbo_action_high_levels = r#"data-action="click->navigation-left-nav-docs#onNavigateManageHighLevels" "#;
4+
%>
15

2-
<div class="nav flex-column" role="tablist" aria-orientation="vertical" data-controller="cms-index-link">
6+
<div class="nav flex-column cms-level-<%- level %>" role="tablist" aria-orientation="vertical" data-controller="cms-index-link" data-level="<%- level %>">
37
<%
48
let color = if active {
59
"purple"
@@ -11,14 +15,14 @@
1115
%>
1216
<% if level == 1 {%>
1317
<div class="d-flex flex-row gap-2 align-items-center">
14-
<div class="menu-item flex-grow-1">
15-
<a class='d-block p-2 <% if active {%><%- String::from("active") %><% } %>' href="<%- href %>">
18+
<div class="menu-item flex-grow-1" data-navigation-left-nav-docs-target="level1Container">
19+
<a data-turbo-is-visitable class='d-block p-2 <% if active {%><%- String::from("active") %><% } %>' href="<%- href %>" <%- turbo_action_level_1 %> data-navigation-left-nav-docs-target="level1Link">
1620
<span class="text-wrap"><%- title %></span>
1721
</a>
1822
</div>
1923
</div>
2024
<% } else {%>
21-
<a class="nav-link ps-1 text-break <%- color %>" href="<%- href %>"><%- title %></a>
25+
<a data-turbo-is-visitable class="nav-link ps-1 text-break <%- color %>" href="<%- href %>" <%- turbo_action_high_levels %> data-navigation-left-nav-docs-target="highLevels"><%- title %></a>
2226
<% } %>
2327

2428
<% } else {
@@ -37,22 +41,22 @@
3741

3842
<% if level == 1 {%>
3943
<div class="menu-item flex-grow-1 d-flex flex-row align-items-center">
40-
<div class='w-100 d-flex flex-row gap-2 align-items-start <% if active || open {%><%- String::from("active") %><% } %> justify-content-between'>
41-
<a class='d-block p-2' href="<%- href %>">
44+
<div class='w-100 d-flex flex-row gap-2 align-items-start <% if active || open {%><%- String::from("active") %><% } %> justify-content-between doc-left-nav-level1-link-container' data-navigation-left-nav-docs-target="level1Container">
45+
<a data-turbo-is-visitable class='d-block p-2' href="<%- href %>" <%- turbo_action_level_1 %> data-navigation-left-nav-docs-target="level1Link">
4246
<span class="text-wrap"><%- title %></span>
4347
</a>
4448
<div class="pt-2">
45-
<span class="material-symbols-outlined rotate-on-aria-expanded text-white" data-bs-toggle="collapse" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>">expand_more</span>
49+
<span class="material-symbols-outlined rotate-on-aria-expanded text-white" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>" data-action="click->navigation-left-nav-docs#expand">expand_more</span>
4650
</div>
4751
</div>
4852
</div>
4953
<% } else {%>
5054
<span class="ps-1 py-0 d-flex justify-content-between align-items-start text-break" >
51-
<a class="nav-link px-0 text-break <%- color %>" href="<%- href %>">
55+
<a data-turbo-is-visitable class="nav-link px-0 text-break <%- color %>" href="<%- href %>" <%- turbo_action_high_levels %> data-navigation-left-nav-docs-target="highLevels">
5256
<span class="text-wrap"><%- title %></span>
5357
</a>
5458
<div class="pt-2">
55-
<span class="material-symbols-outlined rotate-on-aria-expanded" data-bs-toggle="collapse" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>">expand_more</span>
59+
<span class="material-symbols-outlined rotate-on-aria-expanded" href="#doc-<%= id %>" role="button" aria-expanded="<%- aria %>" aria-controls="doc-<%= id %>" data-action="click->navigation-left-nav-docs#expand">expand_more</span>
5660
</div>
5761
</span>
5862
<% } %>

pgml-dashboard/src/components/layouts/head/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
7474

7575
<script async type="nomodule" src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
76-
<script defer type="module" src="/dashboard/static/js/libs/turbo-7.3.0.min.js"></script>
76+
<script defer type="module" src="/dashboard/static/js/libs/turbo-7.3.0.custom.min.js"></script>
7777

7878
<!-- Code Mirror -->
7979
<script defer type="module" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js"></script>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { Controller } from "@hotwired/stimulus";
2+
3+
export default class extends Controller {
4+
static targets = [
5+
"level1Container",
6+
"level1Link",
7+
"highLevels"
8+
];
9+
10+
// After page update we reset scroll position of nave back to where it was
11+
connect() {
12+
let nav = document.getElementsByClassName("doc-leftnav")
13+
if (nav.length > 0) {
14+
let position = nav[0].getAttribute("data-scroll")
15+
nav[0].scrollTop = position
16+
}
17+
}
18+
19+
// trubo-frame permanent breakes bootstrap data attribute collapse for aria
20+
// so we manually controll collapse
21+
expand(e) {
22+
let aria = e.currentTarget.getAttribute("aria-expanded")
23+
let id = e.currentTarget.getAttribute("aria-controls")
24+
25+
let bsCollapse = bootstrap.Collapse.getOrCreateInstance(document.getElementById(id))
26+
if (aria === "true") {
27+
bsCollapse.hide()
28+
e.currentTarget.setAttribute("aria-expanded", "false")
29+
} else {
30+
bsCollapse.show()
31+
e.currentTarget.setAttribute("aria-expanded", "true")
32+
}
33+
}
34+
35+
// Activly manage nav state for level 1 links
36+
onNavigateManageLevel1(e) {
37+
this.removeAllActive()
38+
39+
let container = e.currentTarget.closest("div")
40+
container.classList.add("active")
41+
42+
e.currentTarget.classList.add("active")
43+
44+
this.preventScrollOnNav()
45+
}
46+
47+
// Activly manage nav state for high level links
48+
onNavigateManageHighLevels(e) {
49+
this.removeAllActive()
50+
51+
let container = e.currentTarget.closest('div[data-level="1"]')
52+
let menu = container.querySelector(".menu-item")
53+
let link = menu.querySelector(".doc-left-nav-level1-link-container")
54+
55+
link.classList.add("active")
56+
57+
e.currentTarget.classList.add("purple")
58+
59+
this.preventScrollOnNav()
60+
}
61+
62+
// trubo-frame permanent scrolles nav to top on navigation so we capture the scrroll position prior
63+
// to updating the page so after we can set the scroll position back to where it was
64+
preventScrollOnNav() {
65+
let nav = document.getElementsByClassName("doc-leftnav")
66+
if (nav.length > 0) {
67+
let position = nav[0].scrollTop;
68+
nav[0].setAttribute("data-scroll", position)
69+
}
70+
}
71+
72+
// Helper function to quickly remove all state styling
73+
removeAllActive() {
74+
for(let i = 0; i < this.highLevelsTargets.length; i++) {
75+
this.highLevelsTargets[i].classList.remove("purple")
76+
}
77+
78+
for (let i = 0; i < this.level1ContainerTargets.length; i++) {
79+
this.level1ContainerTargets[i].classList.remove("active")
80+
}
81+
82+
for (let i = 0; i < this.level1LinkTargets.length; i++) {
83+
this.level1LinkTargets[i].classList.remove("active")
84+
}
85+
}
86+
}

pgml-dashboard/src/components/navigation/left_nav/docs/template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
%>
2525

2626
<% if !mobile { %>
27-
<div class="doc-leftnav-container" data-controller="navigation-left-nav-docs">
28-
<nav class="doc-leftnav" data-action="scroll->navigation-left-nav-docs#showScrollbar">
27+
<div class="doc-leftnav-container" id="cart-counter" data-controller="navigation-left-nav-docs" data-turbo-permanent>
28+
<nav class="doc-leftnav" data-scroll="0">
2929
<div class="d-flex flex-column justify-content-between">
3030
<div class="d-xl-flex flex-column py-4">
3131
<div class="pt-2 ps-2 d-flex flex-column gap-4_5">

pgml-dashboard/static/js/libs/turbo-7.3.0.custom.min.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pgml-dashboard/static/js/libs/turbo-7.3.0.min.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy