Page MenuHomeFreeBSD

website: fix light-dark themes switch
ClosedPublic

Authored by vladlen on Sun, May 17, 7:35 PM.
Tags
Referenced Files
Unknown Object (File)
Mon, May 25, 4:39 AM
Unknown Object (File)
Sun, May 24, 4:08 PM
Unknown Object (File)
Sun, May 24, 1:06 AM
Unknown Object (File)
Sat, May 23, 4:46 AM
Unknown Object (File)
Fri, May 22, 10:38 PM
Unknown Object (File)
Fri, May 22, 5:19 AM
Unknown Object (File)
Fri, May 22, 1:10 AM
Unknown Object (File)
Thu, May 21, 10:20 PM
Subscribers

Details

Summary

Maybe I'm missing something, but I couldn't find any code that persists the theme state after switching. In my browsers, the theme always resets to light on the next page.
I added a tiny JavaScript snippet that saves the checkbox state in localStorage on its change, and restores it on page load.

This implementation avoids cookies (no server overhead, no expiry), respects the existing pure‑CSS theme switching (.theme-switch:checked ~ #page), and is self‑contained without polluting the global scope.

This patch fixes https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295341

Diff Detail

Repository
R9 FreeBSD doc repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

vladlen created this revision.

Put it in the header and as a separate file please.

ziaee added inline comments.
website/themes/beastie/layouts/baseof.html
7 ↗(On Diff #177980)

Maybe clearer?

For me is ok, but please, put in an external javascript file and add it in the head

JavaScript code moved to separate file
website/themes/beastie/assets/js/theme-chooser.js

JS code is called from <head> of the every page.

for me is ok, but the JavaScript is yours, put your name in the copyright :)

This revision is now accepted and ready to land.Tue, May 19, 8:20 PM

@vladlen, can we move this?

Oh, I missed this Accept. I'll change copyrigth and commit.

This revision was automatically updated to reflect the committed changes.