diff options
-rw-r--r-- | inc/render.inc.php | 23 | ||||
-rw-r--r-- | modules-available/webinterface/page.inc.php | 4 | ||||
-rw-r--r-- | modules-available/webinterface/templates/customization.html | 2 |
3 files changed, 24 insertions, 5 deletions
diff --git a/inc/render.inc.php b/inc/render.inc.php index c34c285a..72993ab5 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -57,10 +57,11 @@ class Render if (!empty($bgcolor) || !empty($title)) { self::$header .= '<style type="text/css">' . "\n"; if (!empty($bgcolor)) { - self::$header .= ".navbar-header { background-color: $bgcolor; }"; + $fgcolor = self::readableColor($bgcolor); + self::$header .= ".navbar-header{background-color:$bgcolor}a.navbar-brand{color:$fgcolor!important}"; } if (!empty($title)) { - self::$header .= '#navbar-sub:after { content: "' . self::cssEsc($title) . '";margin:0 }'; + self::$header .= '#navbar-sub:after{content:"' . self::cssEsc($title) . '";margin:0}'; } self::$header .= "\n</style>"; } @@ -302,4 +303,22 @@ class Render self::$dashboard = $params; } + public static function readableColor($hex) { + if (strlen($hex) <= 4) { + $cnt = 1; + } else { + $cnt = 2; + } + if (preg_match('/^#?([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})$/i', $hex, $out) != 1) + return '#000'; + $chans = array(); + $f = ($cnt === 1 ? 17 : 1); + for ($i = 1; $i <= 3; ++$i) { + $out[$i] = (hexdec($out[$i]) * $f); + $chans[] = $out[$i] ^ 0x80; + } + $b = (255 - (0.299 * $out[1] + 0.587 * $out[2] + 0.114 * $out[3])) * 2; + return sprintf("#%02x%02x%02x", ($chans[0] + $b) / 3, ($chans[1] + $b) / 3, ($chans[2] + $b) / 3); + } + } diff --git a/modules-available/webinterface/page.inc.php b/modules-available/webinterface/page.inc.php index e5a25834..e576807e 100644 --- a/modules-available/webinterface/page.inc.php +++ b/modules-available/webinterface/page.inc.php @@ -133,8 +133,8 @@ class Page_WebInterface extends Page $data['selected_hide'] = 'checked'; Render::addTemplate('passwords', $data); $data = array('prefix' => Property::get('page-title-prefix')); - $data['colors'] = array_map(function ($i) { return array('color' => $i); }, - array('', 'red', 'green', 'blue', 'black', 'white', 'orange', 'gray', 'lime', 'magenta', 'yellow')); + $data['colors'] = array_map(function ($i) { return array('color' => $i ? '#' . $i : '', 'text' => Render::readableColor($i)); }, + array('', 'f00', '0f0', '00f', 'ff0', 'f0f', '0ff', 'fff', '000', 'f90', '09f', '90f', 'f09', '9f0')); $color = Property::get('logo-background'); foreach ($data['colors'] as &$c) { if ($c['color'] === $color) { diff --git a/modules-available/webinterface/templates/customization.html b/modules-available/webinterface/templates/customization.html index 447404a6..7949f95b 100644 --- a/modules-available/webinterface/templates/customization.html +++ b/modules-available/webinterface/templates/customization.html @@ -17,7 +17,7 @@ {{lang_logoBackground}} <select class="form-control" name="bgcolor"> {{#colors}} - <option style="color:{{color}}" {{selected}}>{{color}}</option> + <option style="color:{{text}};background:{{color}}" {{selected}}>{{color}}</option> {{/colors}} </select> </label> |