1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
<?php /* Widget Name: Tabs Description: A tabby widget to switch between tabbed content panels. Author: SiteOrigin Author URI: https://siteorigin.com Documentation: https://siteorigin.com/widgets-bundle/tabs-widget/ */
class SiteOrigin_Widget_Tabs_Widget extends SiteOrigin_Widget { function __construct() { parent::__construct( 'sow-tabs', __( 'SiteOrigin Tabs', 'so-widgets-bundle' ), array( 'description' => __( 'A tabs widget.', 'so-widgets-bundle' ), 'help' => 'https://siteorigin.com/widgets-bundle/tabs-widget/', ), array(), false, plugin_dir_path( __FILE__ ) ); } /** * Initialize the tabs widget. */ function initialize() { $this->register_frontend_scripts( array( array( 'sow-tabs', plugin_dir_url( __FILE__ ) . 'js/tabs' . SOW_BUNDLE_JS_SUFFIX . '.js', array( 'jquery' ), SOW_BUNDLE_VERSION ) ) ); } function get_widget_form() { return array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'so-widgets-bundle' ), ), 'tabs' => array( 'type' => 'repeater', 'label' => __( 'Tabs', 'so-widgets-bundle' ), 'item_label' => array( 'selector' => "[id*='tabs-title']", 'update_event' => 'change', 'value_method' => 'val' ), 'fields' => array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'so-widgets-bundle' ), ), 'content_text' => array( 'type' => 'tinymce', 'label' => __( 'Content', 'so-widgets-bundle' ), ), ), ), 'initial_tab_position' => array( 'type' => 'number', 'label' => __( 'Initially selected tab', 'so-widgets-bundle' ), 'default' => 1, 'description' => __( 'The position of the tab to be selected when the page first loads.', 'so-widgets-bundle' ), ), 'design' => array( 'type' => 'section', 'label' => __( 'Design', 'so-widgets-bundle' ), 'hide' => true, 'fields' => array( 'tabs_container' => array( 'type' => 'section', 'label' => __( 'Tabs container', 'so-widgets-bundle' ), 'hide' => true, 'fields' => array( 'background_color' => array( 'type' => 'color', 'label' => __( 'Background color', 'so-widgets-bundle' ), 'default' => '#828282', ), 'border_color' => array( 'type' => 'color', 'label' => __( 'Border color', 'so-widgets-bundle' ), ), 'border_width' => array( 'type' => 'measurement', 'label' => __( 'Border width', 'so-widgets-bundle' ), ), ), ), 'tabs' => array( 'type' => 'section', 'label' => __( 'Tabs', 'so-widgets-bundle' ), 'hide' => true, 'fields' => array( 'background_color' => array( 'type' => 'color', 'label' => __( 'Background color', 'so-widgets-bundle' ), ), 'background_hover_color' => array( 'type' => 'color', 'label' => __( 'Background hover color', 'so-widgets-bundle' ), 'default' => '#F9F9F9', ), 'title_color' => array( 'type' => 'color', 'label' => __( 'Title color', 'so-widgets-bundle' ), 'default' => '#FFFFFF', ), 'title_hover_color' => array( 'type' => 'color', 'label' => __( 'Title hover color', 'so-widgets-bundle' ), 'default' => '#2D2D2D', ), 'border_color' => array( 'type' => 'color', 'label' => __( 'Border color', 'so-widgets-bundle' ), 'default' => '#828282', ), 'border_hover_color' => array( 'type' => 'color', 'label' => __( 'Border hover color', 'so-widgets-bundle' ), 'default' => '#F9F9F9', ), 'border_width' => array( 'type' => 'measurement', 'label' => __( 'Border width', 'so-widgets-bundle' ), ), 'border_hover_width' => array( 'type' => 'measurement', 'label' => __( 'Border hover width', 'so-widgets-bundle' ), ), ), ), 'panels' => array( 'type' => 'section', 'label' => __( 'Panels', 'so-widgets-bundle' ), 'hide' => true, 'fields' => array( 'background_color' => array( 'type' => 'color', 'label' => __( 'Background color', 'so-widgets-bundle' ), 'default' => '#F9F9F9', ), 'font_color' => array( 'type' => 'color', 'label' => __( 'Font color', 'so-widgets-bundle' ), ), 'border_color' => array( 'type' => 'color', 'label' => __( 'Border color', 'so-widgets-bundle' ), ), 'border_width' => array( 'type' => 'measurement', 'label' => __( 'Border width', 'so-widgets-bundle' ), ), ), ), ), ), ); } public function get_less_variables( $instance ) { if ( empty( $instance ) || empty( $instance['design'] ) ) { return array(); }
$design = $instance['design']; return array( 'tabs_container_background_color' => $design['tabs_container']['background_color'], 'tabs_container_border_color' => $design['tabs_container']['border_color'], 'tabs_container_border_width' => $design['tabs_container']['border_width'], 'has_tabs_container_border_width' => empty( $design['tabs_container']['border_width'] ) ? 'false' : 'true', 'tabs_background_color' => $design['tabs']['background_color'], 'tabs_background_hover_color' => $design['tabs']['background_hover_color'], 'tabs_title_color' => $design['tabs']['title_color'], 'tabs_title_hover_color' => $design['tabs']['title_hover_color'], 'tabs_border_color' => $design['tabs']['border_color'], 'tabs_border_hover_color' => $design['tabs']['border_hover_color'], 'tabs_border_width' => $design['tabs']['border_width'], 'has_tabs_border_width' => empty( $design['tabs']['border_width'] ) ? 'false' : 'true', 'tabs_border_hover_width' => $design['tabs']['border_hover_width'], 'has_tabs_border_hover_width' => empty( $design['tabs']['border_hover_width'] ) ? 'false' : 'true', 'panels_background_color' => $design['panels']['background_color'], 'panels_font_color' => $design['panels']['font_color'], 'panels_border_color' => $design['panels']['border_color'], 'panels_border_width' => $design['panels']['border_width'], 'has_panels_border_width' => empty( $design['panels']['border_width'] ) ? 'false' : 'true', ); } public function get_template_variables( $instance, $args ) { if( empty( $instance ) ) return array(); $tabs = empty( $instance['tabs'] ) ? array() : $instance['tabs']; foreach ( $tabs as $i => &$tab ) { if ( empty( $tab['before_title'] ) ) { $tab['before_title'] = ''; } if ( empty( $tab['after_title'] ) ) { $tab['after_title'] = ''; } if ( empty( $tab['title'] ) ) { $id = $this->id_base; if ( ! empty( $instance['_sow_form_id'] ) ) { $id .= '-' . $instance['_sow_form_id']; } else if ( ! empty( $args['widget_id'] ) ) { $id .= '-' . $args['widget_id']; } $tab['anchor'] = $id . '-' . $i; } else { $tab['anchor'] = $tab['title']; } } if ( empty( $instance['initial_tab_position'] ) || $instance['initial_tab_position'] < 1 || $instance['initial_tab_position'] > count( $tabs ) ) { $init_tab_index = 0; } else { $init_tab_index = $instance['initial_tab_position'] - 1; } return array( 'tabs' => $tabs, 'initial_tab_index' => $init_tab_index, ); } public function render_panel_content( $panel, $instance ) { $content = wp_kses_post( $panel['content_text'] ); echo apply_filters( 'siteorigin_widgets_tabs_render_panel_content', $content, $panel, $instance ); } function get_form_teaser(){ if( class_exists( 'SiteOrigin_Premium' ) ) return false; return sprintf( __( 'Get more customization options and the ability to use widgets and layouts as your tabs content with %sSiteOrigin Premium%s', 'so-widgets-bundle' ), '<a href="https://siteorigin.com/downloads/premium/?featured_addon=plugin/tabs" target="_blank">', '</a>' ); } }
siteorigin_widget_register('sow-tabs', __FILE__, 'SiteOrigin_Widget_Tabs_Widget');
|