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
2 
3 namespace Ajax\bootstrap\html;
4 
5 use Ajax\JsUtils;
8 
16 
24  public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
25  parent::__construct($identifier, "button");
26  $this->setProperty("class", "btn btn-default");
27  $this->setProperty("role", "button");
28  $this->content=$value;
29  if (isset($cssStyle)) {
30  $this->setStyle($cssStyle);
31  }
32  if (isset($onClick)) {
33  $this->onClick($onClick);
34  }
35  }
36 
42  public function setValue($value) {
43  $this->content=$value;
44  return $this;
45  }
46 
53  public function setStyle($cssStyle) {
54  return $this->addToPropertyCtrl("class", CssRef::getStyle($cssStyle, "btn"), CssRef::Styles("btn"));
55  }
56 
63  public function setSize($size) {
64  if (is_int($size)) {
65  return $this->addToPropertyUnique("class", CssRef::sizes()[$size], CssRef::sizes());
66  }
67  return $this->addToPropertyCtrl("class", $size, CssRef::sizes());
68  }
69 
74  public function setActive() {
75  return $this->addToPropertyCtrl("class", "active", array (
76  "active"
77  ));
78  }
79 
84  public function setDisabled() {
85  return $this->addToPropertyCtrl("class", "disabled", array (
86  "disabled"
87  ));
88  }
89 
90  public function setToggled() {
91  return $this->setProperty("data-toggle", "button");
92  }
93 
94  /*
95  * (non-PHPdoc)
96  * @see BaseHtml::run()
97  */
98  public function run(JsUtils $js) {
99  $this->_bsComponent=$js->bootstrap()->generic("#".$this->identifier);
100  if (array_key_exists("data-toggle", $this->properties)) {
101  $this->_bsComponent->addCode("$.fn.toggled=function(){return this.hasClass('active');};");
102  }
103  $this->addEventsOnRun($js);
104  return $this->_bsComponent;
105  }
106 
107 
108 
109  /*
110  * (non-PHPdoc)
111  * @see \Ajax\bootstrap\html\BaseHtml::fromArray()
112  */
113  public function fromArray($array) {
114  $array=parent::fromArray($array);
115  foreach ( $array as $key => $value ) {
116  $this->setProperty($key, $value);
117  }
118  return $array;
119  }
120 }
setSize($size)
define the button size available values : "btn-lg","","btn-sm","btn-xs"
Definition: HtmlButton.php:63
addEventsOnRun(JsUtils $js=NULL)
setDisabled()
Disables the button.
Definition: HtmlButton.php:84
onClick($jsCode, $stopPropagation=false, $preventDefault=true)
Twitter Bootstrap Button component.
Definition: HtmlButton.php:15
setActive()
Sets the "active" css class to the button.
Definition: HtmlButton.php:74
bootstrap(Bootstrap $bootstrap=NULL)
getter or setter of the Twitter Bootstrap variable
Definition: JsUtils.php:141
static Styles($prefix="btn")
Definition: CssRef.php:27
JQuery PHP library.
Definition: JsUtils.php:23
setValue($value)
Set the button value.
Definition: HtmlButton.php:42
addToPropertyUnique($name, $value, $typeCtrl)
static sizes($prefix="btn")
Definition: CssRef.php:38
static getStyle($cssStyle, $prefix)
return a valid style avaible values : "default","primary","success","info","warning","danger"
Definition: CssRef.php:346
setStyle($cssStyle)
define the button style avaible values : "btn-default","btn-primary","btn-success","btn-info","btn-warning","btn-danger"
Definition: HtmlButton.php:53
addToPropertyCtrl($name, $value, $typeCtrl)
__construct($identifier, $value="", $cssStyle=null, $onClick=null)
Constructs an HTML Bootstrap button.
Definition: HtmlButton.php:24