phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlTabs.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\bootstrap\html;
4
12use Ajax\JsUtils;
16
18 protected $tabs=array ();
19 protected $_tabsType="tabs";
20 protected $stacked="";
21
22 public function __construct($identifier, $tagName="ul") {
23 parent::__construct($identifier, $tagName);
24 $this->_template="<%tagName% %properties%>%tabs%</%tagName%>%content%";
25 $this->setProperty("class", "nav nav-".$this->_tabsType);
26 }
27
28 protected function addTab_($tab, $index=null) {
29 if($tab instanceof HtmlDropdown){
30 $tab->setMTagName("li");
31 }
32 if (isset($index)) {
33 $inserted=array (
34 $tab
35 );
36 array_splice($this->tabs, $index, 0, $inserted);
37 } else
38 $this->tabs []=$tab;
39 }
40
41 public function setActive($index){
42 $size=\sizeof($this->tabs);
43 for ($i=0;$i<$size;$i++){
44 $this->tabs[$i]->setActive($i==$index);
45 }
46 }
47
48 public function disable($index){
49 $this->tabs[$index]->disable();
50 }
51
52 public function addTab($element, $index=null) {
53 $iid=$this->countTabs()+1;
54 $tab=$element;
55 if (is_string($element)) {
56 $tab=new HtmlTabItem("tab-".$this->identifier."-".$iid, $element);
57 $this->addTab_($tab, $index);
58 } elseif (\is_array($element)) {
59 $tab=new HtmlTabItem("tab-".$this->identifier."-".$iid);
60 $tab->fromArray($element);
61 $this->addTab_($tab, $index);
62 } else {
63 $this->addTab_($tab, $index);
64 }
65 return $tab;
66 }
67
68 /*
69 * (non-PHPdoc)
70 * @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray()
71 */
72 public function fromArray($array) {
73 $array=parent::fromArray($array);
74 $this->addTabs($array);
75 return $array;
76 }
77
78 public function addTabs($tabs) {
79 foreach ( $tabs as $tab ) {
80 $this->addTab($tab);
81 }
82 return $this;
83 }
84
85 public function getTabstype() {
86 return $this->_tabsType;
87 }
88
89 public function setTabstype($_tabsType="tabs") {
90 $this->_tabsType=$_tabsType;
91 return $this;
92 }
93
94 /*
95 * (non-PHPdoc)
96 * @see \Ajax\bootstrap\html\BaseHtml::compile()
97 */
98 public function compile(JsUtils $js=NULL, &$view=NULL) {
99 $this->setProperty("class", "nav nav-".$this->_tabsType." ".$this->stacked);
100 return parent::compile($js, $view);
101 }
102
103 /*
104 * (non-PHPdoc)
105 * @see \Ajax\bootstrap\html\HtmlDoubleElement::run()
106 */
107 public function run(JsUtils $js) {
108 $this->_bsComponent=new Tabs($js);
109 foreach ( $this->tabs as $tab ) {
110 $this->_bsComponent->addTab($tab->run($js));
111 }
112 $this->addEventsOnRun($js);
113 return $this->_bsComponent;
114 }
115
116 public function createTabContents() {
117 $tabContent=new HtmlTabContent("tabcontent-".$this->identifier);
118 foreach ( $this->tabs as $tab ) {
119 if ($tab instanceof HtmlTabItem)
120 $tabContent->addTabItem($tab->getHref());
121 elseif ($tab instanceof HtmlDropdown) {
122 foreach ( $tab->getItems() as $dropdownItem ) {
123 $tabContent->addTabItem($dropdownItem->getHref());
124 }
125 }
126 }
127 return $tabContent;
128 }
129
130 public function addTabContents() {
131 $this->content=$this->createTabContents();
132 }
133
134 public function getTabContent($index) {
135 $this->content->getTabItem($index);
136 }
137
138 public function setContentToTab($index, $text) {
139 $tabContentItem=$this->content->getTabItem($index);
140 if (isset($tabContentItem))
141 $tabContentItem->setContent($text);
142 }
143
144 public function countTabs() {
145 return sizeof($this->tabs);
146 }
147
148 public function getTabItem($index) {
149 if ($index<sizeof($this->content->get))
150 return $this->content;
151 }
152
153 public function fadeEffect() {
154 if (sizeof($this->content->getTabItems())>0) {
155 $this->content->getTabItem(0)->addToProperty("class", "fade in");
156 $size=sizeof($this->tabs);
157 for($index=0; $index<$size; $index++) {
158 $this->content->getTabItem($index)->addToProperty("class", "fade");
159 }
160 }
161 }
162
163 public function on($event, $jsCode,$stopPropagation=false,$preventDefault=false){
164 foreach ($this->tabs as $tab){
165 $tab->on($event,$jsCode,$stopPropagation,$preventDefault);
166 }
167 return $this;
168 }
169
170 public function setStacked($stacked=true){
171 if($stacked)
172 $this->stacked="nav-stacked";
173 else $this->stacked="";
174 }
175
176 /* (non-PHPdoc)
177 * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
178 */
179 public function fromDatabaseObject($object, $function) {
180 $this->addTab($function($object));
181 }
182}
JQuery PHP library.
Definition JsUtils.php:23
Composant Twitter Bootstrap Tab.
Definition Tabs.php:13
Twitter Bootstrap HTML Dropdown component.
__construct($identifier, $tagName="ul")
Definition HtmlTabs.php:22
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()
Definition HtmlTabs.php:107
setTabstype($_tabsType="tabs")
Definition HtmlTabs.php:89
compile(JsUtils $js=NULL, &$view=NULL)
Definition HtmlTabs.php:98
addTab_($tab, $index=null)
Definition HtmlTabs.php:28
addTab($element, $index=null)
Definition HtmlTabs.php:52
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
Definition HtmlTabs.php:163
setContentToTab($index, $text)
Definition HtmlTabs.php:138
fromDatabaseObject($object, $function)
Definition HtmlTabs.php:179
Twitter Bootstrap HTML TabContent component.
Inner element for Twitter Bootstrap HTML Dropdown component.