phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlMenu.php
Go to the documentation of this file.
1<?php
2
4
18use Ajax\JsUtils;
22
30 private $_itemHeader;
31
32 public function __construct($identifier, $items=array()) {
33 parent::__construct($identifier, "div", "ui menu");
34 $this->addItems($items);
35 }
36
42 public function setType($type="") {
43 return $this->addToPropertyCtrl("class", $type, array ("","item","text" ));
44 }
45
46 public function setActiveItem($index) {
47 $item=$this->getItem($index);
48 if ($item !== null) {
49 $item->addToProperty("class", "active");
50 }
51 return $this;
52 }
53
54 private function getItemToInsert($item) {
55 if ($item instanceof HtmlInput || $item instanceof HtmlImg || $item instanceof HtmlIcon || $item instanceof HtmlButtonGroups || $item instanceof HtmlButton || $item instanceof HtmlLabel) {
56 $itemO=new HtmlMenuItem("item-" . $this->identifier . "-" . \sizeof($this->content) , $item);
57 $itemO->addClass("no-active");
58 $item=$itemO;
59 }
60 return $item;
61 }
62
63 private function afterInsert($item) {
64 if (!$item instanceof HtmlMenu && $item->propertyContains("class", "header")===false)
65 $item->addToPropertyCtrl("class", "item", array ("item" ));
66 else {
67 $this->setSecondary();
68 }
69 return $item;
70 }
71
78 public function addItem($item) {
79 $number=$item;
80 $item=parent::addItem($this->getItemToInsert($item));
81 if(\is_int($number))
82 $item->setProperty("data-page", $number);
83 return $this->afterInsert($item);
84 }
85
92 public function insertItem($item, $position=0) {
93 $item=parent::insertItem($this->getItemToInsert($item), $position);
94 return $this->afterInsert($item);
95 }
96
97 public function generateMenuAsItem($menu, $header=null) {
98 $count=$this->count();
99 $item=new HtmlSemDoubleElement("item-" . $this->identifier . "-" . $count, "div");
100 if (isset($header)) {
101 $headerItem=new HtmlSemDoubleElement("item-header-" . $this->identifier . "-" . $count, "div", "header");
102 $headerItem->setContent($header);
103 $item->addContent($headerItem);
104 $this->_itemHeader=$headerItem;
105 }
106 if(\is_array($menu)){
107 $menu=new HtmlMenu("menu-" . $this->identifier . "-" . $count,$menu);
108 }
109 $menu->setClass("menu");
110 $item->addContent($menu);
111 return $item;
112 }
113
119 public function addHeader($caption){
120 if(!($caption instanceof HtmlDoubleElement)){
121 $header=new HtmlDoubleElement('','div');
122 $header->setContent($caption);
123 }else{
124 $header=$caption;
125 }
126 $header->addClass('item header');
127 $this->wrapContent($header);
128 return $header;
129 }
130
131 public function addMenuAsItem($menu, $header=null) {
132 return $this->addItem($this->generateMenuAsItem($menu, $header));
133 }
134
135 public function addPopupAsItem($value, $identifier, $content="") {
136 $value=new HtmlSemDoubleElement($identifier, "a", "browse item", $value);
137 $value->addContent(new HtmlIcon("", "dropdown"));
138 $value=$this->addItem($value);
139 $popup=new HtmlPopup($value, "popup-" . $this->identifier . "-" . $this->count(), $content);
140 $popup->setFlowing()->setPosition("bottom left")->setOn("click");
141 $this->wrap("", $popup);
142 return $popup;
143 }
144
145 public function addDropdownAsItem($value, $items=NULL) {
146 $dd=$value;
147 if (\is_string($value)) {
148 $dd=new HtmlDropdown("dropdown-" . $this->identifier . "-" . $this->count(), $value, $items);
149 }
150 $this->addItem($dd);
151 return $dd;
152 }
153
160 protected function createItem($value) {
161 $itemO=new HtmlMenuItem($this->identifier."-item-" . \sizeof($this->content),"");
162 $itemO->setTagName("a");
163 $itemO->setContent($value);
164 return $itemO;
165 }
166
167 public function setSecondary($value=true) {
168 if($value)
169 $this->addToProperty("class", "secondary");
170 else
171 $this->removePropertyValue("class", "secondary");
172 return $this;
173 }
174
175 public function setVertical() {
176 return $this->addToPropertyCtrl("class", "vertical", array ("vertical" ));
177 }
178
179 public function setPosition($value="right") {
180 return $this->addToPropertyCtrl("class", $value, array ("right","left" ));
181 }
182
183 public function setPointing($value=Direction::NONE) {
184 return $this->addToPropertyCtrl("class", $value . " pointing", Direction::getConstantValues("pointing"));
185 }
186
187 public function asTab($vertical=false) {
188 $this->apply(function (HtmlDoubleElement &$item) {
189 $item->setTagName("a");
190 });
191 if ($vertical === true)
192 $this->setVertical();
193 return $this->addToProperty("class", "tabular");
194 }
195
196 public function asPagination() {
197 $this->apply(function (HtmlDoubleElement &$item) {
198 $item->setTagName("a");
199 });
200 return $this->addToProperty("class", "pagination");
201 }
202
203 public function setFixed() {
204 return $this->addToProperty("class", "fixed");
205 }
206
207 public function setFluid() {
208 return $this->addToProperty("class", "fluid");
209 }
210
211 public function setCompact() {
212 return $this->addToProperty("class", "compact");
213 }
214
215 /*
216 * (non-PHPdoc)
217 * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
218 */
219 public function fromDatabaseObject($object, $function) {
220 $return=$function($object);
221 if (\is_array($return))
222 $this->addItems($return);
223 else
224 $this->addItem($return);
225 }
226
232 public function setWidth($width) {
233 if (\is_int($width)) {
234 $width=Wide::getConstants()["W" . $width];
235 }
236 $this->addToPropertyCtrl("class", $width, Wide::getConstants());
237 return $this->addToPropertyCtrl("class", "item", array ("item" ));
238 }
239
240 public function addImage($identifier, $src="", $alt="") {
241 return $this->addItem(new HtmlImg($identifier, $src, $alt));
242 }
243
244 public static function vertical($identifier, $items=array()) {
245 return (new HtmlMenu($identifier, $items))->setVertical();
246 }
247
248 public function getItemHeader() {
249 return $this->_itemHeader;
250 }
251
252 public function setHasContainer(){
253 return $this->wrapContent("<div class='ui container'>","</div>");
254 }
255
256 public function run(JsUtils $js){
257 if($this->identifier!=="" && !isset($this->_bsComponent))
258 $this->onClick('if(!$(this).hasClass("dropdown")&&!$(this).hasClass("no-active")){$(this).addClass("active").siblings().removeClass("active");}',false,false);
259 $result= parent::run($js);
260 return $result->setItemSelector(">.item:not(.header)");
261 }
262}
JQuery PHP library.
Definition JsUtils.php:23
wrap($before, $after="")
Definition BaseHtml.php:170
Base class for Html collections.
getItem($index)
Return the item at index.
onClick($jsCode, $stopPropagation=false, $preventDefault=true)
Base class for Semantic Html collections.
Base class for Semantic double elements.
addToPropertyCtrl($name, $value, $typeCtrl)
addToProperty($name, $value, $separator=" ")
setType($type="")
Sets the menu type.
Definition HtmlMenu.php:42
addHeader($caption)
Adds an header to the menu.
Definition HtmlMenu.php:119
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
Definition HtmlMenu.php:256
addPopupAsItem($value, $identifier, $content="")
Definition HtmlMenu.php:135
static vertical($identifier, $items=array())
Definition HtmlMenu.php:244
__construct($identifier, $items=array())
Definition HtmlMenu.php:32
addItem($item)
adds and returns an item\Ajax\common\html\HtmlDoubleElement
Definition HtmlMenu.php:78
addImage($identifier, $src="", $alt="")
Definition HtmlMenu.php:240
setWidth($width)
Defines the menu width.
Definition HtmlMenu.php:232
Semantic UI Buttongroups component.
Semantic Button component.
Semantic Icon component.
Definition HtmlIcon.php:14
Semantic Label component.
Definition HtmlLabel.php:20