News for hackers. Stuff that matters.
Re:Using Dark Mode in CSS with MacOS Mojave by morley on Thursday October 25, 2018 @08:33AM (#18300371)
This is why I think they should focus on exposing the dark mode setting in Javascript instead of CSS.

Sites that support dark mode should (and will almost always) have a toggle for it. It'd be better if this setting helped _inform_ the default initial state rather than _forcing_ a choice on you. To me, that's a lot easier done with a Javascript API than CSS.

Re:Using Dark Mode in CSS with MacOS Mojave by yunyu on Thursday October 25, 2018 @08:37AM (#18300393)
You'd be able to do this with the matchMedia API: https://developer.mozilla.org/en-US/docs/Web/API/Window/matc...
Re:Using Dark Mode in CSS with MacOS Mojave by morley on Thursday October 25, 2018 @10:59AM (#18301391)
I didn't know about that, thanks for that!
Re:Using Dark Mode in CSS with MacOS Mojave by stephenr on Thursday October 25, 2018 @10:53AM (#18301322)
More javascript is almost never the best solution to any problem, particular when it’s shown that css can achieve the same result.
Re:Using Dark Mode in CSS with MacOS Mojave by morley on Thursday October 25, 2018 @11:00AM (#18301398)
My argument is that CSS doesn't achieve the same result; it forces one particular mode on you instead of allowing a choice.
Re:Using Dark Mode in CSS with MacOS Mojave by stephenr on Thursday October 25, 2018 @11:11AM (#18301487)
You have all the choice in the world. Use whatever tech you want (browser js, server side templating, client side xslt, etc) to have an attribute on the body element indicating opt-in status, and use that in your media query to target only the users who want it.

With the css solution it’s doable on a site that has no javascript.

Re:Using Dark Mode in CSS with MacOS Mojave by int_19h on Thursday October 25, 2018 @02:57PM (#18303548)
The right place for the switch in this case is the browser. The browser should have a button for light/dark/system, defaulting to system. And CSS should follow that.

JS should not be involved, and we don't need every site to have its own version of the switch, located in a different place and looking different.

Re:Using Dark Mode in CSS with MacOS Mojave by reaperducer on Thursday October 25, 2018 @04:12PM (#18304188)
You don't need Javascript to implement a switch that changes from light mode to dark mode. That can be easily done in CSS. I've done it on web sites to switch to a high-contrast color scheme for people with vision difficulties.
Re:Using Dark Mode in CSS with MacOS Mojave by codazoda on Thursday October 25, 2018 @09:24AM (#18300692)
You could easily apply or remove the css via Javascript to allow enable / disable of the feature.
Re:Using Dark Mode in CSS with MacOS Mojave by giobox on Thursday October 25, 2018 @11:06AM (#18301438)
Exactly. This is going to be the simplest browser extension anyone has ever written, if someone hasn’t done so already.