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