PluginProbe
Ever Compare – Products Compare Plugin for WooCommerce / 1.0.2
Ever Compare – Products Compare Plugin for WooCommerce v1.0.2
1.3.7 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 trunk 1.0.0 1.0.1 1.0.2 All 31 releases
ever-compare / includes / classes / Admin / Settings_APi.php

Settings_APi.php in Ever Compare – Products Compare Plugin for WooCommerce 1.0.2, at includes/classes/Admin/Settings_APi.php

717 lines 26.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EverCompare\Admin;
3 /**
4 * Settings Api class
5 */
6 class Settings_APi {
7
8 /**
9 * settings sections array
10 *
11 * @var array
12 */
13 protected $settings_sections = array();
14
15 /**
16 * Settings fields array
17 *
18 * @var array
19 */
20 protected $settings_fields = array();
21
22 public function __construct() {
23 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
24 }
25
26 /**
27 * Enqueue scripts and styles
28 */
29 function admin_enqueue_scripts() {
30 wp_enqueue_style( 'wp-color-picker' );
31 wp_enqueue_media();
32 wp_enqueue_script( 'wp-color-picker' );
33 wp_enqueue_script( 'jquery-ui-sortable' );
34 wp_enqueue_script( 'jquery' );
35 }
36
37 /**
38 * Set settings sections
39 *
40 * @param array $sections setting sections array
41 */
42 function set_sections( $sections ) {
43 $this->settings_sections = $sections;
44
45 return $this;
46 }
47
48 /**
49 * Add a single section
50 *
51 * @param array $section
52 */
53 function add_section( $section ) {
54 $this->settings_sections[] = $section;
55
56 return $this;
57 }
58
59 /**
60 * Set settings fields
61 *
62 * @param array $fields settings fields array
63 */
64 function set_fields( $fields ) {
65 $this->settings_fields = $fields;
66
67 return $this;
68 }
69
70 function add_field( $section, $field ) {
71 $defaults = array(
72 'name' => '',
73 'label' => '',
74 'desc' => '',
75 'type' => 'text'
76 );
77
78 $arg = wp_parse_args( $field, $defaults );
79 $this->settings_fields[$section][] = $arg;
80
81 return $this;
82 }
83
84 /**
85 * Initialize and registers the settings sections and fileds to WordPress
86 *
87 * Usually this should be called at `admin_init` hook.
88 *
89 * This function gets the initiated settings sections and fields. Then
90 * registers them to WordPress and ready for use.
91 */
92 function admin_init() {
93
94 //register settings sections
95 foreach ( $this->settings_sections as $section ) {
96 if ( false == get_option( $section['id'] ) ) {
97 add_option( $section['id'] );
98 }
99
100 if ( isset($section['desc']) && !empty($section['desc']) ) {
101 $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
102 $callback = create_function('', 'echo "' . str_replace( '"', '\"', $section['desc'] ) . '";');
103 } else if ( isset( $section['callback'] ) ) {
104 $callback = $section['callback'];
105 } else {
106 $callback = null;
107 }
108
109 add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
110 }
111
112 //register settings fields
113 foreach ( $this->settings_fields as $section => $field ) {
114 foreach ( $field as $option ) {
115
116 $name = $option['name'];
117 $type = isset( $option['type'] ) ? $option['type'] : 'text';
118 $label = isset( $option['label'] ) ? $option['label'] : '';
119 $callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
120
121 $args = array(
122 'id' => $name,
123 'class' => isset( $option['class'] ) ? $option['class'] : $name,
124 'label_for' => "{$section}[{$name}]",
125 'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
126 'name' => $label,
127 'section' => $section,
128 'size' => isset( $option['size'] ) ? $option['size'] : null,
129 'options' => isset( $option['options'] ) ? $option['options'] : '',
130 'std' => isset( $option['default'] ) ? $option['default'] : '',
131 'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
132 'type' => $type,
133 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
134 'min' => isset( $option['min'] ) ? $option['min'] : '',
135 'max' => isset( $option['max'] ) ? $option['max'] : '',
136 'step' => isset( $option['step'] ) ? $option['step'] : '',
137 'headding' => isset( $option['headding'] ) ? $option['headding'] : '',
138 );
139
140 add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
141 }
142 }
143
144 // creates our settings in the options table
145 foreach ( $this->settings_sections as $section ) {
146 register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
147 }
148 }
149
150 /**
151 * Get field description for display
152 *
153 * @param array $args settings field args
154 */
155 public function get_field_description( $args ) {
156 if ( ! empty( $args['desc'] ) ) {
157 $desc = sprintf( '<p class="description">%s</p>', $args['desc'] );
158 } else {
159 $desc = '';
160 }
161 return $desc;
162 }
163
164 /**
165 * Get Title for display
166 *
167 * @param array $args settings field args
168 */
169 public function callback_title( $args ) {
170 $headding = isset( $args['headding'] ) ? $args['headding'] : '';
171 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
172 $html = sprintf( '<h2 class="element_section_title %1$s-title">%2$s</h2>', $size, $headding );
173 echo $html;
174 }
175
176 /**
177 * Displays a text field for a settings field
178 *
179 * @param array $args settings field args
180 */
181 function callback_text( $args ) {
182
183 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
184 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
185 $type = isset( $args['type'] ) ? $args['type'] : 'text';
186 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
187
188 $html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
189 $html .= $this->get_field_description( $args );
190
191 echo $html;
192 }
193
194 /**
195 * Displays a multitextbox for a settings field
196 *
197 * @param array $args settings field args
198 */
199 function callback_multitext( $args ) {
200
201 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
202 $html = '<fieldset>';
203 foreach ( $args['options'] as $key => $label ) {
204 $new_value = isset( $value[$key] ) ? $value[$key] : '';
205 $html .= sprintf( '<label for="htoptions_sp_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
206 $html .= sprintf( '<input type="text" class="multitextbox" id="htoptions_sp_%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%4$s" />', $args['section'], $args['id'], $key, $new_value );
207 $html .= sprintf( ' %1$s</label><br>', $label );
208 }
209
210 $html .= $this->get_field_description( $args );
211 $html .= '</fieldset>';
212
213 echo $html;
214 }
215
216 /**
217 * Displays a url field for a settings field
218 *
219 * @param array $args settings field args
220 */
221 function callback_url( $args ) {
222 $this->callback_text( $args );
223 }
224
225 /**
226 * Displays a number field for a settings field
227 *
228 * @param array $args settings field args
229 */
230 function callback_number( $args ) {
231 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
232 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
233 $type = isset( $args['type'] ) ? $args['type'] : 'number';
234 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
235 $min = ( $args['min'] == '' ) ? '' : ' min="' . $args['min'] . '"';
236 $max = ( $args['max'] == '' ) ? '' : ' max="' . $args['max'] . '"';
237 $step = ( $args['step'] == '' ) ? '' : ' step="' . $args['step'] . '"';
238
239 $html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
240 $html .= $this->get_field_description( $args );
241
242 echo $html;
243 }
244
245 /**
246 * Displays a checkbox for a settings field
247 *
248 * @param array $args settings field args
249 */
250 function callback_checkbox( $args ) {
251
252 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
253
254 $html = '<fieldset class="htoptions_element_checkbox">';
255 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
256 $html .= sprintf( '<input type="checkbox" class="checkbox" id="htoptions_sp_%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
257 $html .= sprintf( '<label for="htoptions_sp_%1$s[%2$s]">%3$s</label>', $args['section'], $args['id'], $args['desc'] );
258 $html .= sprintf( '<div class="htoption_checkbox_desc" id="htoptions_sp_%1$s[%2$s]">%3$s</div>', $args['section'], $args['id'], $args['desc'] );
259 $html .= '</fieldset>';
260
261 echo $html;
262 }
263
264 /**
265 * Displays a multicheckbox for a settings field
266 *
267 * @param array $args settings field args
268 */
269 function callback_multicheck( $args ) {
270
271 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
272 $html = '<fieldset>';
273 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
274 foreach ( $args['options'] as $key => $label ) {
275 $checked = isset( $value[$key] ) ? $value[$key] : '0';
276 $html .= sprintf( '<label for="htoptions_sp_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
277 $html .= sprintf( '<input type="checkbox" class="checkbox" id="htoptions_sp_%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
278 $html .= sprintf( '%1$s</label><br>', $label );
279 }
280
281 $html .= $this->get_field_description( $args );
282 $html .= '</fieldset>';
283
284 echo $html;
285 }
286
287 /**
288 * Displays a multicheckbox for a settings field
289 *
290 * @param array $args settings field args
291 */
292 function callback_multicheckshort( $args ) {
293
294 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
295 $html = '<fieldset><ul class="htoption_shortable">';
296 $html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
297 foreach ( $args['options'] as $key => $label ) {
298 $checked = isset( $value[$key] ) ? $value[$key] : '0';
299 $html .= sprintf( '<li><label for="htoptions_sp_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
300 $html .= sprintf( '<input type="checkbox" class="checkbox" id="htoptions_sp_%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
301 $html .= sprintf( '%1$s</label></li>', $label );
302 }
303
304 $html .= $this->get_field_description( $args );
305 $html .= '</ul></fieldset>';
306
307 echo $html;
308 }
309
310 /**
311 * Displays a radio button for a settings field
312 *
313 * @param array $args settings field args
314 */
315 function callback_radio( $args ) {
316
317 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
318 $html = '<fieldset>';
319
320 foreach ( $args['options'] as $key => $label ) {
321 $html .= sprintf( '<label for="htoptions_sp_%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
322 $html .= sprintf( '<input type="radio" class="radio" id="htoptions_sp_%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
323 $html .= sprintf( '%1$s</label><br>', $label );
324 }
325
326 $html .= $this->get_field_description( $args );
327 $html .= '</fieldset>';
328
329 echo $html;
330 }
331
332 /**
333 * Displays a selectbox for a settings field
334 *
335 * @param array $args settings field args
336 */
337 function callback_select( $args ) {
338
339 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
340 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
341 $html = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
342
343 foreach ( $args['options'] as $key => $label ) {
344 $html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
345 }
346
347 $html .= sprintf( '</select>' );
348 $html .= $this->get_field_description( $args );
349
350 echo $html;
351 }
352
353 /**
354 * Displays a multiselect for a settings field
355 *
356 * @param array $args settings field args
357 */
358 function callback_multiselect( $args ) {
359
360 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
361 $html = sprintf( '<select multiple="multiple" class="%1$s" name="%1$s[%2$s][]" id="%1$s[%2$s]">', $args['section'], $args['id'] );
362 foreach ( $args['options'] as $key => $label ) {
363 $selected = '';
364 if( !empty( $value ) ){
365 $selected = in_array( $key, $value ) ? $key : '';
366 }
367 $html .= sprintf( '<option value="%1$s" %2$s>%3$s</option>', $key, selected( $selected, $key, false ), $label );
368 }
369 $html .= sprintf( '</select>' );
370 $html .= $this->get_field_description( $args );
371
372 echo $html;
373 }
374
375 /**
376 * Displays a textarea for a settings field
377 *
378 * @param array $args settings field args
379 */
380 function callback_textarea( $args ) {
381
382 $value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
383 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
384 $placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
385
386 $html = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
387 $html .= $this->get_field_description( $args );
388
389 echo $html;
390 }
391
392 /**
393 * Displays the html for a settings field
394 *
395 * @param array $args settings field args
396 * @return string
397 */
398 function callback_html( $args ) {
399 echo $this->get_field_description( $args );
400 }
401
402 /**
403 * Displays a rich text textarea for a settings field
404 *
405 * @param array $args settings field args
406 */
407 function callback_wysiwyg( $args ) {
408
409 $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
410 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : '500px';
411
412 echo '<div style="max-width: ' . $size . ';">';
413
414 $editor_settings = array(
415 'teeny' => true,
416 'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
417 'textarea_rows' => 10
418 );
419
420 if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
421 $editor_settings = array_merge( $editor_settings, $args['options'] );
422 }
423
424 wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
425
426 echo '</div>';
427
428 echo $this->get_field_description( $args );
429 }
430
431 /**
432 * Displays a file upload field for a settings field
433 *
434 * @param array $args settings field args
435 */
436 function callback_file( $args ) {
437
438 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
439 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
440 $id = $args['section'] . '[' . $args['id'] . ']';
441 $label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File' );
442
443 $html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
444 $html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
445 $html .= $this->get_field_description( $args );
446
447 echo $html;
448 }
449
450 /**
451 * Displays a password field for a settings field
452 *
453 * @param array $args settings field args
454 */
455 function callback_password( $args ) {
456
457 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
458 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
459
460 $html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
461 $html .= $this->get_field_description( $args );
462
463 echo $html;
464 }
465
466 /**
467 * Displays a color picker field for a settings field
468 *
469 * @param array $args settings field args
470 */
471 function callback_color( $args ) {
472
473 $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
474 $size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
475
476 $html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
477 $html .= $this->get_field_description( $args );
478
479 echo $html;
480 }
481
482
483 /**
484 * Displays a select box for creating the pages select box
485 *
486 * @param array $args settings field args
487 */
488 function callback_pages( $args ) {
489
490 $dropdown_args = array(
491 'selected' => esc_attr($this->get_option($args['id'], $args['section'], $args['std'] ) ),
492 'name' => $args['section'] . '[' . $args['id'] . ']',
493 'id' => $args['section'] . '[' . $args['id'] . ']',
494 'echo' => 0
495 );
496 $html = wp_dropdown_pages( $dropdown_args );
497 echo $html;
498 }
499
500 /**
501 * Sanitize callback for Settings API
502 *
503 * @return mixed
504 */
505 function sanitize_options( $options ) {
506
507 if ( !$options ) {
508 return $options;
509 }
510
511 foreach( $options as $option_slug => $option_value ) {
512 $sanitize_callback = $this->get_sanitize_callback( $option_slug );
513
514 // If callback is set, call it
515 if ( $sanitize_callback ) {
516 $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
517 continue;
518 }
519 }
520
521 return $options;
522 }
523
524 /**
525 * Get sanitization callback for given option slug
526 *
527 * @param string $slug option slug
528 *
529 * @return mixed string or bool false
530 */
531 function get_sanitize_callback( $slug = '' ) {
532 if ( empty( $slug ) ) {
533 return false;
534 }
535
536 // Iterate over registered fields and see if we can find proper callback
537 foreach( $this->settings_fields as $section => $options ) {
538 foreach ( $options as $option ) {
539 if ( $option['name'] != $slug ) {
540 continue;
541 }
542
543 // Return the callback name
544 return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
545 }
546 }
547
548 return false;
549 }
550
551 /**
552 * Get the value of a settings field
553 *
554 * @param string $option settings field name
555 * @param string $section the section name this field belongs to
556 * @param string $default default text if it's not found
557 * @return string
558 */
559 function get_option( $option, $section, $default = '' ) {
560
561 $options = get_option( $section );
562
563 if ( isset( $options[$option] ) ) {
564 return $options[$option];
565 }
566
567 return $default;
568 }
569
570 /**
571 * Show navigations as tab
572 *
573 * Shows all the settings section labels as tab
574 */
575 function show_navigation() {
576 $html = '<h2 class="nav-tab-wrapper">';
577
578 $count = count( $this->settings_sections );
579
580 // don't show the navigation if only one section exists
581 if ( $count === 1 ) {
582 return;
583 }
584
585 foreach ( $this->settings_sections as $tab ) {
586 $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
587 }
588
589 $html .= '</h2>';
590
591 echo $html;
592 }
593
594 /**
595 * Show the section settings forms
596 *
597 * This function displays every sections in a different form
598 */
599 function show_forms() {
600 ?>
601 <div class="metabox-holder">
602 <?php foreach ( $this->settings_sections as $form ) { ?>
603 <div id="<?php echo $form['id']; ?>" class="group" style="display: none;">
604 <form method="post" action="options.php">
605 <?php
606 do_action( 'wsa_form_top_' . $form['id'], $form );
607 settings_fields( $form['id'] );
608 do_settings_sections( $form['id'] );
609 do_action( 'wsa_form_bottom_' . $form['id'], $form );
610 if ( isset( $this->settings_fields[ $form['id'] ] ) ):
611 ?>
612 <div class="wl-submit-button" style="padding-left: 10px">
613 <?php submit_button(); ?>
614 </div>
615 <?php endif; ?>
616 </form>
617 </div>
618 <?php } ?>
619 </div>
620 <?php
621 $this->script();
622 }
623
624 /**
625 * Tabbable JavaScript codes & Initiate Color Picker
626 *
627 * This code uses localstorage for displaying active tabs
628 */
629 function script() {
630 ?>
631 <script>
632 jQuery(document).ready(function($) {
633 //Initiate Color Picker
634 $('.wp-color-picker-field').wpColorPicker();
635 $(".proelement .wp-picker-container button").attr("disabled", true);
636
637 // Switches option sections
638 $('.group').hide();
639 var activetab = '';
640 if (typeof(localStorage) != 'undefined' ) {
641 activetab = localStorage.getItem("activetab");
642 }
643
644 //if url has section id as hash then set it as active or override the current local storage value
645 if(window.location.hash){
646 activetab = window.location.hash;
647 if (typeof(localStorage) != 'undefined' ) {
648 localStorage.setItem("activetab", activetab);
649 }
650 }
651
652 if (activetab != '' && $(activetab).length ) {
653 $(activetab).fadeIn();
654 } else {
655 $('.group:first').fadeIn();
656 }
657 $('.group .collapsed').each(function(){
658 $(this).find('input:checked').parent().parent().parent().nextAll().each(
659 function(){
660 if ($(this).hasClass('last')) {
661 $(this).removeClass('hidden');
662 return false;
663 }
664 $(this).filter('.hidden').removeClass('hidden');
665 });
666 });
667
668 if (activetab != '' && $(activetab + '-tab').length ) {
669 $(activetab + '-tab').addClass('nav-tab-active');
670 }
671 else {
672 $('.nav-tab-wrapper a:first').addClass('nav-tab-active');
673 }
674 $('.nav-tab-wrapper a').click(function(evt) {
675 $('.nav-tab-wrapper a').removeClass('nav-tab-active');
676 $(this).addClass('nav-tab-active').blur();
677 var clicked_group = $(this).attr('href');
678 if (typeof(localStorage) != 'undefined' ) {
679 localStorage.setItem("activetab", $(this).attr('href'));
680 }
681 $('.group').hide();
682 $(clicked_group).fadeIn();
683 evt.preventDefault();
684 });
685
686 $('.wpsa-browse').on('click', function (event) {
687 event.preventDefault();
688
689 var self = $(this);
690
691 // Create the media frame.
692 var file_frame = wp.media.frames.file_frame = wp.media({
693 title: self.data('uploader_title'),
694 button: {
695 text: self.data('uploader_button_text'),
696 },
697 multiple: false
698 });
699
700 file_frame.on('select', function () {
701 attachment = file_frame.state().get('selection').first().toJSON();
702 self.prev('.wpsa-url').val(attachment.url).change();
703 });
704
705 // Finally, open the modal
706 file_frame.open();
707 });
708
709 // Initiate sortable Field
710 $( ".htoption_shortable" ).sortable();
711
712 });
713 </script>
714 <?php
715 }
716
717 }