Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions landing-pages/site/layouts/_partials/hooks/head-end.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@

<meta name="description" content="{{ .Description | default $.Site.Params.description }}" />

{{/* Early theme initialization to prevent FOUC and ensure animation gets correct theme */}}
{{ if .Site.Params.ui.showLightDarkModeMenu -}}
<script>
(function() {
'use strict';
const themeKey = 'td-color-theme';
const getStoredTheme = () => localStorage.getItem(themeKey);
const getPreferredTheme = () => {
const storedTheme = getStoredTheme();
if (storedTheme) {
return storedTheme;
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
};
const setTheme = theme => {
if (theme === 'auto') {
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'));
} else {
document.documentElement.setAttribute('data-bs-theme', theme);
}
};
setTheme(getPreferredTheme());
})();
</script>
{{ end -}}

<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
Expand Down
15 changes: 15 additions & 0 deletions landing-pages/src/js/headerAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ export function initHeaderAnimation() {
});
};

// Listen for theme changes and redraw
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'data-bs-theme') {
// Theme changed, sketch.draw() will be called automatically on next frame
// No need to do anything here as p5 continuously calls draw()
}
});
});

observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['data-bs-theme']
});

sketch.windowResized = debounce(() => {
const positionInfo = canvas.getBoundingClientRect();
const vw = positionInfo.width; // viewport width
Expand Down
Loading