Elgg  Version master
color_schemes.css.php
Go to the documentation of this file.
1 <?php
2 if (!elgg_get_config('color_schemes_enabled')) {
3  return;
4 }
5 
6 $css_vars = _elgg_services()->cssCompiler->getCssVars();
7 unset($css_vars['default']);
8 if (empty($css_vars)) {
9  return;
10 }
11 
12 foreach ($css_vars as $color_scheme => $css_variables) {
13  $scheme_vars = '';
14  foreach ($css_variables as $variable => $value) {
15  $scheme_vars .= "--elgg-{$variable}: {$value};";
16  }
17 
18  $variables_output = '';
19  if ($color_scheme === 'dark') {
20  // set a global setting to let browser know it is dark mode
21  $variables_output .= 'color-scheme: dark;';
22  }
23 
24  $variables_output .= 'body {' . $scheme_vars . '}';
25 
26  // css output
27  echo ":root[data-color-scheme={$color_scheme}] {";
28  echo $variables_output;
29  echo '}';
30 
31  // special browser detection for dark scheme
32  if ($color_scheme === 'dark') {
33  echo '@media (prefers-color-scheme: dark) {';
34  echo ':root:not([data-color-scheme]) {';
35  echo $variables_output;
36  echo '}';
37  echo '}';
38  }
39 }
if(!elgg_get_config('color_schemes_enabled')) $css_vars
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:347
$value
Definition: generic.php:51