phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlButtongroups.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\bootstrap\html;
4
7
15
19 protected $elements;
20
21 public function __construct($identifier, $elements=array(), $cssStyle=NULL, $size=NULL, $tagName="div") {
22 parent::__construct($identifier, $tagName);
23 $this->_template='<%tagName% id="%identifier%" %properties%>%elements%</%tagName%>';
24 $this->setProperty("class", "btn-group");
25 $this->setRole("group");
26 $this->addElements($elements);
27 if (isset($cssStyle)) {
28 $this->setStyle($cssStyle);
29 }
30 if (isset($size)) {
31 $this->setSize($size);
32 }
33 }
34
41 public function setSize($size) {
42 foreach ( $this->elements as $element ) {
43 $element->setSize($size);
44 }
45 if (is_int($size)) {
46 return $this->addToPropertyUnique("class", CssRef::sizes("btn-group")[$size], CssRef::sizes("btn-group"));
47 }
48 return $this->addToPropertyCtrl("class", $size, CssRef::sizes("btn-group"));
49 }
50
51 public function setStyle($value) {
52 foreach ( $this->elements as $element )
53 $element->setStyle($value);
54 }
55
56 private function dropdownAsButton($bt) {
57 $this->addExistingDropDown($bt);
58 $bt->setTagName("button");
59 $bt->addBtnClass("dropdown-toogle");
60 $bt->addBtnClass("btn-default");
61 }
62
63 private function addExistingDropDown($bt) {
64 $bt->setMTagName("div");
65 $bt->setRole("group");
66 $bt->setMClass("btn-group");
67 }
68
69 public function addElement($element) {
70 $result=$element;
71 $iid=sizeof($this->elements)+1;
72 if (($element instanceof HtmlDropdown)||($element instanceof HtmlSplitbutton)) {
73 $this->addExistingDropDown($element);
74 } elseif (\is_array($element)) {
75 $result=$this->_addArrayElement($element,$iid);
76 } elseif (is_string($element)) {
77 $result=new HtmlButton($this->identifier."-button-".$iid,$element);
78 }
79 if($result instanceof HtmlButton)
80 $this->elements[]=$result;
81 return $result;
82 }
83
84 private function _addArrayElement(array $element,$iid){
85 if (array_key_exists("glyph", $element))
86 $bt=new HtmlGlyphButton($this->identifier."-button-".$iid);
87 elseif (array_key_exists("btnCaption", $element)) {
88 if (array_key_exists("split", $element))
89 $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid);
90 else{
91 $bt=new HtmlDropdown($this->identifier."-dropdown-".$iid);
92 $this->dropdownAsButton($bt);
93 }
94 } else{
95 $bt=new HtmlButton($this->identifier."-button-".$iid);
96 $bt->fromArray($element);
97 }
98 return $bt;
99 }
100
101 public function addElements($elements) {
102 foreach ( $elements as $element ) {
103 $this->addElement($element);
104 }
105 return $this;
106 }
107
108 /*
109 * (non-PHPdoc)
110 * @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray()
111 */
112 public function fromArray($array) {
113 $this->addElements($array);
114 }
115
116 public function setAlignment($value) {
117 if (is_int($value)) {
118 $value=CssRef::alignment("btn-group")[$value];
119 } else
120 $value="btn-group-".$value;
121 if (strstr($value, "justified")) {
122 foreach ( $this->elements as $element ) {
123 $element->wrap('<div class="btn-group" role="group">', '</div>');
124 }
125 }
126 $this->addToPropertyCtrl("class", $value, CssRef::alignment("btn-group-"));
127 }
128
134 public function getElement($index) {
135 if (is_int($index))
136 return $this->elements[$index];
137 else {
138 $elm=$this->getElementById($index, $this->elements);
139 return $elm;
140 }
141 }
142
143 public function setElement($index, $button) {
144 $this->elements[$index]=$button;
145 return $this;
146 }
147
148 /*
149 * (non-PHPdoc)
150 * @see \Ajax\bootstrap\html\base\BaseHtml::on()
151 */
152 public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
153 foreach ( $this->elements as $element ) {
154 $element->on($event, $jsCode, $stopPropagation, $preventDefault);
155 }
156 return $this;
157 }
158
159 public function getElements() {
160 return $this->elements;
161 }
162
163 /* (non-PHPdoc)
164 * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
165 */
166 public function fromDatabaseObject($object, $function) {
167 $this->addElement($function($object));
168 }
169
170}
Twitter Bootstrap Button component.
Twitter Bootstrap Buttongroups component.
getElement($index)
Return the element at index.
setSize($size)
define the buttons size available values : "btn-group-lg","","btn-group-sm","btn-group-xs"
__construct($identifier, $elements=array(), $cssStyle=NULL, $size=NULL, $tagName="div")
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
Twitter Bootstrap HTML Dropdown component.
Twitter Bootstrap Button component with a Glyph icon.
Twitter Bootstrap HTML Splitbutton component.
Default HTML values for Twitter Bootstrap HTML components.
Definition CssRef.php:12
getElementById($identifier, $elements)
Definition BaseHtml.php:178