phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlButton.php
Go to the documentation of this file.
1<?php
3
9
19
32 public function __construct($identifier, $value = null, $cssStyle = null, $onClick = null) {
33 parent::__construct($identifier, "button", "ui button");
34 $this->content = $value;
35 if (isset($cssStyle)) {
36 $this->setStyle($cssStyle);
37 }
38 if (isset($onClick)) {
39 $this->onClick($onClick);
40 }
41 }
42
49 public function setValue($value) {
50 if (is_array($this->content)) {
51 foreach ($this->content as $i => $content) {
52 if (is_string($content)) {
53 $this->content[$i] = $value;
54 return $this;
55 }
56 }
57 }
58 $this->content = $value;
59 return $this;
60 }
61
68 public function setStyle($cssStyle) {
69 return $this->addToProperty("class", $cssStyle);
70 }
71
72 public function setFocusable($value = true) {
73 if ($value === true)
74 $this->setProperty("tabindex", "0");
75 else {
76 $this->removeProperty("tabindex");
77 }
78 return $this;
79 }
80
81 public function setAnimated($content, $animation = "") {
82 $this->setTagName("div");
83 $this->addToProperty("class", "animated " . $animation);
84 $visible = new HtmlSemDoubleElement("visible-" . $this->identifier, "div");
85 $visible->setClass("visible content");
86 $visible->setContent($this->content);
87 $hidden = new HtmlSemDoubleElement("hidden-" . $this->identifier, "div");
88 $hidden->setClass("hidden content");
89 $hidden->setContent($content);
90 $this->content = array(
91 $visible,
92 $hidden
93 );
94 return $hidden;
95 }
96
102 public function asIcon($icon) {
103 $iconO = $icon;
104 if (\is_string($icon)) {
105 $iconO = new HtmlIcon("icon-" . $this->identifier, $icon);
106 }
107 $this->addToProperty("class", "icon");
108 $this->content = $iconO;
109 return $this;
110 }
111
112 public function asSubmit() {
113 $this->setProperty("type", "submit");
114 return $this->setTagName("button");
115 }
116
125 public function addLabel($label, $before = false, $icon = NULL) {
126 $this->tagName = "div";
127 $prefix = "";
128 if ($before)
129 $prefix = "left ";
130 $this->addToProperty("class", $prefix . "labeled");
131 $isIcon = (isset($this->content[0]) && $this->content[0] instanceof HtmlIcon);
132 $this->content = new HtmlButton("button-" . $this->identifier, $this->content);
133 if ($isIcon) {
134 $this->content->addClass("icon");
135 }
136 $this->content->setTagName("div");
137 $label = new HtmlLabel("label-" . $this->identifier, $label, $icon, "a");
138 $label->setBasic();
139 $this->addContent($label, $before);
140 return $label;
141 }
142
143 /*
144 * (non-PHPdoc)
145 * @see \Ajax\common\html\BaseHtml::fromArray()
146 */
147 public function fromArray($array) {
148 $array = parent::fromArray($array);
149 foreach ($array as $key => $value) {
150 $this->setProperty($key, $value);
151 }
152 return $array;
153 }
154
160 public function setPositive() {
161 return $this->addToProperty("class", "positive");
162 }
163
164 public function setColor($color) {
165 if (\is_array($this->content)) {
166 foreach ($this->content as $content) {
167 if ($content instanceof HtmlButton)
168 $content->setColor($color);
169 }
170 } else
171 parent::setColor($color);
172 return $this;
173 }
174
180 public function setNegative() {
181 return $this->addToProperty("class", "negative");
182 }
183
189 public function setToggle($active = "") {
190 $this->onCreate("$('#" . $this->identifier . "').state();");
191 return $this->addToProperty("class", "toggle " . $active);
192 }
193
198 public function setCircular() {
199 return $this->addToProperty("class", "circular");
200 }
201
207 public function setBasic() {
208 return $this->addToProperty("class", "basic");
209 }
210
211 public function setEmphasis($value) {
212 return $this->addToPropertyCtrl("class", $value, Emphasis::getConstants());
213 }
214
215 public function setLoading() {
216 return $this->addToProperty("class", "loading");
217 }
218
227 public static function social($identifier, $social, $value = NULL) {
228 if ($value === NULL)
229 $value = \ucfirst($social);
230 $return = new HtmlButton($identifier, $value);
231 $return->addIcon($social);
232 return $return->addToPropertyCtrl("class", $social, Social::getConstants());
233 }
234
244 public static function labeled($identifier, $value, $icon, $before = true) {
245 $result = new HtmlButton($identifier, $value);
246 $result->addIcon($icon, $before, true);
247 return $result;
248 }
249
257 public static function icon($identifier, $icon) {
258 $result = new HtmlButton($identifier);
259 $result->asIcon($icon);
260 return $result;
261 }
262
268 public function asLink($href = NULL, $target = NULL) {
269 parent::asLink($href, $target);
270 return $this;
271 }
272
283 public static function dropdown($identifier, $value, $items = [], $asCombo = false, $icon = null) {
284 $result = new HtmlButtonGroups($identifier, [
285 $value
286 ]);
287 $dd = $result->addDropdown($items, $asCombo);
288 if (isset($icon) && $dd instanceof HtmlDropdown)
289 $dd->setIcon($icon);
290 return $result;
291 }
292
293 public function addPopupConfirmation($message, $buttons = ["Okay","Cancel"]) {
294 $elm = new HtmlSemDoubleElement('popup-confirm-' . $this->_identifier);
295 $elm->setContent([
296 'message' => new HtmlSemDoubleElement('popup-confirm-message-' . $this->_identifier, 'p', '', $message)
297 ]);
298 $this->addPopupHtml($elm, null, [
299 'on' => 'click'
300 ]);
301 return $elm;
302 }
303}
static getConstants()
Definition BaseEnum.php:17
onClick($jsCode, $stopPropagation=false, $preventDefault=true)
Base class for Semantic double elements.
addPopupHtml($html="", $variation=NULL, $params=array())
Adds an html popup to the element.
addToPropertyCtrl($name, $value, $typeCtrl)
addToProperty($name, $value, $separator=" ")
Semantic UI Buttongroups component.
Semantic Button component.
static dropdown($identifier, $value, $items=[], $asCombo=false, $icon=null)
Returns a button with a dropdown button.
setStyle($cssStyle)
define the button style
setBasic()
button is less pronounced
setPositive()
hint towards a positive consequence
setValue($value)
Set the button value.
setToggle($active="")
formatted to toggle on/off
asLink($href=NULL, $target=NULL)
{Transforms the element into a link.HtmlSemDoubleElement}
setNegative()
hint towards a negative consequence
static social($identifier, $social, $value=NULL)
Returns a new social Button.
addLabel($label, $before=false, $icon=NULL)
Add and return a button label.
addPopupConfirmation($message, $buttons=["Okay","Cancel"])
__construct($identifier, $value=null, $cssStyle=null, $onClick=null)
Constructs an HTML Semantic button.
setAnimated($content, $animation="")
static labeled($identifier, $value, $icon, $before=true)
Returns a new labeled Button.
static icon($identifier, $icon)
Returns a new icon Button.
Semantic Icon component.
Definition HtmlIcon.php:14
Semantic Label component.
Definition HtmlLabel.php:20