1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
/** |
7
|
|
|
* Semantic UI Buttongroups component |
8
|
|
|
* @see http://semantic-ui.com/elements/button.html |
9
|
|
|
* @author jc |
10
|
|
|
* @version 1.001 |
11
|
|
|
*/ |
12
|
|
|
class HtmlButtonGroups extends HtmlSemDoubleElement { |
13
|
|
|
|
14
|
|
|
public function __construct($identifier, $elements=array(),$asIcons=false) { |
15
|
|
|
parent::__construct($identifier, "div"); |
16
|
|
|
$this->setProperty("class", "ui buttons"); |
17
|
|
|
$this->content=array(); |
18
|
|
|
if($asIcons===true) |
19
|
|
|
$this->asIcons(); |
20
|
|
|
$this->addElements($elements,$asIcons); |
21
|
|
|
} |
22
|
|
|
public function addElement($element,$asIcon=false){ |
23
|
|
|
$elementO=$element; |
24
|
|
|
if(\is_string($element)){ |
25
|
|
|
if($asIcon){ |
26
|
|
|
$elementO=new HtmlButton("button-".\sizeof($this->content)); |
27
|
|
|
$elementO->asIcon($element); |
28
|
|
|
}else |
29
|
|
|
$elementO=new HtmlButton("button-".\sizeof($this->content),$element); |
30
|
|
|
} |
31
|
|
|
$this->addContent($elementO); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function addElements($elements,$asIcons=false) { |
36
|
|
|
foreach ( $elements as $element ) { |
37
|
|
|
$this->addElement($element,$asIcons); |
38
|
|
|
} |
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function insertOr($aferIndex=0,$or="OR"){ |
43
|
|
|
$orElement=new HtmlSemDoubleElement("or-".$this->identifier,"div"); |
44
|
|
|
$orElement->setClass("or"); |
45
|
|
|
$orElement->setProperty("data-text", $or); |
46
|
|
|
array_splice($this->content, $aferIndex+1, 0, array($orElement)); |
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
/* |
50
|
|
|
* (non-PHPdoc) |
51
|
|
|
* @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray() |
52
|
|
|
*/ |
53
|
|
|
public function fromArray($array) { |
54
|
|
|
$this->addElements($array); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function asIcons(){ |
58
|
|
|
return $this->addToProperty("class", "icons"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setVertical(){ |
62
|
|
|
return $this->addToProperty("class", "vertical"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setLabeled(){ |
66
|
|
|
return $this->addToProperty("class", "labeled icon"); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Return the element at index |
71
|
|
|
* @param int $index |
72
|
|
|
* @return HtmlButton |
73
|
|
|
*/ |
74
|
|
|
public function getElement($index) { |
75
|
|
|
if (is_int($index)) |
76
|
|
|
return $this->content[$index]; |
77
|
|
|
else { |
78
|
|
|
$elm=$this->getElementById($index, $this->content); |
79
|
|
|
return $elm; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setElement($index, $button) { |
84
|
|
|
$this->content[$index]=$button; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/* |
89
|
|
|
* (non-PHPdoc) |
90
|
|
|
* @see \Ajax\bootstrap\html\base\BaseHtml::on() |
91
|
|
|
*/ |
92
|
|
|
public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
93
|
|
|
foreach ( $this->content as $element ) { |
94
|
|
|
$element->on($event, $jsCode, $stopPropagation, $preventDefault); |
95
|
|
|
} |
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getElements() { |
100
|
|
|
return $this->content; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/* (non-PHPdoc) |
104
|
|
|
* @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
105
|
|
|
*/ |
106
|
|
|
public function fromDatabaseObject($object, $function) { |
107
|
|
|
$this->addElement($function($object)); |
108
|
|
|
} |
109
|
|
|
} |