Allows the ZnetDK 4 Mobile application to be displayed with a dark theme.
- This module add a "Theme" button to the User Panel. When clicked, a modal dialog is displayed to apply the dark theme or to come back to the light theme.
- The favorite theme is saved in database for the logged in user.
- The
Autobutton when selected, makes the theme selected automatically according to the selected theme at Operating System or Web browser level. - The
data-themeattribute is added to thebodyelement and is useful to know which theme is currently applied ('dark'or'light'). - The jQuery event
z4mthemechooserchangeis triggered by the HTML body element each time the theme has changed.
- ZnetDK 4 Mobile version 3.2 or higher,
- A MySQL database is configured to store the application data,
- PHP version 7.4 or higher,
- Authentication is enabled
(
CFG_AUTHENT_REQUIREDisTRUEin the App'sconfig.php).
- Copy module's code in the
./engine/modules/z4m_themechooser/subdirectory, - Edit the App's
config.phplocated in the./applications/default/app/subfolder and set the path or URL of your dark theme CSS stylesheet to theMOD_Z4M_THEMECHOOSER_CSS_DARK_THEMEPHP constant.
If the app logo to be displayed for dark theme is different from the one for light theme, also set the path of your light and dark logos to theMOD_Z4M_THEMECHOOSER_LOGO_LIGHT_THEMEandMOD_Z4M_THEMECHOOSER_LOGO_DARK_THEMEPHP constants.
For example:
define('MOD_Z4M_THEMECHOOSER_CSS_DARK_THEME', 'applications/'.ZNETDK_APP_NAME.'/public/css/theme-dark.css');
// Optional: the paths of the light and dark logos
define('MOD_Z4M_THEMECHOOSER_LOGO_LIGHT_THEME', 'applications/'.ZNETDK_APP_NAME.'/public/images/logo-light.png');
define('MOD_Z4M_THEMECHOOSER_LOGO_DARK_THEME', 'applications/'.ZNETDK_APP_NAME.'/public/images/logo-dark.png');- In option, If the app logo to be displayed for dark theme is different from the one for light theme,
edit the
locale.phpscript of your application and set theLC_HEAD_IMG_LOGOPHP constant to the path of the dark logo if dark theme is to be displayed.
For example:
/* Heading images */
use z4m_themechooser\mod\controller\Users;
if (Users::getUserTheme() === MOD_Z4M_THEMECHOOSER_CSS_DARK_THEME) {
define('LC_HEAD_IMG_LOGO', ZNETDK_ROOT_URI . MOD_Z4M_THEMECHOOSER_LOGO_DARK_THEME);
} else {
define('LC_HEAD_IMG_LOGO', ZNETDK_ROOT_URI . MOD_Z4M_THEMECHOOSER_LOGO_LIGHT_THEME);
}When Auto is selected in the Theme modal dialog and the color scheme is dark at OS or User Agent level,
a white background is displayed a few milliseconds before the dark theme be applied.
To avoid this flicker effect:
- Imports the
prevent_flash_effect.phpscript at the end of themobile_favicons.phpscript specified via theCFG_MOBILE_FAVICON_CODE_FILENAMEconstant. For example:
<?php require 'z4m_themechooser/mod/view/fragment/prevent_flash_effect.php'; ?>- Next, surrounds the light theme styles by the
:root:has(body[data-theme="light"])selector. For Example:
:root:has(body[data-theme="light"]) {
color-scheme: light;
/* Other styles of the light theme... */
body {
--z4m-light-primary:#0b78d1;
--z4m-light-primary-txt:#fff;
--z4m-light-secondary:#FF9400;
--z4m-light-secondary-txt:#000;
--z4m-light:#FFF;
/* And so on... */
}
}- Finally, be sure the style
color-scheme: light;is set among the styles of the light theme.
This module is translated in French, English and Spanish languages. To translate this module in another language or change the standard translations:
- Copy in the clipboard the PHP constants declared within the
locale_en.phpscript of the module, - Paste them from the clipboard within the
locale.phpscript of your application, - Finally, translate each text associated with these PHP constants into your own language.
The zdk_user_themes SQL table is created automatically by the module
when the user's favorite theme is read or saved for the first time.
If the MySQL user declared through the
CFG_SQL_APPL_USR
PHP constant does not have CREATE privilege, the module can't create the
required SQL table.
In this case, you can create the zdk_user_themes SQL table by importing
in MySQL or phpMyAdmin the script
z4m_themechooser.sql provided by the module.
See CHANGELOG.md file.
Your contribution to the ZnetDK 4 Mobile project is welcome. Please refer to the CONTRIBUTING.md file.
