1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\common\html\HtmlSingleElement; |
6
|
|
|
use Ajax\semantic\html\base\constants\Size; |
7
|
|
|
use Ajax\semantic\html\base\constants\Color; |
8
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Semantic Icon component |
12
|
|
|
* @see http://semantic-ui.com/elements/icon.html |
13
|
|
|
* @author jc |
14
|
|
|
* @version 1.001 |
15
|
|
|
*/ |
16
|
|
|
class HtmlIcon extends HtmlSingleElement { |
17
|
|
|
protected $icon; |
18
|
|
|
protected $size; |
19
|
|
|
protected $attributes; |
20
|
|
|
protected $color; |
21
|
|
|
|
22
|
|
|
public function __construct($identifier, $icon) { |
23
|
|
|
parent::__construct($identifier, "i"); |
24
|
|
|
$this->icon=$icon; |
25
|
|
|
$this->_template='<i class="%icon% icon %size% %attributes% %color%"></i>'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getIcon() { |
29
|
|
|
return $this->icon; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* sets the icon |
34
|
|
|
* @param string $icon |
35
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
36
|
|
|
*/ |
37
|
|
|
public function setIcon($icon) { |
38
|
|
|
$this->icon=$icon; |
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* adds an icon in icon element |
44
|
|
|
* @param string $icon |
45
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
46
|
|
|
*/ |
47
|
|
|
public function addToIcon($icon) { |
48
|
|
|
return $this->addToMember($this->icon, $icon); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
* |
55
|
|
|
* @see \Ajax\common\html\HtmlSingleElement::setSize() |
56
|
|
|
*/ |
57
|
|
|
public function setSize($size) { |
58
|
|
|
$this->setMemberCtrl($this->size, $size, Size::getConstants()); |
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setDisabled() { |
63
|
|
|
return $this->addToMember($this->attributes, "disabled"); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Icon used as a simple loader |
68
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
69
|
|
|
*/ |
70
|
|
|
public function asLoader() { |
71
|
|
|
return $this->addToMember($this->attributes, "loading"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* An icon can be fitted, without any space to the left or right of it. |
76
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
77
|
|
|
*/ |
78
|
|
|
public function setFitted() { |
79
|
|
|
return $this->addToMember($this->attributes, "fitted"); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* |
84
|
|
|
* @param string $sens horizontally or vertically |
85
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
86
|
|
|
*/ |
87
|
|
|
public function setFlipped($sens="horizontally") { |
88
|
|
|
return $this->addToMember($this->attributes, "flipped " . $sens); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* |
93
|
|
|
* @param string $sens clockwise or counterclockwise |
94
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
95
|
|
|
*/ |
96
|
|
|
public function setRotated($sens="clockwise") { |
97
|
|
|
return $this->addToMember($this->attributes, "rotated " . $sens); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setFloated($direction="right") { |
101
|
|
|
return $this->addToMemberCtrl($this->attributes, $direction . " floated", Direction::getConstantValues("floated")); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* icon formatted as a link |
106
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
107
|
|
|
*/ |
108
|
|
|
public function asLink($href=NULL) { |
109
|
|
|
if (isset($href)) { |
110
|
|
|
$this->wrap("<a href='" . $href . "'>", "</a>"); |
111
|
|
|
} |
112
|
|
|
return $this->addToMember($this->attributes, "link"); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function setCircular($inverted=false) { |
116
|
|
|
$invertedStr=""; |
117
|
|
|
if ($inverted !== false) |
118
|
|
|
$invertedStr=" inverted"; |
119
|
|
|
return $this->addToMember($this->attributes, "circular" . $invertedStr); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* |
124
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
125
|
|
|
*/ |
126
|
|
|
public function setInverted() { |
127
|
|
|
return $this->addToMember($this->attributes, "inverted"); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setOutline() { |
131
|
|
|
return $this->addToMember($this->attributes, "outline"); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* |
136
|
|
|
* @param string $inverted |
137
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
138
|
|
|
*/ |
139
|
|
|
public function setBordered($inverted=false) { |
140
|
|
|
$invertedStr=""; |
141
|
|
|
if ($inverted !== false) |
142
|
|
|
$invertedStr=" inverted"; |
143
|
|
|
return $this->addToMember($this->attributes, "bordered" . $invertedStr); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* |
148
|
|
|
* @param string $color |
149
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
150
|
|
|
*/ |
151
|
|
|
public function setColor($color) { |
152
|
|
|
return $this->setMemberCtrl($this->color, $color, Color::getConstants()); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* |
157
|
|
|
* @return \Ajax\semantic\html\HtmlIcon |
158
|
|
|
*/ |
159
|
|
|
public function toCorner() { |
160
|
|
|
return $this->addToMember($this->attributes, "corner"); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function addLabel($label) { |
164
|
|
|
$this->wrap("", $label); |
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public static function label($identifier, $icon, $label) { |
169
|
|
|
$result=new HtmlIcon($identifier, $icon); |
170
|
|
|
return $result->addLabel($label); |
171
|
|
|
} |
172
|
|
|
} |