Skip to content

Commit d2472c5

Browse files
authored
Add "theme switch" menu to top commits nav bar (#312)
1 parent 148ab88 commit d2472c5

File tree

7 files changed

+430
-439
lines changed

7 files changed

+430
-439
lines changed

doc/source/_static/css/custom.css

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ body.light-theme {
2525
body.dark-theme {
2626
/* Primary Colors */
2727
--text-color: #c9c9c9; /* Light Gray */
28-
--heading-color: red; /* Off-White */
28+
--heading-color: red; /* Off-White */
2929
--main-bg-color: #282c34; /* Charcoal Main Background */
3030
--sidebar-bg-color: rgba(40, 44, 52, 0.9); /* Charcoal (Slight transparency) */
3131
--border-color: #3e4451; /* Darker Border */
@@ -43,31 +43,27 @@ body.dark-theme {
4343

4444
/* --- 2. Apply Variables to Global Elements --- */
4545

46-
/* Apply to the main body and body wrapper */
4746
body {
4847
color: var(--text-color);
49-
background-color: var(--main-bg-color); /* Fallback if no background image */
48+
background-color: var(--main-bg-color);
5049
transition: background-color 0.3s, color 0.3s;
5150
}
5251

53-
/* Ensure headings use the heading color */
5452
h1, h2, h3, h4, h5, h6,
5553
div.document > h1, div.document > h2, div.document > h3 {
5654
color: var(--heading-color);
5755
}
5856

5957
/* --- 3. Sidebar Styling --- */
6058

61-
/* Target the main sidebar wrapper */
6259
div.sphinxsidebar {
6360
background: var(--sidebar-bg-color) !important;
6461
border-right: 1px solid var(--border-color);
65-
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2); /* Keep shadow dark */
62+
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
6663
color: var(--text-color);
6764
transition: background-color 0.3s, color 0.3s;
6865
}
6966

70-
/* Sidebar Headings */
7167
div.sphinxsidebar h1,
7268
div.sphinxsidebar h3,
7369
div.sphinxsidebar .caption {
@@ -78,28 +74,24 @@ div.sphinxsidebar .caption {
7874
font-size: 16pt;
7975
}
8076

81-
/* Sidebar Normal Links */
8277
div.sphinxsidebar a {
8378
color: var(--link-color);
8479
text-decoration: none;
8580
}
8681

87-
/* Sidebar Links on Hover */
8882
div.sphinxsidebar a:hover {
8983
color: var(--link-hover-color);
9084
text-decoration: underline;
9185
}
9286

93-
/* Fix Current/Active Navigation Links */
9487
div.sphinxsidebar li.toctree-l1.current > a,
9588
div.sphinxsidebar li.toctree-l2.current > a {
9689
font-weight: bold;
9790
color: var(--current-link-color) !important;
98-
border-left: 3px solid var(--link-color); /* Use the standard link color for the border */
91+
border-left: 3px solid var(--link-color);
9992
padding-left: 5px;
10093
}
10194

102-
/* Ensure the link text for all navigation items is dark/correct */
10395
div.sphinxsidebar ul li a, div.sphinxsidebar p {
10496
color: var(--text-color);
10597
padding-left: 8px;
@@ -128,7 +120,6 @@ div.sphinxsidebar ul li a, div.sphinxsidebar p {
128120

129121
.bodywrapper {
130122
background-color: var(--main-bg-color);
131-
/* Transition to smooth the background change when toggling background image */
132123
transition: background-color 0.3s;
133124
}
134125

@@ -142,12 +133,12 @@ body.dark-theme .bodywrapper .body {
142133

143134
/* --- 7. Random Theme Overrides --- */
144135

145-
/* Define the new CSS variables for random colors (they will be set via JS) */
136+
/* Define the new CSS variables for random colors (set via JS) */
146137
:root {
147-
--random-main-bg-color: #282c34; /* Default Dark */
148-
--random-text-color: #c9c9c9; /* Default Light Gray */
149-
--random-heading-color: #ffffff; /* Default White */
150-
--random-link-color: #92b0ff; /* Default Blue */
138+
--random-main-bg-color: #282c34;
139+
--random-text-color: #c9c9c9;
140+
--random-heading-color: #ffffff;
141+
--random-link-color: #92b0ff;
151142
--random-link-hover-color: #a8c1ff;
152143
--random-sidebar-bg-color: rgba(40, 44, 52, 0.9);
153144
--random-border-color: #3e4451;
@@ -164,8 +155,8 @@ body.custom-random-theme {
164155
--border-color: var(--random-border-color);
165156
--link-color: var(--random-link-color);
166157
--link-hover-color: var(--random-link-hover-color);
167-
--current-link-color: var(--random-heading-color); /* Use a bright color */
168-
--search-bg-color: var(--random-border-color); /* Use a darker color */
158+
--current-link-color: var(--random-heading-color);
159+
--search-bg-color: var(--random-border-color);
169160
--footer-bg-color: var(--random-footer-bg-color);
170161
--footer-text-color: var(--random-text-color);
171162

@@ -174,23 +165,20 @@ body.custom-random-theme {
174165
--commit-date-color: #ffcc00; /* Yellow */
175166
}
176167

177-
/* Ensure the bodywrapper also uses the random background color if background image is off */
178168
body.custom-random-theme .bodywrapper {
179169
background-color: var(--random-main-bg-color);
180170
}
181171

182172
/* --- 8. Custom Vertical Orange Gradient for bodywrapper --- */
183173

184-
/* Target the bodywrapper element for the gradient background */
185174
.bodywrapper .body {
186175
background-image: linear-gradient(
187176
to bottom,
188-
#FFF3E0 0%, /* Very Light Orange / Creamy */
189-
#FFB74D 50%, /* Medium Orange */
190-
#E65100 100% /* Dark Orange */
177+
#FFF3E0 0%,
178+
#FFB74D 50%,
179+
#E65100 100%
191180
) !important;
192181

193-
/* Fallback color for non-supporting browsers */
194182
background-color: #E65100;
195183
}
196184

@@ -207,43 +195,78 @@ div.body .caption {
207195

208196
#full-width-commit-banner {
209197
width: 100%;
210-
background-color: #333; /* Dark background for banner */
198+
background-color: #333;
211199
color: white;
212200
padding: 10px 0;
213-
text-align: left; /* Aligns the button */
201+
text-align: left;
214202
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
215-
position: relative; /* Essential for dropdown positioning */
216-
z-index: 1000; /* Ensure it stays on top */
203+
position: relative;
204+
z-index: 1000;
217205
}
218206

219-
#commit-dropdown-button {
220-
margin-left: 20px; /* Left align from page edge */
207+
/* Base style for banner buttons */
208+
.banner-button {
209+
margin-left: 20px;
221210
padding: 8px 15px;
222211
background-color: #555;
223212
color: white;
224213
border: none;
225214
cursor: pointer;
215+
margin-right: 10px; /* Space between buttons */
226216
}
227217

228-
#commit-dropdown-content {
218+
/* Base style for both dropdowns */
219+
.dropdown-content {
229220
position: absolute;
230-
left: 20px;
231-
top: 100%; /* Position below the button */
232-
background-color: white;
233-
color: black;
221+
top: 100%;
234222
border: 1px solid #ccc;
235223
max-height: 400px;
236224
overflow-y: auto;
237-
width: 300px;
238225
z-index: 1001;
239226
padding: 10px;
240227
}
241228

242-
/* Class to control the initial visibility */
243-
#commit-dropdown-content.commit-dropdown-hidden {
229+
/* Initial hidden state for the dropdown content (used by JS to toggle) */
230+
.commit-dropdown-hidden {
244231
display: none;
245232
}
246233

234+
/* Positioning the commit dropdown */
235+
#commit-dropdown-content {
236+
left: 20px;
237+
width: 300px;
238+
}
239+
240+
/* Positioning the theme dropdown (adjust '250px' based on layout/button width) */
241+
#theme-options-content {
242+
left: 250px;
243+
width: 180px;
244+
}
245+
246+
247+
/* Theme/Background options list formatting */
248+
#theme-options-content h3 {
249+
margin-top: 10px;
250+
margin-bottom: 5px;
251+
font-size: 1em;
252+
color: var(--heading-color);
253+
}
254+
255+
.theme-option-group {
256+
padding-left: 5px;
257+
margin-bottom: 15px;
258+
}
259+
260+
.theme-option-group p {
261+
margin: 3px 0;
262+
}
263+
264+
.theme-switch-link {
265+
color: var(--link-color) !important;
266+
text-decoration: none;
267+
font-size: 0.9em;
268+
}
269+
247270
#commit-search {
248271
width: 95%;
249272
padding: 5px;
@@ -254,7 +277,7 @@ div.body .caption {
254277
border-color: var(--border-color);
255278
}
256279

257-
/* --- 10. CSS Class Styles for Dynamic Content (Commits) --- */
280+
/* --- 10. CSS Class Styles for Dynamic Content (Commits and Dropdowns) --- */
258281

259282
/* Style for the short SHA link (used in renderCommits) */
260283
.commit-sha-link {
@@ -279,8 +302,8 @@ div.body .caption {
279302
text-decoration: underline;
280303
}
281304

282-
/* Ensure the dropdown content itself uses the theme colors correctly */
283-
body #commit-dropdown-content {
305+
/* Ensure ALL dropdown content uses the correct theme colors */
306+
body .dropdown-content {
284307
background-color: var(--main-bg-color);
285308
color: var(--text-color);
286309
border-color: var(--border-color);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Map page IDs to their corresponding background image URLs
2+
const BG_MAP = {
3+
'shades-games-club': 'the-big-issue',
4+
'first-event': 'first-event-second-game',
5+
'second-event': 'second-event',
6+
'third-event': 'third-event-beers-in-play',
7+
'fourth-event': 'fourth-event',
8+
'fifth-event': 'fifth-event',
9+
'sixth-event': 'sixth-event',
10+
catan: 'catan',
11+
chess: 'chess',
12+
'c-o-o-l-chess': 'cool-chess',
13+
harmegedo: 'harmegedo',
14+
'history-of-64-shades': 'history',
15+
quaternity: 'quaternity-wooden-set',
16+
'the-first-challenger': 'first-event-first-game',
17+
'top-pitfalls': 'top-pitfalls',
18+
'uno-show-em-no-mercy': 'uno-show-em-no-mercy',
19+
};
20+
21+
const BACKGROUND_KEY = 'sphinx_background_preference';
22+
23+
/**
24+
* Public function to turn the background image on or off.
25+
* Defined globally so the HTML `href="javascript:setBackground(...)` works.
26+
* @param {string} state - 'on' or 'off'
27+
*/
28+
window.setBackground = function (state) {
29+
const mainSection = document.querySelector('[role="main"] > section:first-child');
30+
if (!mainSection) return;
31+
32+
const pageId = mainSection.id;
33+
const bgUrl = BG_MAP[pageId];
34+
const body = document.body;
35+
const bodyWrapper = document.querySelector('.bodywrapper');
36+
37+
// The updateBackgroundLinks function is now in commit-banner.js,
38+
// but since that file is loaded first, we can rely on it being available.
39+
const updateBackgroundLinks = window.updateBackgroundLinks || function () {}; // Fallback
40+
41+
if (state === 'on' && bgUrl) {
42+
body.style.backgroundImage = `url('_static/images/backgrounds/${bgUrl}.jpg')`;
43+
body.style.backgroundSize = 'cover';
44+
body.style.backgroundAttachment = 'fixed';
45+
body.classList.add('background-on');
46+
47+
if (bodyWrapper) {
48+
bodyWrapper.style.background = 'transparent';
49+
}
50+
} else {
51+
body.style.backgroundImage = 'none';
52+
body.style.backgroundSize = '';
53+
body.style.backgroundAttachment = '';
54+
body.classList.remove('background-on');
55+
56+
if (bodyWrapper) {
57+
bodyWrapper.style.background = 'var(--main-bg-color)';
58+
}
59+
}
60+
61+
localStorage.setItem(BACKGROUND_KEY, state);
62+
updateBackgroundLinks(state);
63+
};
64+
65+
function loadBackgroundPreference() {
66+
const storedBackground = localStorage.getItem(BACKGROUND_KEY) || 'on';
67+
window.setBackground(storedBackground); // Use the global function
68+
}
69+
70+
// Wait for the document to fully load and load background preference
71+
document.addEventListener('DOMContentLoaded', function () {
72+
loadBackgroundPreference();
73+
});

0 commit comments

Comments
 (0)