Passed
Push — master ( bd8ea3...e370f7 )
by Jean-Christophe
02:57
created
Ajax/semantic/html/modules/HtmlDropdown.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 use Ajax\service\JArray;
14 14
 
15 15
 class HtmlDropdown extends HtmlSemDoubleElement {
16
-	use FieldTrait,LabeledIconTrait {
16
+	use FieldTrait, LabeledIconTrait {
17 17
 		addIcon as addIconP;
18 18
 	}
19 19
 
20
-	protected $mClass = "menu";
20
+	protected $mClass="menu";
21 21
 
22
-	protected $mTagName = "div";
22
+	protected $mTagName="div";
23 23
 
24
-	protected $items = array();
24
+	protected $items=array();
25 25
 
26
-	protected $_params = array(
26
+	protected $_params=array(
27 27
 		"action" => "nothing",
28 28
 		"on" => "hover",
29 29
 		"showOnFocus" => true
@@ -37,29 +37,29 @@  discard block
 block discarded – undo
37 37
 
38 38
 	protected $_multiple;
39 39
 
40
-	public function __construct($identifier, $value = "", $items = array(), $associative = true) {
40
+	public function __construct($identifier, $value="", $items=array(), $associative=true) {
41 41
 		parent::__construct($identifier, "div");
42
-		$this->_template = include dirname(__FILE__) . '/../templates/tplDropdown.php';
42
+		$this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php';
43 43
 		$this->setProperty("class", "ui dropdown");
44
-		$this->_multiple = false;
45
-		$content = [];
46
-		$text = '';
44
+		$this->_multiple=false;
45
+		$content=[];
46
+		$text='';
47 47
 		if ($value instanceof HtmlSemDoubleElement) {
48
-			$text = $value;
49
-		} elseif ($value !== null) {
50
-			$text = new HtmlSemDoubleElement("text-" . $this->identifier, "div");
48
+			$text=$value;
49
+		} elseif ($value!==null) {
50
+			$text=new HtmlSemDoubleElement("text-".$this->identifier, "div");
51 51
 			$text->setClass("text");
52 52
 			$this->setValue($value);
53 53
 		}
54
-		if ($text != null) {
55
-			$content = [
54
+		if ($text!=null) {
55
+			$content=[
56 56
 				"text" => $text
57 57
 			];
58 58
 		}
59
-		$content["arrow"] = new HtmlIcon($identifier . "-icon", "dropdown");
60
-		$this->content = $content;
61
-		$this->tagName = "div";
62
-		$this->_associative = $associative;
59
+		$content["arrow"]=new HtmlIcon($identifier."-icon", "dropdown");
60
+		$this->content=$content;
61
+		$this->tagName="div";
62
+		$this->_associative=$associative;
63 63
 		$this->addItems($items);
64 64
 	}
65 65
 
@@ -71,16 +71,16 @@  discard block
 block discarded – undo
71 71
 		return $this->input;
72 72
 	}
73 73
 
74
-	public function addItem($item, $value = NULL, $image = NULL, $description = NULL) {
75
-		$itemO = $this->beforeAddItem($item, $value, $image, $description);
76
-		$this->items[] = $itemO;
74
+	public function addItem($item, $value=NULL, $image=NULL, $description=NULL) {
75
+		$itemO=$this->beforeAddItem($item, $value, $image, $description);
76
+		$this->items[]=$itemO;
77 77
 		return $itemO;
78 78
 	}
79 79
 
80
-	public function addIcon($icon, $before = true, $labeled = false) {
80
+	public function addIcon($icon, $before=true, $labeled=false) {
81 81
 		$this->removeArrow();
82 82
 		$this->addIconP($icon, $before, $labeled);
83
-		$elm = $this->getElementById("text-" . $this->identifier, $this->content);
83
+		$elm=$this->getElementById("text-".$this->identifier, $this->content);
84 84
 		if (isset($elm)) {
85 85
 			$elm->setWrapAfter("");
86 86
 		}
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 	}
89 89
 
90 90
 	public function addIcons($icons) {
91
-		$count = $this->count();
92
-		for ($i = 0; $i < \sizeof($icons) && $i < $count; $i ++) {
91
+		$count=$this->count();
92
+		for ($i=0; $i<\sizeof($icons) && $i<$count; $i++) {
93 93
 			$this->getItem($i)->addIcon($icons[$i]);
94 94
 		}
95 95
 	}
@@ -101,32 +101,32 @@  discard block
 block discarded – undo
101 101
 	 * @param int $position
102 102
 	 * @return HtmlDropdownItem
103 103
 	 */
104
-	public function insertItem($item, $position = 0) {
105
-		$itemO = $this->beforeAddItem($item);
106
-		$start = array_slice($this->items, 0, $position);
107
-		$end = array_slice($this->items, $position);
108
-		$start[] = $item;
109
-		$this->items = array_merge($start, $end);
104
+	public function insertItem($item, $position=0) {
105
+		$itemO=$this->beforeAddItem($item);
106
+		$start=array_slice($this->items, 0, $position);
107
+		$end=array_slice($this->items, $position);
108
+		$start[]=$item;
109
+		$this->items=array_merge($start, $end);
110 110
 		return $itemO;
111 111
 	}
112 112
 
113 113
 	protected function removeArrow() {
114
-		if (\sizeof($this->content) > 1) {
114
+		if (\sizeof($this->content)>1) {
115 115
 			unset($this->content["arrow"]);
116
-			$this->content = \array_values($this->content);
116
+			$this->content=\array_values($this->content);
117 117
 		}
118 118
 	}
119 119
 
120
-	protected function beforeAddItem($item, $value = NULL, $image = NULL, $description = NULL) {
121
-		$itemO = $item;
120
+	protected function beforeAddItem($item, $value=NULL, $image=NULL, $description=NULL) {
121
+		$itemO=$item;
122 122
 		if (\is_array($item)) {
123
-			$description = JArray::getValue($item, "description", 3);
124
-			$value = JArray::getValue($item, "value", 1);
125
-			$image = JArray::getValue($item, "image", 2);
126
-			$item = JArray::getValue($item, "item", 0);
123
+			$description=JArray::getValue($item, "description", 3);
124
+			$value=JArray::getValue($item, "value", 1);
125
+			$image=JArray::getValue($item, "image", 2);
126
+			$item=JArray::getValue($item, "item", 0);
127 127
 		}
128
-		if (! $item instanceof HtmlDropdownItem) {
129
-			$itemO = new HtmlDropdownItem("dd-item-" . $this->identifier . "-" . \sizeof($this->items), $item, $value, $image, $description);
128
+		if (!$item instanceof HtmlDropdownItem) {
129
+			$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items), $item, $value, $image, $description);
130 130
 		} elseif ($itemO instanceof HtmlDropdownItem) {
131 131
 			$this->addToProperty("class", "vertical");
132 132
 		}
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	}
143 143
 
144 144
 	public function addInput($name) {
145
-		if (! isset($name))
146
-			$name = "input-" . $this->identifier;
145
+		if (!isset($name))
146
+			$name="input-".$this->identifier;
147 147
 		$this->setAction("activate");
148
-		$this->input = new HtmlInput($name, "hidden");
149
-		$this->input->setIdentifier("input-" . $this->identifier);
148
+		$this->input=new HtmlInput($name, "hidden");
149
+		$this->input->setIdentifier("input-".$this->identifier);
150 150
 		return $this->input;
151 151
 	}
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param string $icon
158 158
 	 * @return HtmlDropdownItem
159 159
 	 */
160
-	public function addSearchInputItem($placeHolder = NULL, $icon = NULL) {
160
+	public function addSearchInputItem($placeHolder=NULL, $icon=NULL) {
161 161
 		return $this->addItem(HtmlDropdownItem::searchInput($placeHolder, $icon));
162 162
 	}
163 163
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @param string $icon
178 178
 	 * @return HtmlDropdownItem
179 179
 	 */
180
-	public function addHeaderItem($caption = NULL, $icon = NULL) {
180
+	public function addHeaderItem($caption=NULL, $icon=NULL) {
181 181
 		return $this->addItem(HtmlDropdownItem::header($caption, $icon));
182 182
 	}
183 183
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 	 * @return $this
223 223
 	 */
224 224
 	public function setPropertyValues($property, $values) {
225
-		$i = 0;
226
-		if (\is_array($values) === false) {
227
-			$values = \array_fill(0, $this->count(), $values);
225
+		$i=0;
226
+		if (\is_array($values)===false) {
227
+			$values=\array_fill(0, $this->count(), $values);
228 228
 		}
229 229
 		foreach ($values as $value) {
230
-			$c = $this->items[$i ++];
230
+			$c=$this->items[$i++];
231 231
 			if (isset($c)) {
232 232
 				$c->setProperty($property, $value);
233 233
 			} else {
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
 	 * @param boolean $dropdown
262 262
 	 */
263 263
 	public function asDropdown($dropdown) {
264
-		if ($dropdown === false) {
265
-			$this->_template = include dirname(__FILE__) . '/../templates/tplDropdownMenu.php';
266
-			$dropdown = "menu";
264
+		if ($dropdown===false) {
265
+			$this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php';
266
+			$dropdown="menu";
267 267
 		} else {
268
-			$dropdown = "dropdown";
269
-			$this->mClass = "menu";
268
+			$dropdown="dropdown";
269
+			$this->mClass="menu";
270 270
 		}
271 271
 		return $this->addToPropertyCtrl("class", $dropdown, array(
272 272
 			"menu",
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		));
293 293
 	}
294 294
 
295
-	public function asButton($floating = false) {
295
+	public function asButton($floating=false) {
296 296
 		$this->removeArrow();
297 297
 		if ($floating)
298 298
 			$this->addToProperty("class", "floating");
@@ -300,15 +300,15 @@  discard block
 block discarded – undo
300 300
 		return $this->addToProperty("class", "button");
301 301
 	}
302 302
 
303
-	public function asSelect($name = NULL, $multiple = false, $selection = true) {
304
-		$this->_multiple = $multiple;
303
+	public function asSelect($name=NULL, $multiple=false, $selection=true) {
304
+		$this->_multiple=$multiple;
305 305
 		if (isset($name))
306 306
 			$this->addInput($name);
307 307
 		if ($multiple) {
308 308
 			$this->addToProperty("class", "multiple");
309 309
 		}
310 310
 		if ($selection) {
311
-			if ($this->propertyContains("class", "button") === false)
311
+			if ($this->propertyContains("class", "button")===false)
312 312
 				$this->addToPropertyCtrl("class", "selection", array(
313 313
 					"selection"
314 314
 				));
@@ -316,31 +316,31 @@  discard block
 block discarded – undo
316 316
 		return $this;
317 317
 	}
318 318
 
319
-	public function asSearch($name = NULL, $multiple = false, $selection = true) {
319
+	public function asSearch($name=NULL, $multiple=false, $selection=true) {
320 320
 		$this->asSelect($name, $multiple, $selection);
321 321
 		return $this->addToProperty("class", "search");
322 322
 	}
323 323
 
324
-	public function setSelect($name = NULL, $multiple = false) {
325
-		$this->_template = '<%tagName% id="%identifier%" %properties%>%items%</%tagName%>';
326
-		if (! isset($name))
327
-			$name = "select-" . $this->identifier;
328
-		$this->input = null;
324
+	public function setSelect($name=NULL, $multiple=false) {
325
+		$this->_template='<%tagName% id="%identifier%" %properties%>%items%</%tagName%>';
326
+		if (!isset($name))
327
+			$name="select-".$this->identifier;
328
+		$this->input=null;
329 329
 		if ($multiple) {
330 330
 			$this->setProperty("multiple", true);
331 331
 			$this->addToProperty("class", "multiple");
332 332
 		}
333 333
 		$this->setAction("activate");
334
-		$this->tagName = "select";
334
+		$this->tagName="select";
335 335
 		$this->setProperty("name", $name);
336
-		$this->content = null;
336
+		$this->content=null;
337 337
 		foreach ($this->items as $item) {
338 338
 			$item->asOption();
339 339
 		}
340 340
 		return $this;
341 341
 	}
342 342
 
343
-	public function asSubmenu($pointing = NULL) {
343
+	public function asSubmenu($pointing=NULL) {
344 344
 		$this->setClass("ui dropdown link item");
345 345
 		if (isset($pointing)) {
346 346
 			$this->setPointing($pointing);
@@ -348,29 +348,29 @@  discard block
 block discarded – undo
348 348
 		return $this;
349 349
 	}
350 350
 
351
-	public function setPointing($value = Direction::NONE) {
352
-		return $this->addToPropertyCtrl("class", $value . " pointing", Direction::getConstantValues("pointing"));
351
+	public function setPointing($value=Direction::NONE) {
352
+		return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing"));
353 353
 	}
354 354
 
355 355
 	public function setValue($value) {
356
-		$this->value = $value;
356
+		$this->value=$value;
357 357
 		return $this;
358 358
 	}
359 359
 
360 360
 	public function setDefaultText($text) {
361
-		$this->content["text"] = new HtmlSemDoubleElement("", "div", "default text", $text);
361
+		$this->content["text"]=new HtmlSemDoubleElement("", "div", "default text", $text);
362 362
 		return $this;
363 363
 	}
364 364
 
365 365
 	private function applyValue() {
366
-		$value = $this->value;
366
+		$value=$this->value;
367 367
 		if (isset($this->input) && isset($value)) {
368 368
 			$this->input->setProperty("value", $value);
369 369
 		} else {
370 370
 			$this->setProperty("value", $value);
371 371
 		}
372
-		$textElement = $this->getElementById("text-" . $this->identifier, $this->content);
373
-		if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && ! $this->_multiple)
372
+		$textElement=$this->getElementById("text-".$this->identifier, $this->content);
373
+		if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple)
374 374
 			$textElement->setContent($value);
375 375
 		return $this;
376 376
 	}
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
 	 * @see BaseHtml::run()
381 381
 	 */
382 382
 	public function run(JsUtils $js) {
383
-		if ($this->propertyContains("class", "simple") === false) {
384
-			if (isset($this->_bsComponent) === false) {
385
-				$this->_bsComponent = $js->semantic()->dropdown("#" . $this->identifier, $this->_params);
383
+		if ($this->propertyContains("class", "simple")===false) {
384
+			if (isset($this->_bsComponent)===false) {
385
+				$this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier, $this->_params);
386 386
 				$this->_bsComponent->setItemSelector(".item");
387 387
 			}
388 388
 			$this->addEventsOnRun($js);
@@ -397,31 +397,31 @@  discard block
 block discarded – undo
397 397
 	}
398 398
 
399 399
 	public function setAction($action) {
400
-		$this->_params["action"] = $action;
400
+		$this->_params["action"]=$action;
401 401
 		return $this;
402 402
 	}
403 403
 
404 404
 	public function setOn($on) {
405
-		$this->_params["on"] = $on;
405
+		$this->_params["on"]=$on;
406 406
 		return $this;
407 407
 	}
408 408
 
409 409
 	public function setShowOnFocus($value) {
410
-		$this->_params["showOnFocus"] = $value;
410
+		$this->_params["showOnFocus"]=$value;
411 411
 		return $this;
412 412
 	}
413 413
 
414 414
 	public function setAllowAdditions($value) {
415
-		$this->_params["allowAdditions"] = $value;
415
+		$this->_params["allowAdditions"]=$value;
416 416
 		return $this;
417 417
 	}
418 418
 
419 419
 	public function setFullTextSearch($value) {
420
-		$this->_params["fullTextSearch"] = $value;
420
+		$this->_params["fullTextSearch"]=$value;
421 421
 		return $this;
422 422
 	}
423 423
 
424
-	public function compile(JsUtils $js = NULL, &$view = NULL) {
424
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
425 425
 		$this->applyValue();
426 426
 		return parent::compile($js, $view);
427 427
 	}
@@ -430,19 +430,19 @@  discard block
 block discarded – undo
430 430
 		return $this->input;
431 431
 	}
432 432
 
433
-	public function setIcon($icon = "dropdown") {
434
-		$this->content["arrow"] = new HtmlIcon($this->identifier . "-icon", $icon);
433
+	public function setIcon($icon="dropdown") {
434
+		$this->content["arrow"]=new HtmlIcon($this->identifier."-icon", $icon);
435 435
 		return $this;
436 436
 	}
437 437
 
438
-	public function jsAddItem($caption, $value = null) {
439
-		$value = $value ?? $caption;
440
-		$js = "var first=$('#{$this->identifier} .item').first();if(first!=undefined){var newItem =first.clone();first.parent().append(newItem);newItem.html({$caption});newItem.attr('data-value',{$value}).removeClass('active filtered');}";
438
+	public function jsAddItem($caption, $value=null) {
439
+		$value=$value ?? $caption;
440
+		$js="var first=$('#{$this->identifier} .item').first();if(first!=undefined){var newItem =first.clone();first.parent().append(newItem);newItem.html({$caption});newItem.attr('data-value',{$value}).removeClass('active filtered');}";
441 441
 		return $js;
442 442
 	}
443 443
 
444 444
 	public function setClearable($value) {
445
-		$this->_params["clearable"] = $value;
445
+		$this->_params["clearable"]=$value;
446 446
 		return $this;
447 447
 	}
448 448
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	 * Parameters addedValue, addedText, $addedChoice
452 452
 	 */
453 453
 	public function setOnAdd($jsCode) {
454
-		$this->_params["onAdd"] = $jsCode;
454
+		$this->_params["onAdd"]=$jsCode;
455 455
 		return $this;
456 456
 	}
457 457
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 	 * Parameters removedValue, removedText, $removedChoice
461 461
 	 */
462 462
 	public function setOnRemove($jsCode) {
463
-		$this->_params["onRemove"] = $jsCode;
463
+		$this->_params["onRemove"]=$jsCode;
464 464
 		return $this;
465 465
 	}
466 466
 }
Please login to merge, or discard this patch.