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
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
// Make sure "select" field is loaded
require_once WCQD_METABOX_FIELDS_DIR . 'select.php';
if ( ! class_exists( 'WCQD_METABOX_Select_Advanced_Field' ) )
{
class WCQD_METABOX_Select_Advanced_Field extends WCQD_METABOX_Select_Field
{
/**
* Enqueue scripts and styles
*
* @return void
*/
static function admin_enqueue_scripts()
{
wp_enqueue_style( 'select2', WCQD_METABOX_CSS_URL . 'select2/select2.css', array(), '3.2' );
wp_enqueue_style( 'rwmb-select-advanced', WCQD_METABOX_CSS_URL . 'select-advanced.css', array(), WCQD_METABOX_VER );
wp_register_script( 'select2', WCQD_METABOX_JS_URL . 'select2/select2.min.js', array(), '3.2', true );
wp_enqueue_script( 'rwmb-select', WCQD_METABOX_JS_URL . 'select.js', array(), WCQD_METABOX_VER, true );
wp_enqueue_script( 'rwmb-select-advanced', WCQD_METABOX_JS_URL . 'select-advanced.js', array( 'select2', 'rwmb-select' ), WCQD_METABOX_VER, true );
}
/**
* Get field HTML
*
* @param mixed $meta
* @param array $field
*
* @return string
*/
static function html( $meta, $field )
{
$html = sprintf(
'<select class="rwmb-select-advanced" name="%s" id="%s" size="%s"%s data-options="%s">',
$field['field_name'],
$field['id'],
$field['size'],
$field['multiple'] ? ' multiple' : '',
esc_attr( wp_json_encode( $field['js_options'] ) )
);
$html .= self::options_html( $field, $meta );
$html .= '</select>';
$html .= self::get_select_all_html( $field['multiple'] );
return $html;
}
/**
* Normalize parameters for field
*
* @param array $field
*
* @return array
*/
static function normalize_field( $field )
{
$field = parent::normalize_field( $field );
$field = wp_parse_args( $field, array(
'js_options' => array(),
) );
$field['js_options'] = wp_parse_args( $field['js_options'], array(
'allowClear' => true,
'width' => 'resolve',
'placeholder' => $field['placeholder'],
) );
return $field;
}
}
}