protected function AvailabilityCalendarCssGenerator::createStatesCss in Availability Calendars 7.5
Same name and namespace in other branches
- 7.3 availability_calendar.styles.inc \AvailabilityCalendarCssGenerator::createStatesCss()
- 7.4 availability_calendar.styles.inc \AvailabilityCalendarCssGenerator::createStatesCss()
Return value
string The CSS for the states.
1 call to AvailabilityCalendarCssGenerator::createStatesCss()
- AvailabilityCalendarCssGenerator::createCss in ./
availability_calendar.styles.inc - Creates the css.
File
- ./
availability_calendar.styles.inc, line 732
Class
Code
protected function createStatesCss() {
$category = 'states';
$splitDay = $this
->getStyle($category, 'split-day');
$states = availability_calendar_get_states();
$css = '';
$css .= "/* Whole day coloring */\n";
foreach ($states as $sid => $state) {
$class = $state['css_class'];
// Whole day state.
$selector = ".{$class}, .{$class} > div";
$css .= $this
->cssSelector($selector);
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'background-color',
));
$css .= $this
->cssSelectorEnd();
}
// Get the width and heigth.
$cellWidth = (int) $this
->getStyle('days', 'width');
// We have to subtract pixels, so this value can only be in pixels.
$cellWidthUnit = 'px';
$cellHeight = (int) $this
->getStyle('days', 'height');
$cellHeightUnit = 'px';
if (!empty($splitDay)) {
$css .= "/* Split day coloring */\n";
// Styles for the state colors. The border color definitions for the pm
// state should be superfluous as the background-color is the same.
// However I did get some artifacts in at least FireFox.
foreach ($states as $sid => $state) {
$class = $state['css_class'];
$css .= $this
->cssSelector("html[dir=ltr] .cal .{$class}-am > span");
switch ($splitDay) {
case '/':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-left-color',
));
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-top-color',
));
break;
case '\\':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-left-color',
));
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-bottom-color',
));
break;
case '|':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-left-color',
));
break;
case '―':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-top-color',
));
break;
}
$css .= $this
->cssSelectorEnd();
$css .= $this
->cssSelector("html[dir=ltr] .cal .{$class}-pm > span");
switch ($splitDay) {
case '/':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-right-color',
));
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-bottom-color',
));
break;
case '\\':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-right-color',
));
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-top-color',
));
break;
case '|':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-right-color',
));
break;
case '―':
$css .= $this
->addCssColorDeclaration($category, array(
$class => 'border-bottom-color',
));
break;
}
$css .= $this
->cssSelectorEnd();
}
// Styles for the outer span that takes care of the background coloring of
// split days.
$css .= "/* Split day dimensioning and positioning */\n";
$css .= $this
->cssSelector('.cal td > span');
switch ($splitDay) {
case '/':
$css .= $this
->cssDeclaration('width', '0');
$css .= $this
->cssDeclaration('height', '0');
$css .= $this
->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
$css .= $this
->cssDeclaration('border-top-width', floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
$css .= $this
->cssDeclaration('border-bottom-width', ceil($cellHeight / 2) . $cellHeightUnit);
break;
case '\\':
$css .= $this
->cssDeclaration('width', '0');
$css .= $this
->cssDeclaration('height', '0');
$css .= $this
->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
$css .= $this
->cssDeclaration('border-bottom-width', floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
$css .= $this
->cssDeclaration('border-top-width', ceil($cellHeight / 2) . $cellHeightUnit);
break;
case '|':
$css .= $this
->cssDeclaration('width', '0');
$css .= $this
->addCssLengthDeclaration('days', 'height');
$css .= $this
->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
$css .= $this
->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
break;
case '―':
$css .= $this
->addCssLengthDeclaration('days', 'width');
$css .= $this
->cssDeclaration('height', '0');
$css .= $this
->cssDeclaration('border-top-width', floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('border-bottom-width', ceil($cellHeight / 2) . $cellHeightUnit);
break;
}
$css .= $this
->cssSelectorEnd();
// Styles for the inner span within the td that contains the day number.
$css .= $this
->cssSelector('.cal td > span > span');
switch ($splitDay) {
case '/':
$css .= $this
->cssDeclaration('top', -floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('left', -floor($cellWidth / 2) . $cellWidthUnit);
break;
case '\\':
$css .= $this
->cssDeclaration('top', -floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('left', -ceil($cellWidth / 2) . $cellWidthUnit);
break;
case '|':
$css .= $this
->cssDeclaration('top', '0');
$css .= $this
->cssDeclaration('left', -floor($cellWidth / 2) . $cellWidthUnit);
break;
case '―':
$css .= $this
->cssDeclaration('top', -floor($cellHeight / 2) . $cellHeightUnit);
$css .= $this
->cssDeclaration('left', '0');
break;
}
$css .= $this
->cssSelectorEnd();
}
$css .= "/* Dimensions and other properties for element containing day number */\n";
$css .= $this
->cssSelector('.cal td > div, .cal td > span > span');
if ($cellWidth >= 2 && $cellHeight >= 2) {
// Subtract border of 1px.
$cellWidth -= 2;
$cellHeight -= 2;
$css .= $this
->cssDeclaration('width', $cellWidth . $cellWidthUnit);
$css .= $this
->cssDeclaration('height', $cellHeight . $cellHeightUnit);
$css .= $this
->cssDeclaration('line-height', $cellHeight . $cellHeightUnit);
}
$css .= $this
->addCssDeclaration('days', 'text-align');
$css .= $this
->addCssDeclaration('days', 'vertical-align');
$css .= $this
->cssSelectorEnd();
return $css;
}