Skip to content

Stable and fail-safe Night Mode Toggle Switch code for HTML websites and apps.

Latest
Compare
Choose a tag to compare
@Dorson Dorson released this 22 Apr 07:26
· 1 commit to master since this release
10dd683

In this version: the code logic for the Dark Mode color switch is now hardened against possible failure situations, where the data input of the expected variables were missing, corrupted, false, or faked.

The memory recall function is now also hardened against possible exception cases, where the browser or the coder accidentally would corrupt expected variable inputs.

Actively decided NOT to check for the classList of the HTML Tags on memory recall, because the classList.contains command can AND does fail hard by itself, if the Tag is not yet loaded.

During DOM load the classList.contains command hangs the JS scripts for no reason, if we feed it wrong data during our testing process. Probably a browser bug. On false input the classList.contains command produces an error that is much, much larger, than having two CSS classes inside of the same HTML tag twice. Having CSS classes twice for the same tag breaks nothing. But checking for false CSS classes can break the script. It's a paradox :-) So we avoid it !

The code checks for this exception case during the switch function, so we do not need to do it during the memory recall, where bugs could be a lot more dangerous.

One could never know who will use this night mode switch in what type of devices.

Being fail-safe is better for devices that sustain human life, or safety.

The future possible failure scenario is when the browser will not recognize the JavaScript commands in 20 years. Web standards change, nothing is fail-safe in the long term, or on the long enough timeline !

Happy Color Switching everyone !