|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Customizer Control: kirki-radio. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Kirki |
|
6
|
|
|
* @subpackage Controls |
|
7
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
|
8
|
|
|
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT |
|
9
|
|
|
* @since 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Radio control |
|
19
|
|
|
*/ |
|
20
|
|
|
class Kirki_Control_Radio extends WP_Customize_Control { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The control type. |
|
24
|
|
|
* |
|
25
|
|
|
* @access public |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $type = 'kirki-radio'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Used to automatically generate all CSS output. |
|
32
|
|
|
* |
|
33
|
|
|
* @access public |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
public $output = array(); |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Data type |
|
40
|
|
|
* |
|
41
|
|
|
* @access public |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
public $option_type = 'theme_mod'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Enqueue control related scripts/styles. |
|
48
|
|
|
* |
|
49
|
|
|
* @access public |
|
50
|
|
|
*/ |
|
51
|
|
|
public function enqueue() { |
|
52
|
|
|
|
|
53
|
|
|
Kirki_Custom_Build::register_dependency( 'jquery' ); |
|
54
|
|
|
Kirki_Custom_Build::register_dependency( 'customize-base' ); |
|
55
|
|
|
|
|
56
|
|
|
if ( ! Kirki_Custom_Build::is_custom_build() ) { |
|
57
|
|
|
wp_enqueue_script( 'kirki-radio', trailingslashit( Kirki::$url ) . 'controls/radio/radio.js', array( 'jquery', 'customize-base' ), false, true ); |
|
58
|
|
|
wp_enqueue_style( 'kirki-radio-css', trailingslashit( Kirki::$url ) . 'controls/radio/radio.css', null ); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
|
64
|
|
|
* |
|
65
|
|
|
* @see WP_Customize_Control::to_json() |
|
66
|
|
|
*/ |
|
67
|
|
|
public function to_json() { |
|
68
|
|
|
parent::to_json(); |
|
69
|
|
|
|
|
70
|
|
|
$this->json['default'] = $this->setting->default; |
|
71
|
|
|
if ( isset( $this->default ) ) { |
|
72
|
|
|
$this->json['default'] = $this->default; |
|
73
|
|
|
} |
|
74
|
|
|
$this->json['output'] = $this->output; |
|
75
|
|
|
$this->json['value'] = $this->value(); |
|
76
|
|
|
$this->json['choices'] = $this->choices; |
|
77
|
|
|
$this->json['link'] = $this->get_link(); |
|
78
|
|
|
$this->json['id'] = $this->id; |
|
79
|
|
|
|
|
80
|
|
|
$this->json['inputAttrs'] = ''; |
|
81
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
|
82
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
|
89
|
|
|
* |
|
90
|
|
|
* Class variables for this control class are available in the `data` JS object; |
|
91
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
92
|
|
|
* |
|
93
|
|
|
* @see WP_Customize_Control::print_template() |
|
94
|
|
|
* |
|
95
|
|
|
* @access protected |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function content_template() { |
|
98
|
|
|
?> |
|
99
|
|
|
<div class="kirki-controls-loading-spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div> |
|
100
|
|
|
<# if ( ! data.choices ) { return; } #> |
|
101
|
|
|
|
|
102
|
|
|
<# if ( data.label ) { #> |
|
103
|
|
|
<span class="customize-control-title">{{ data.label }}</span> |
|
104
|
|
|
<# } #> |
|
105
|
|
|
<# if ( data.description ) { #> |
|
106
|
|
|
<span class="description customize-control-description">{{{ data.description }}}</span> |
|
107
|
|
|
<# } #> |
|
108
|
|
|
<# for ( key in data.choices ) { #> |
|
109
|
|
|
<label> |
|
110
|
|
|
<input {{{ data.inputAttrs }}} type="radio" value="{{ key }}" name="_customize-radio-{{ data.id }}" {{{ data.link }}}<# if ( data.value === key ) { #> checked<# } #> /> |
|
111
|
|
|
<# if ( _.isArray( data.choices[ key ] ) ) { #> |
|
112
|
|
|
{{ data.choices[ key ][0] }} |
|
113
|
|
|
<span class="option-description">{{ data.choices[ key ][1] }}</span> |
|
114
|
|
|
<# } else { #> |
|
115
|
|
|
{{ data.choices[ key ] }} |
|
116
|
|
|
<# } #> |
|
117
|
|
|
</label> |
|
118
|
|
|
<# } #> |
|
119
|
|
|
<?php |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|