1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Customizer Control: background. |
4
|
|
|
* |
5
|
|
|
* Creates a new custom control. |
6
|
|
|
* Custom controls contains all background-related options. |
7
|
|
|
* |
8
|
|
|
* @package Kirki |
9
|
|
|
* @subpackage Controls |
10
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
11
|
|
|
* @license http://opensource.org/licenses/https://opensource.org/licenses/MIT |
12
|
|
|
* @since 1.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Adds multiple input fiels that combined make up the background control. |
17
|
|
|
*/ |
18
|
|
|
class Kirki_Control_Background extends WP_Customize_Control { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The control type. |
22
|
|
|
* |
23
|
|
|
* @access public |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
public $type = 'kirki-background'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Used to automatically generate all CSS output. |
30
|
|
|
* |
31
|
|
|
* @access public |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
public $output = array(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Data type |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $option_type = 'theme_mod'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Enqueue control related scripts/styles. |
46
|
|
|
* |
47
|
|
|
* @access public |
48
|
|
|
*/ |
49
|
|
|
public function enqueue() { |
50
|
|
|
|
51
|
|
|
Kirki_Custom_Build::register_dependency( 'jquery' ); |
52
|
|
|
Kirki_Custom_Build::register_dependency( 'wp-color-picker' ); |
53
|
|
|
wp_enqueue_style( 'wp-color-picker-alpha' ); |
54
|
|
|
wp_enqueue_script( 'wp-color-picker-alpha', trailingslashit( Kirki::$url ) . 'assets/vendor/wp-color-picker-alpha/wp-color-picker-alpha.js', array( 'wp-color-picker' ), '1.2', true ); |
55
|
|
|
|
56
|
|
|
if ( ! Kirki_Custom_Build::is_custom_build() ) { |
57
|
|
|
wp_enqueue_script( 'kirki-background', trailingslashit( Kirki::$url ) . 'controls/background/background.js', array( 'jquery', 'wp-color-picker-alpha' ) ); |
58
|
|
|
wp_enqueue_style( 'kirki-background', trailingslashit( Kirki::$url ) . 'controls/background/background.css', null ); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
64
|
|
|
* |
65
|
|
|
* @access public |
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
|
|
|
* Render the control's content. |
88
|
|
|
* |
89
|
|
|
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
90
|
|
|
* |
91
|
|
|
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. |
92
|
|
|
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. |
93
|
|
|
* |
94
|
|
|
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
95
|
|
|
* |
96
|
|
|
* @since 3.4.0 |
97
|
|
|
*/ |
98
|
|
|
protected function render_content() {} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
102
|
|
|
* |
103
|
|
|
* Class variables for this control class are available in the `data` JS object; |
104
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
105
|
|
|
* |
106
|
|
|
* @see WP_Customize_Control::print_template() |
107
|
|
|
* |
108
|
|
|
* @access protected |
109
|
|
|
*/ |
110
|
|
|
protected function content_template() { |
111
|
|
|
?> |
112
|
|
|
<div class="kirki-controls-loading-spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div> |
113
|
|
|
<label> |
114
|
|
|
<span class="customize-control-title"> |
115
|
|
|
{{{ data.label }}} |
116
|
|
|
</span> |
117
|
|
|
<# if ( data.description ) { #> |
118
|
|
|
<span class="description customize-control-description">{{{ data.description }}}</span> |
119
|
|
|
<# } #> |
120
|
|
|
</label> |
121
|
|
|
<div class="background-wrapper"> |
122
|
|
|
|
123
|
|
|
<!-- background-color --> |
124
|
|
|
<div class="background-color"> |
125
|
|
|
<h4><?php esc_attr_e( 'Background Color', 'kirki' ); ?></h4> |
126
|
|
|
<input type="text" data-default-color="{{ data.default['background-color'] }}" data-alpha="true" value="{{ data.value['background-color'] }}" class="kirki-color-control"/> |
127
|
|
|
</div> |
128
|
|
|
|
129
|
|
|
<!-- background-image --> |
130
|
|
|
<div class="background-image"> |
131
|
|
|
<h4><?php esc_attr_e( 'Background Image', 'kirki' ); ?></h4> |
132
|
|
|
<div class="attachment-media-view background-image-upload"> |
133
|
|
|
<# if ( data.value['background-image'] ) { #> |
134
|
|
|
<div class="thumbnail thumbnail-image"> |
135
|
|
|
<img src="{{ data.value['background-image'] }}" alt="" /> |
136
|
|
|
</div> |
137
|
|
|
<# } else { #> |
138
|
|
|
<div class="placeholder"> |
139
|
|
|
<?php esc_attr_e( 'No File Selected', 'kirki' ); ?> |
140
|
|
|
</div> |
141
|
|
|
<# } #> |
142
|
|
|
<div class="actions"> |
143
|
|
|
<button class="button background-image-upload-remove-button<# if ( ! data.value['background-image'] ) { #> hidden <# } #>"> |
144
|
|
|
<?php esc_attr_e( 'Remove', 'kirki' ); ?> |
145
|
|
|
</button> |
146
|
|
|
<button type="button" class="button background-image-upload-button"> |
147
|
|
|
<?php esc_attr_e( 'Select File', 'kirki' ); ?> |
148
|
|
|
</button> |
149
|
|
|
</div> |
150
|
|
|
</div> |
151
|
|
|
</div> |
152
|
|
|
|
153
|
|
|
<!-- background-repeat --> |
154
|
|
|
<div class="background-repeat"> |
155
|
|
|
<h4><?php esc_attr_e( 'Background Repeat', 'kirki' ); ?></h4> |
156
|
|
|
<select {{{ data.inputAttrs }}}> |
157
|
|
|
<option value="no-repeat"<# if ( 'no-repeat' === data.value['background-repeat'] ) { #> selected <# } #>><?php esc_attr_e( 'No Repeat', 'kirki' ); ?></option> |
158
|
|
|
<option value="repeat-all"<# if ( 'repeat-all' === data.value['background-repeat'] ) { #> selected <# } #>><?php esc_attr_e( 'Repeat All', 'kirki' ); ?></option> |
159
|
|
|
<option value="repeat-x"<# if ( 'repeat-x' === data.value['background-repeat'] ) { #> selected <# } #>><?php esc_attr_e( 'Repeat Horizontally', 'kirki' ); ?></option> |
160
|
|
|
<option value="repeat-y"<# if ( 'repeat-y' === data.value['background-repeat'] ) { #> selected <# } #>><?php esc_attr_e( 'Repeat Vertically', 'kirki' ); ?></option> |
161
|
|
|
</select> |
162
|
|
|
</div> |
163
|
|
|
|
164
|
|
|
<!-- background-position --> |
165
|
|
|
<div class="background-position"> |
166
|
|
|
<h4><?php esc_attr_e( 'Background Position', 'kirki' ); ?></h4> |
167
|
|
|
<select {{{ data.inputAttrs }}}> |
168
|
|
|
<option value="left top"<# if ( 'left top' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Left Top', 'kirki' ); ?></option> |
169
|
|
|
<option value="left center"<# if ( 'left center' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Left Center', 'kirki' ); ?></option> |
170
|
|
|
<option value="left bottom"<# if ( 'left bottom' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Left Bottom', 'kirki' ); ?></option> |
171
|
|
|
<option value="right top"<# if ( 'right top' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Right Top', 'kirki' ); ?></option> |
172
|
|
|
<option value="right center"<# if ( 'right center' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Right Center', 'kirki' ); ?></option> |
173
|
|
|
<option value="right bottom"<# if ( 'right bottom' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Right Bottom', 'kirki' ); ?></option> |
174
|
|
|
<option value="center top"<# if ( 'center top' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Center Top', 'kirki' ); ?></option> |
175
|
|
|
<option value="center center"<# if ( 'center center' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Center Center', 'kirki' ); ?></option> |
176
|
|
|
<option value="center bottom"<# if ( 'center bottom' === data.value['background-position'] ) { #> selected <# } #>><?php esc_attr_e( 'Center Bottom', 'kirki' ); ?></option> |
177
|
|
|
</select> |
178
|
|
|
</div> |
179
|
|
|
|
180
|
|
|
<!-- background-size --> |
181
|
|
|
<div class="background-size"> |
182
|
|
|
<h4><?php esc_attr_e( 'Background Size', 'kirki' ); ?></h4> |
183
|
|
|
<div class="buttonset"> |
184
|
|
|
<input {{{ data.inputAttrs }}} class="switch-input screen-reader-text" type="radio" value="cover" name="_customize-bg-{{{ data.id }}}-size" id="{{ data.id }}cover" <# if ( 'cover' === data.value['background-size'] ) { #> checked="checked" <# } #>> |
185
|
|
|
<label class="switch-label switch-label-<# if ( 'cover' === data.value['background-size'] ) { #>on <# } else { #>off<# } #>" for="{{ data.id }}cover"> |
186
|
|
|
<?php esc_attr_e( 'Cover', 'kirki' ); ?> |
187
|
|
|
</label> |
188
|
|
|
</input> |
189
|
|
|
<input {{{ data.inputAttrs }}} class="switch-input screen-reader-text" type="radio" value="contain" name="_customize-bg-{{{ data.id }}}-size" id="{{ data.id }}contain" <# if ( 'contain' === data.value['background-size'] ) { #> checked="checked" <# } #>> |
190
|
|
|
<label class="switch-label switch-label-<# if ( 'contain' === data.value['background-size'] ) { #>on <# } else { #>off<# } #>" for="{{ data.id }}contain"> |
191
|
|
|
<?php esc_attr_e( 'Contain', 'kirki' ); ?> |
192
|
|
|
</label> |
193
|
|
|
</input> |
194
|
|
|
<input {{{ data.inputAttrs }}} class="switch-input screen-reader-text" type="radio" value="auto" name="_customize-bg-{{{ data.id }}}-size" id="{{ data.id }}auto" <# if ( 'auto' === data.value['background-size'] ) { #> checked="checked" <# } #>> |
195
|
|
|
<label class="switch-label switch-label-<# if ( 'auto' === data.value['background-size'] ) { #>on <# } else { #>off<# } #>" for="{{ data.id }}auto"> |
196
|
|
|
<?php esc_attr_e( 'Auto', 'kirki' ); ?> |
197
|
|
|
</label> |
198
|
|
|
</input> |
199
|
|
|
</div> |
200
|
|
|
</div> |
201
|
|
|
|
202
|
|
|
<!-- background-attachment --> |
203
|
|
|
<div class="background-attachment"> |
204
|
|
|
<h4><?php esc_attr_e( 'Background Attachment', 'kirki' ); ?></h4> |
205
|
|
|
<div class="buttonset"> |
206
|
|
|
<input {{{ data.inputAttrs }}} class="switch-input screen-reader-text" type="radio" value="scroll" name="_customize-bg-{{{ data.id }}}-attachment" id="{{ data.id }}scroll" <# if ( 'scroll' === data.value['background-attachment'] ) { #> checked="checked" <# } #>> |
207
|
|
|
<label class="switch-label switch-label-<# if ( 'scroll' === data.value['background-attachment'] ) { #>on <# } else { #>off<# } #>" for="{{ data.id }}scroll"> |
208
|
|
|
<?php esc_attr_e( 'Scroll', 'kirki' ); ?> |
209
|
|
|
</label> |
210
|
|
|
</input> |
211
|
|
|
<input {{{ data.inputAttrs }}} class="switch-input screen-reader-text" type="radio" value="fixed" name="_customize-bg-{{{ data.id }}}-attachment" id="{{ data.id }}fixed" <# if ( 'fixed' === data.value['background-attachment'] ) { #> checked="checked" <# } #>> |
212
|
|
|
<label class="switch-label switch-label-<# if ( 'fixed' === data.value['background-attachment'] ) { #>on <# } else { #>off<# } #>" for="{{ data.id }}fixed"> |
213
|
|
|
<?php esc_attr_e( 'Fixed', 'kirki' ); ?> |
214
|
|
|
</label> |
215
|
|
|
</input> |
216
|
|
|
</div> |
217
|
|
|
</div> |
218
|
|
|
<# valueJSON = JSON.stringify( data.value ).replace( /'/g, ''' ); #> |
219
|
|
|
<input class="background-hidden-value" type="hidden" value='{{{ valueJSON }}}' {{{ data.link }}}> |
220
|
|
|
<?php |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|