add algorithm to generate the calendar's text color
This commit is contained in:
parent
ce331bd1d3
commit
601237a0c3
|
@ -267,7 +267,7 @@ class OC_Calendar_Calendar{
|
|||
'url' => OCP\Util::linkTo('calendar', 'ajax/events.php').'?calendar_id='.$calendar['id'],
|
||||
'backgroundColor' => $calendar['calendarcolor'],
|
||||
'borderColor' => '#888',
|
||||
'textColor' => 'black',
|
||||
'textColor' => self::generateTextColor($calendar['calendarcolor']),
|
||||
'cache' => true,
|
||||
);
|
||||
}
|
||||
|
@ -287,4 +287,21 @@ class OC_Calendar_Calendar{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief generates the text color for the calendar
|
||||
* @param integer $calendarname
|
||||
* @return boolean
|
||||
*/
|
||||
public static function generateTextColor($calendarcolor){
|
||||
if(substr_count($calendarcolor, '#') == 1){
|
||||
$calendarcolor = substr($calendarcolor,1);
|
||||
}
|
||||
$red = hexdec(substr($calendarcolor,0,2));
|
||||
$green = hexdec(substr($calendarcolor,2,2));
|
||||
$blue = hexdec(substr($calendarcolor,2,2));
|
||||
//recommendation by W3C
|
||||
$computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000);
|
||||
return ($computation > 130)?'black':'white';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue