Fix regression (class not found, css on hover broken) with try to manage

contrast on categories.
This commit is contained in:
Laurent Destailleur 2016-02-16 15:01:28 +01:00
parent 6c7fc55988
commit d8e173af03
4 changed files with 54 additions and 16 deletions

View File

@ -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 = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip"' . ( $forced_color ? ' style="color: #'.$forced_color.'"' : '' ) .'>';
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color .'">';
$linkend='</a>';
$picto='category';

View File

@ -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 '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
else print $textifnotdefined;
}

View File

@ -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;
}
/* ============================================================================== */

View File

@ -2789,6 +2789,14 @@ table.dp {
color: rgb(<?php print $colortextlink; ?>);
}
.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;
}
/* ============================================================================== */