1: <?php
2:
3: App::uses('CssProperties', 'Layouts.Lib');
4: App::uses('ArrayUtil', 'Base.Lib');
5:
6: class CssBox {
7:
8: private $borderRadius = '3px';
9: private $borderWidth = '1px';
10: private $borderStyle = 'solid';
11: private $borderColor = '#7d99ca';
12: private $backgroundColorStart = '#d3d3d3';
13: private $backgroundColorEnd = '#707070';
14: private $padding = '10px';
15: private $autoBuildHover = false;
16:
17: public function __construct($options) {
18: foreach ($options as $name => $value) {
19: if (isset($this->{$name})) {
20: $this->{$name} = $value;
21: }
22: }
23: }
24:
25: public function build($selectors) {
26: $b = $this->_defaultProperties()->build($selectors);
27: if ($this->autoBuildHover) {
28: $b .= $this->_hoverProperties()->build($selectors, 'hover');
29: }
30: return $b;
31: }
32:
33: 34: 35: 36: 37:
38: private function _defaultProperties() {
39: $props = new CssProperties(array(
40: '-webkit-border-radius' => $this->borderRadius,
41: '-moz-border-radius' => $this->borderRadius,
42: 'border-radius' => $this->borderRadius,
43: 'border-width' => $this->borderWidth,
44: 'border-style' => $this->borderStyle,
45: 'border-color' => $this->borderColor,
46: 'padding' => $this->padding,
47: 'text-decoration' => 'none',
48: 'display' => 'inline-block',
49: 'filter' => "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr={$this->backgroundColorStart}, endColorstr={$this->backgroundColorEnd})",
50: ));
51: return $props->add($this->_gradientProperties(false));
52: }
53:
54: 55: 56:
57: private function _hoverProperties() {
58: return $this->_gradientProperties(true);
59: }
60:
61: 62: 63:
64: private function _gradientProperties($invertBackgroundColorStartEnd) {
65: if ($invertBackgroundColorStartEnd) {
66: $backgroundColorEnd = $this->backgroundColorStart;
67: $backgroundColorStart = $this->backgroundColorEnd;
68: } else {
69: $backgroundColorStart = $this->backgroundColorStart;
70: $backgroundColorEnd = $this->backgroundColorEnd;
71: }
72:
73: return new CssProperties(array(
74: 'background-color' => $backgroundColorStart,
75: 'background-image' => array(
76: "-webkit-gradient(linear, left top, left bottom, from({$backgroundColorStart}), to({$backgroundColorEnd}))",
77: "-webkit-linear-gradient(top, {$backgroundColorStart}, {$backgroundColorEnd})",
78: "-moz-linear-gradient(top, {$backgroundColorStart}, {$backgroundColorEnd})",
79: "-ms-linear-gradient(top, {$backgroundColorStart}, {$backgroundColorEnd})",
80: "-o-linear-gradient(top, {$backgroundColorStart}, {$backgroundColorEnd})",
81: "linear-gradient(to bottom, {$backgroundColorStart}, {$backgroundColorEnd})",
82: ),
83: 'filter' => "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr={$this->backgroundColorStart}, endColorstr={$this->backgroundColorEnd})",
84: ));
85: }
86:
87: }
88: