1 <?php
2 3 4 5 6 7 8 9 10
11 namespace uix\ui;
12
13 14 15 16 17 18
19 class panel extends \uix\data\data{
20
21 22 23 24 25 26 27
28 public $type = 'panel';
29
30 31 32 33 34 35
36 protected function enqueue_active_assets(){
37
38 ?><style type="text/css">
39 > .uix-panel-tabs > li[aria-selected="true"] a {
40 box-shadow: 3px 0 0 <?php echo $this->base_color(); ?> inset;
41 }
42 .uix-top-tabs > .uix-panel-tabs > li[aria-selected="true"] a {
43 box-shadow: 0 3px 0 <?php echo $this->base_color(); ?> inset;
44 }
45
46 </style>
47 <?php
48 }
49
50
51 52 53 54 55 56
57 public function set_assets() {
58
59 $this->assets['script']['panel'] = $this->url . 'assets/js/panel' . UIX_ASSET_DEBUG . '.js';
60 $this->assets['style']['panel'] = $this->url . 'assets/css/panel' . UIX_ASSET_DEBUG . '.css';
61
62 parent::set_assets();
63
64 }
65
66
67 68 69 70 71 72 73
74 public function get_data(){
75
76 if( empty( $this->data ) ){
77
78 $data = array(
79 $this->slug => array()
80 );
81
82 foreach ($this->child as $child){
83 if ( null !== $child->get_data() )
84 $data[$this->slug] += $child->get_data();
85 }
86
87 if( empty( $data ) )
88 $data = null;
89
90 $this->data = $data;
91 }
92
93
94
95 return $this->data;
96 }
97
98 99 100 101 102 103
104 public function set_data( $data ){
105
106 if( !empty( $data[ $this->slug ] ) ){
107 foreach ($this->child as $child){
108 if (method_exists($child, 'set_data'))
109 $child->set_data($data[$this->slug]);
110
111 }
112 }
113
114 }
115
116 117 118 119 120 121
122 public function render(){
123 $output = null;
124
125 if( $this->child_count() > 0 ) {
126
127 $output .= '<div id="panel-' . esc_attr( $this->id() ) . '" class="uix-' . esc_attr($this->type) . '-inside ' . esc_attr($this->wrapper_class_names()) . '">';
128
129 $output .= $this->label();
130
131 $output .= $this->description();
132
133 $output .= $this->navigation();
134
135 $output .= $this->panel_section();
136
137
138 $output .= '</div>';
139 }
140
141 $output .= $this->render_template();
142
143 return $output;
144 }
145
146 147 148 149 150 151 152
153 public function navigation(){
154 $output = null;
155
156 if( $this->child_count() > 1 ) {
157
158 $output .= '<ul class="uix-' . esc_attr($this->type) . '-tabs uix-panel-tabs">';
159 $active = 'true';
160 foreach ($this->child as $child) {
161 if ( $this->is_section_object( $child ) ){
162 $output .= $this->tab_label($child, $active);
163 $active = 'false';
164 }
165
166 }
167 $output .= '</ul>';
168 }
169 return $output;
170 }
171
172 173 174 175 176 177 178
179 public function child_count(){
180
181 $count = 0;
182 if( !empty( $this->child ) ){
183 foreach( $this->child as $child ){
184 if ( $this->is_section_object( $child ) ){
185 $count++;
186 }
187 }
188 }
189
190 return $count;
191 }
192
193 194 195 196 197 198 199 200 201
202 private function tab_label( $child, $active ){
203
204 $output = null;
205
206 $label = esc_html( $child->struct['label'] );
207
208 if( !empty( $child->struct['icon'] ) )
209 $label = '<i class="dashicons ' . $child->struct['icon'] . '"></i><span class="label">' . esc_html( $child->struct['label'] ) . '</span>';
210
211 $output .= '<li aria-selected="' . esc_attr( $active ) . '">';
212 $output .= '<a href="#' . esc_attr( $child->id() ) . '" data-parent="' . esc_attr( $this->id() ) . '" class="uix-tab-trigger">' . $label . '</a>';
213 $output .= '</li>';
214
215 return $output;
216 }
217
218 219 220 221 222 223 224
225 public function label(){
226 $output = null;
227 if( !empty( $this->struct['label'] ) )
228 $output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><h3 class="uix-' . esc_attr( $this->type ) . '-title">' . esc_html( $this->struct['label'] ) . '</h3></div>';
229
230 return $output;
231 }
232
233 234 235 236 237 238 239
240 public function description(){
241 $output = null;
242 if( !empty( $this->struct['description'] ) )
243 $output .= '<div class="uix-' . esc_attr( $this->type ) . '-heading"><p class="uix-' . esc_attr( $this->type ) . '-subtitle description">' . esc_html( $this->struct['description'] ) . '</p></div>';
244
245 return $output;
246 }
247
248 249 250 251 252 253 254 255
256 public function is_section_object( $section ){
257 return !in_array( $section->type, array( 'help', 'header', 'footer' ) );
258 }
259
260 261 262 263 264 265 266
267 public function panel_section(){
268 $output = null;
269
270
271 $output .= '<div class="uix-' . esc_attr( $this->type ) . '-sections uix-sections">';
272
273 $hidden = 'false';
274 foreach( $this->child as $section ){
275
276 if ( !$this->is_section_object( $section ) )
277 continue;
278
279 $section->struct['active'] = $hidden;
280 $output .= $section->render();
281 $hidden = 'true';
282 }
283
284 $output .= '</div>';
285
286 return $output;
287 }
288
289 290 291 292 293 294 295
296 public function render_template(){
297
298 $_output = null;
299
300 if( !empty( $this->struct['template'] ) ){
301 ob_start();
302 include $this->struct['template'];
303 $_output .= ob_get_clean();
304 }
305
306 return $_output;
307 }
308
309
310 311 312 313 314 315
316 public function wrapper_class_names(){
317
318 $wrapper_class_names = array(
319 'uix-panel-inside'
320 );
321
322 if( $this->child_count() > 1 )
323 $wrapper_class_names[] = 'uix-has-tabs';
324
325 if( !empty( $this->struct['top_tabs'] ) )
326 $wrapper_class_names[] = 'uix-top-tabs';
327
328 return implode( ' ', $wrapper_class_names );
329 }
330 }