Skip to content

Commit 96ebf2e

Browse files
committed
Dark mode: logo sketch background, iframe message passing
1 parent c3079b9 commit 96ebf2e

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

assets/logo_sketch.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<!DOCTYPE html>
22
<html><head>
3-
<style>*{margin:0;padding:0;overflow:hidden}body{background:#fff}canvas{display:block}</style>
3+
<style>*{margin:0;padding:0;overflow:hidden}body{background:#fff}canvas{display:block;background:#fff}</style>
44
</head><body>
55
<canvas id="canvas"></canvas>
6-
<script>window.Module={canvas:document.getElementById('canvas'),print:console.log,printErr:console.warn};</script>
6+
<script>
7+
window.Module={canvas:document.getElementById('canvas'),print:console.log,printErr:console.warn};
8+
window.addEventListener('message', function(e) {
9+
if (e.data === 'dark') document.body.style.background = '#1a1a2e';
10+
if (e.data === 'light') document.body.style.background = '#fff';
11+
});
12+
</script>
713
<script src="logo_sketch.js"></script>
814
</body></html>

assets/nav.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
(function() {
2+
// Prevent dark mode flash -- apply class before first paint
3+
try {
4+
if (localStorage.getItem('darkMode') === '1') document.documentElement.classList.add('dark-pre');
5+
} catch(e) {}
26
const SITE = 'https://processing-cpp.github.io';
37
const path = window.location.pathname;
48
const parts = path.replace(/\/$/, '').split('/').filter(Boolean);
@@ -56,6 +60,7 @@
5660
const style = document.createElement('style');
5761
style.id = 'nav-shared-style';
5862
style.textContent = `
63+
html.dark-pre body { background:#1a1a2e !important; }
5964
#site-nav {
6065
border-bottom: 1px solid #e0e0e0;
6166
padding: 0 2rem;
@@ -91,6 +96,13 @@
9196
if (document.querySelector('.syntax-block, .impl-block') &&
9297
!document.getElementById('ref-cm-loaded')) {
9398
const CDNJS = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16';
99+
// Preload hints for faster script loading
100+
[CDNJS + '/codemirror.min.js', CDNJS + '/mode/clike/clike.min.js',
101+
SITE + '/assets/cppmode-keywords.js', SITE + '/assets/cppmode.js'].forEach(href => {
102+
const l = document.createElement('link');
103+
l.rel = 'preload'; l.as = 'script'; l.href = href;
104+
document.head.appendChild(l);
105+
});
94106
function loadScript(src, cb) {
95107
const s = document.createElement('script'); s.src = src;
96108
s.onload = cb; document.head.appendChild(s);
@@ -154,6 +166,8 @@
154166
body.dark-mode .sidebar a.active { color:#e8b400 !important; font-weight:700; }
155167
body.dark-mode #nav-dark-btn { background:#313244 !important; color:#cdd6f4 !important; border-color:#45475a !important; }
156168
body.dark-mode .CodeMirror-gutters { background:#181825 !important; border-color:#313244 !important; }
169+
body.dark-mode #hero-preview, body.dark-mode #hero-preview iframe,
170+
body.dark-mode #logo-sketch-wrap, body.dark-mode #logo-sketch-wrap iframe { background:#1e1e2e !important; }
157171
body.dark-mode .CodeMirror-linenumber { color:#6c7086 !important; }
158172
body.dark-mode input, body.dark-mode select, body.dark-mode textarea { background:#181825 !important; color:#cdd6f4 !important; }
159173
body.dark-mode ::placeholder { color:#6c7086 !important; }
@@ -230,6 +244,10 @@
230244
document.querySelectorAll('.CodeMirror').forEach(el => {
231245
if (el.CodeMirror) el.CodeMirror.setOption('theme', on ? 'cppmode-dark' : 'cppmode');
232246
});
247+
// Tell sketch iframes about dark mode
248+
document.querySelectorAll('iframe').forEach(fr => {
249+
try { fr.contentWindow.postMessage(on ? 'dark' : 'light', '*'); } catch(e) {}
250+
});
233251
try { localStorage.setItem('darkMode', on ? '1' : '0'); } catch(e) {}
234252
}
235253
window.__toggleDark = function() {

0 commit comments

Comments
 (0)