FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nullrun-docs/docs/javascripts/extra.js at master · nullrunio/nullrun-docs · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
nullrunio
/
nullrun-docs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nullrun-docs
/
docs
/
javascripts
/
extra.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
139 lines (123 loc) · 5.91 KB
Breadcrumbs
nullrun-docs
/
docs
/
javascripts
/
extra.js
Copy path
File metadata and controls
139 lines (123 loc) · 5.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// NullRun docs — small JS hooks.
//
// Today:
// 1. Theme picker (Helix-style popup) — overrides/partials/header.html
// renders a button + dropdown of {auto, light, dark, navy}. The
// chosen theme is applied by setting Material's data-md-color-*
// attributes on the <body> element (NOT <html> — Material reads
// from <body>). State is persisted to localStorage under both our
// key (`nullrun-docs-theme`) and Material's own (`__palette`).
//
// 2. Sidebar hide toggle — bound to the menu-bar hamburger. Toggles
// a `nr-sidebar-hidden` body class that hides `.md-sidebar--primary`.
// State persisted to localStorage so the choice survives reloads.
//
// 3. Section numbered-title caret auto-flips on open/closed via the
// `nr-collapsible` class we add in JS (Material's stock behaviour
// is unchanged — we just rotate the caret visually).
//
// The menu-bar title h1 is intentionally hidden — the menu-bar is just
// an icon strip; section context lives in the left sidebar. The
// title-sync hook from earlier revisions has been removed (dead code).
const
NR_THEME_KEY
=
"nullrun-docs-theme"
;
/* ── 1. Theme picker ─────────────────────────────────────────────── */
(
function
initThemePicker
(
)
{
const
buttons
=
document
.
querySelectorAll
(
".nr-theme-btn"
)
;
if
(
!
buttons
.
length
)
return
;
// Map our user-facing theme names to Material's expected values.
// "navy" is our custom addition; Material only knows "default" +
// "slate". For navy we apply slate + a body class so our CSS
// overrides win by specificity.
const
themeMap
=
{
light
:
{
scheme
:
"default"
,
primary
:
"black"
,
accent
:
"grey"
,
bodyClass
:
""
}
,
dark
:
{
scheme
:
"slate"
,
primary
:
"white"
,
accent
:
"grey"
,
bodyClass
:
""
}
,
navy
:
{
scheme
:
"slate"
,
primary
:
"white"
,
accent
:
"grey"
,
bodyClass
:
"nr-theme-navy"
}
,
}
;
function
clearBodyClasses
(
)
{
document
.
body
.
classList
.
remove
(
"nr-theme-navy"
)
;
}
function
applyTheme
(
name
)
{
const
t
=
themeMap
[
name
]
;
if
(
!
t
)
return
;
// Material reads these from <body>, not <html>.
clearBodyClasses
(
)
;
document
.
body
.
setAttribute
(
"data-md-color-scheme"
,
t
.
scheme
)
;
document
.
body
.
setAttribute
(
"data-md-color-primary"
,
t
.
primary
)
;
document
.
body
.
setAttribute
(
"data-md-color-accent"
,
t
.
accent
)
;
if
(
t
.
bodyClass
)
document
.
body
.
classList
.
add
(
t
.
bodyClass
)
;
// Persist to localStorage so the choice survives navigation.
try
{
localStorage
.
setItem
(
NR_THEME_KEY
,
name
)
;
// Also update Material's __palette so its runtime stays in sync.
const
existing
=
localStorage
.
getItem
(
"__palette"
)
;
let
parsed
=
{
}
;
try
{
parsed
=
existing
?
JSON
.
parse
(
existing
)
:
{
}
;
}
catch
(
e
)
{
parsed
=
{
}
;
}
if
(
!
parsed
.
color
)
parsed
.
color
=
{
}
;
parsed
.
color
.
scheme
=
t
.
scheme
;
parsed
.
color
.
primary
=
t
.
primary
;
parsed
.
color
.
accent
=
t
.
accent
;
localStorage
.
setItem
(
"__palette"
,
JSON
.
stringify
(
parsed
)
)
;
}
catch
(
e
)
{
/* ignore */
}
}
function
restoreTheme
(
)
{
let
saved
=
null
;
try
{
saved
=
localStorage
.
getItem
(
NR_THEME_KEY
)
;
}
catch
(
e
)
{
/* ignore */
}
if
(
saved
&&
themeMap
[
saved
]
)
{
applyTheme
(
saved
)
;
return
saved
;
}
return
null
;
}
// Restore on first paint (before any flashes of unstyled content).
restoreTheme
(
)
;
buttons
.
forEach
(
(
btn
)
=>
{
btn
.
addEventListener
(
"click"
,
(
ev
)
=>
{
ev
.
preventDefault
(
)
;
const
theme
=
btn
.
getAttribute
(
"data-theme"
)
;
if
(
theme
===
"auto"
)
{
// Reset to OS preference.
try
{
localStorage
.
removeItem
(
NR_THEME_KEY
)
;
}
catch
(
e
)
{
/* ignore */
}
const
systemDark
=
window
.
matchMedia
(
"(prefers-color-scheme: dark)"
)
.
matches
;
applyTheme
(
systemDark
?
"dark"
:
"light"
)
;
}
else
{
applyTheme
(
theme
)
;
}
// Close the popup after selection.
const
popup
=
btn
.
closest
(
".nr-theme"
)
;
if
(
popup
)
popup
.
blur
(
)
;
}
)
;
}
)
;
}
)
(
)
;
/* ── 2. Sidebar hide toggle ─────────────────────────────────────── */
(
function
initSidebarHide
(
)
{
const
KEY
=
"nullrun-docs-sidebar"
;
const
btn
=
document
.
querySelector
(
".nr-sidebar-toggle"
)
;
if
(
!
btn
)
return
;
function
apply
(
state
)
{
if
(
state
===
"hidden"
)
{
document
.
body
.
classList
.
add
(
"nr-sidebar-hidden"
)
;
btn
.
setAttribute
(
"aria-pressed"
,
"true"
)
;
}
else
{
document
.
body
.
classList
.
remove
(
"nr-sidebar-hidden"
)
;
btn
.
setAttribute
(
"aria-pressed"
,
"false"
)
;
}
}
let
saved
=
null
;
try
{
saved
=
localStorage
.
getItem
(
KEY
)
;
}
catch
(
e
)
{
/* ignore */
}
if
(
saved
===
"hidden"
||
saved
===
"visible"
)
apply
(
saved
)
;
btn
.
addEventListener
(
"click"
,
(
)
=>
{
const
willHide
=
!
document
.
body
.
classList
.
contains
(
"nr-sidebar-hidden"
)
;
apply
(
willHide
?
"hidden"
:
"visible"
)
;
try
{
localStorage
.
setItem
(
KEY
,
willHide
?
"hidden"
:
"visible"
)
;
}
catch
(
e
)
{
/* ignore */
}
}
)
;
}
)
(
)
;
/* ── 3. Section caret toggling ─────────────────────────────────────
Material's `navigation.sections` already wires up section collapse
via the chevron on the right. We add a `nr-collapsible` class so
the CSS knows these are accordion sections (vs. plain links). */
(
function
initSectionCaret
(
)
{
document
.
querySelectorAll
(
".md-nav--primary .md-nav__item--section"
)
.
forEach
(
(
item
)
=>
{
item
.
classList
.
add
(
"nr-collapsible"
)
;
}
)
;
}
)
(
)
;
console
.
info
(
"[nullrun-docs] extra.js loaded."
)
;
Back
|
FazBrowse Home
|
New Git URL