Theme¶
Source code: src/yui_theme.js
The theme has three states, and only two of them are written down. An explicit
choice of the user writes data-theme on the root element. The default setting
writes nothing, and the preference of the operating system decides.
yui_theme_now()¶
Gives the theme that is active, as "dark" or "light". It reads
data-theme of the root element, and it reads the preference of the operating
system when the attribute is absent. Without a DOM it gives "light".
yui_is_dark()¶
Tells if the application draws dark.
yui_watch_theme(gobj, event)¶
Follows the theme, and sends event to gobj on every change, with the payload
{theme}. The default event is EV_THEME.
It watches both sources: the attribute data-theme, with a
MutationObserver, and the preference of the operating system, which is the
live source while the attribute is absent.
Returns a handle with disconnect(), or null where there is no DOM.
priv.theme_observer = yui_watch_theme(gobj);
…
if(priv.theme_observer) {
priv.theme_observer.disconnect();
priv.theme_observer = null;
}The gclass must declare the event in its state machine, and it must disconnect
the observer in mt_destroy.