|
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
|
|
|
wp_enqueue_script( 'kirki-slider', trailingslashit( Kirki::$url ) . 'controls/slider/slider.js', array( 'jquery', 'customize-base' ), false, true ); |
|
83
|
|
|
wp_enqueue_style( 'kirki-slider-css', trailingslashit( Kirki::$url ) . 'controls/slider/slider.css', null ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
|
88
|
|
|
* |
|
89
|
|
|
* Class variables for this control class are available in the `data` JS object; |
|
90
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
91
|
|
|
* |
|
92
|
|
|
* @see WP_Customize_Control::print_template() |
|
93
|
|
|
* |
|
94
|
|
|
* @access protected |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function content_template() { |
|
97
|
|
|
?> |
|
98
|
|
|
<label> |
|
99
|
|
|
<# if ( data.label ) { #> |
|
100
|
|
|
<span class="customize-control-title">{{{ data.label }}}</span> |
|
101
|
|
|
<# } #> |
|
102
|
|
|
<# if ( data.description ) { #> |
|
103
|
|
|
<span class="description customize-control-description">{{{ data.description }}}</span> |
|
104
|
|
|
<# } #> |
|
105
|
|
|
<div class="wrapper"> |
|
106
|
|
|
<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 }}" /> |
|
107
|
|
|
<div class="kirki_range_value"> |
|
108
|
|
|
<span class="value">{{ data.value }}</span> |
|
109
|
|
|
<# if ( data.choices['suffix'] ) { #> |
|
110
|
|
|
{{ data.choices['suffix'] }} |
|
111
|
|
|
<# } #> |
|
112
|
|
|
</div> |
|
113
|
|
|
<div class="kirki-slider-reset"> |
|
114
|
|
|
<span class="dashicons dashicons-image-rotate"></span> |
|
115
|
|
|
</div> |
|
116
|
|
|
</div> |
|
117
|
|
|
</label> |
|
118
|
|
|
<?php |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|