From d8e173af032827ae070f00dc5452ca78032dfe64 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 16 Feb 2016 15:01:28 +0100 Subject: [PATCH] Fix regression (class not found, css on hover broken) with try to manage contrast on categories. --- htdocs/categories/class/categorie.class.php | 18 +++++++++++------ htdocs/core/class/html.formother.class.php | 17 +++++++++++----- htdocs/theme/eldy/style.css.php | 13 ++++++++++-- htdocs/theme/md/style.css.php | 22 ++++++++++++++++++--- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index fb74a29a9f5..03a66adab74 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1349,6 +1349,7 @@ class Categorie extends CommonObject /** * Return name and link of category (with picto) + * Use ->id, ->ref, ->label, ->color * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param string $option Sur quoi pointe le lien ('', 'xyz') @@ -1363,13 +1364,18 @@ class Categorie extends CommonObject $label=$langs->trans("ShowCategory").': '. ($this->ref?$this->ref:$this->label); // Check contrast with background and correct text color - $color = colorArrayToHex(colorStringToArray($this->color,array()),''); - $forced_color='000'; - $tmpcolorweight=0; - foreach(colorStringToArray($color,array()) as $x) $tmpcolorweight+=$x; - if ($tmpcolorweight < 400) $forced_color='FFF'; + $forced_color='categtextwhite'; + if ($this->color) + { + $hex=$this->color; + $r = hexdec($hex[0].$hex[1]); + $g = hexdec($hex[2].$hex[3]); + $b = hexdec($hex[4].$hex[5]); + $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm + if ($bright > 0.6) $forced_color='categtextblack'; // Higher than 60% + } - $link = ''; + $link = ''; $linkend=''; $picto='category'; diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 1727db5f227..078dc01d96f 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -595,13 +595,20 @@ class FormOther */ static function showColor($color, $textifnotdefined='') { + $textcolor='FFF'; + if ($color) + { + $hex=$color; + $r = hexdec($hex[0].$hex[1]); + $g = hexdec($hex[2].$hex[3]); + $b = hexdec($hex[4].$hex[5]); + $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm + if ($bright > 0.6) $textcolor='000'; + } + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $color = colorArrayToHex(colorStringToArray($color,array()),''); - $textcolor='000'; - $tmpcolorweight=0; - foreach(colorStringToArray($color,array()) as $x) $tmpcolorweight+=$x; - if ($tmpcolorweight < 400) $textcolor='FFF'; + if ($color) print ''; else print $textifnotdefined; } diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index a756e1f941c..1aa5b41ac3f 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -3655,22 +3655,31 @@ a span.select2-chosen overflow: hidden; } + +/* ============================================================================== */ +/* For categories */ +/* ============================================================================== */ + .noborderoncategories { border: none !important; border-radius: 5px !important; box-shadow: none; -webkit-box-shadow: none !important; box-shadow: none !important; - color: #fff; } span.noborderoncategories a, li.noborderoncategories a { - color: #fff; line-height: normal; vertical-align: top; } span.noborderoncategories { padding: 3px 5px 0px 5px; } +.categtextwhite, .treeview .categtextwhite.hover { + color: #fff !important; +} +.categtextblack { + color: #000 !important; +} /* ============================================================================== */ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index fe1e161dfc8..e08512b9ca4 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -2789,6 +2789,14 @@ table.dp { color: rgb(); } +.categtextwhite, .treeview .categtextwhite.hover { + color: #fff !important; +} +.categtextblack { + color: #000 !important; +} + + /* ============================================================================== */ /* Afficher/cacher */ /* ============================================================================== */ @@ -3498,22 +3506,30 @@ a span.select2-chosen overflow: hidden; } + +/* ============================================================================== */ +/* For categories */ +/* ============================================================================== */ + .noborderoncategories { border: none !important; border-radius: 5px !important; box-shadow: none; -webkit-box-shadow: none !important; box-shadow: none !important; - color: #fff !important; } span.noborderoncategories a, li.noborderoncategories a { - color: #fff !important; line-height: normal; } span.noborderoncategories { padding: 5px 5px 0px 5px; } - +.categtextwhite, .treeview .categtextwhite.hover { + color: #fff !important; +} +.categtextblack { + color: #000 !important; +} /* ============================================================================== */