|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Elements: Tabs. |
|
4
|
|
|
* |
|
5
|
|
|
* A tabbed element. |
|
6
|
|
|
* |
|
7
|
|
|
* @since 3.11.0 |
|
8
|
|
|
* @package Wordlift |
|
9
|
|
|
* @subpackage Wordlift/admin |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Define the {@link Wordlift_Admin_Tabs_Element} class. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 3.11.0 |
|
16
|
|
|
* @package Wordlift |
|
17
|
|
|
* @subpackage Wordlift/admin |
|
18
|
|
|
*/ |
|
19
|
|
|
class Wordlift_Admin_Tabs_Element implements Wordlift_Admin_Element { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Render the element. |
|
23
|
|
|
* |
|
24
|
|
|
* @since 3.11.0 |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $args { |
|
27
|
|
|
* Parameters controlling the html being output. |
|
28
|
|
|
* |
|
29
|
|
|
* @type integer $active The index of the active panel on first render |
|
30
|
|
|
* a zero based number of the tab actual placement |
|
31
|
|
|
* |
|
32
|
|
|
* @type array $tabs { |
|
33
|
|
|
* The array of tabs to be rendered. |
|
34
|
|
|
* The index of the elements is expected to be an ascending integers |
|
35
|
|
|
* tabs with lower index values will be render first (on the left) |
|
36
|
|
|
* |
|
37
|
|
|
* @type string $label The label used for the tab. |
|
38
|
|
|
* @type callable $callback The callback to call to render the |
|
39
|
|
|
* Tab "panel". |
|
40
|
|
|
* @type array $args The arguments array passed to the callback. |
|
41
|
|
|
* } |
|
42
|
|
|
* } |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Wordlift_Admin_Element The element instance. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function render( $args ) { |
|
47
|
|
|
|
|
48
|
|
|
// Enqueue the jQuery UI Tabs script. |
|
49
|
|
|
wp_enqueue_script( 'jquery-ui-tabs' ); |
|
50
|
|
|
|
|
51
|
|
|
// Parse the arguments and merge with default values. |
|
52
|
|
|
$params = wp_parse_args( $args, array( |
|
53
|
|
|
'tabs' => array(), |
|
54
|
|
|
'active' => 0, |
|
55
|
|
|
) ); |
|
56
|
|
|
|
|
57
|
|
|
// Following is the HTML code: |
|
58
|
|
|
// - the labels are printed, using the tab's `label`, |
|
59
|
|
|
// - the panels are printed, using the tab's `callback`. |
|
60
|
|
|
?> |
|
61
|
|
|
<div class="wl-tabs-element" |
|
62
|
|
|
data-active="<?php echo esc_attr( $params['active'] ); ?>"> |
|
63
|
|
|
<ul class="nav-tab-wrapper"> |
|
64
|
|
|
<?php foreach ( $params['tabs'] as $index => $tab ) { ?> |
|
65
|
|
|
<li class="nav-tab"> |
|
66
|
|
|
<a href="#tabs-<?php echo $index + 1; ?>"><?php |
|
67
|
|
|
echo esc_html( $tab['label'] ); ?></a> |
|
68
|
|
|
</li> |
|
69
|
|
|
<?php } ?> |
|
70
|
|
|
</ul> |
|
71
|
|
|
<?php foreach ( $params['tabs'] as $index => $tab ) { ?> |
|
72
|
|
|
<div id="tabs-<?php echo $index + 1; ?>"> |
|
73
|
|
|
<?php call_user_func( $tab['callback'], $tab['args'] ); ?> |
|
74
|
|
|
</div> |
|
75
|
|
|
<?php } ?> |
|
76
|
|
|
</div> |
|
77
|
|
|
|
|
78
|
|
|
<?php |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|