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