Completed
Push — develop ( a7b7e8...718dc0 )
by Aristeides
03:14
created

Kirki_Control_Dimension::l10n()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: dimension
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       2.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * A text control with validation for CSS units.
19
 */
20
class Kirki_Control_Dimension extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-dimension';
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
	 * The kirki_config we're using for this control
48
	 *
49
	 * @access public
50
	 * @var string
51
	 */
52
	public $kirki_config = 'global';
53
54
	/**
55
	 * Enqueue control related scripts/styles.
56
	 *
57
	 * @access public
58
	 */
59
	public function enqueue() {
60
61
		Kirki_Custom_Build::register_dependency( 'jquery' );
62
		Kirki_Custom_Build::register_dependency( 'customize-base' );
63
64
		$script_to_localize = 'kirki-build';
65
		if ( ! Kirki_Custom_Build::is_custom_build() ) {
66
			$script_to_localize = 'kirki-dimension';
67
			wp_enqueue_script( 'kirki-dimension', trailingslashit( Kirki::$url ) . 'controls/dimension/dimension.js', array( 'jquery', 'customize-base' ), false, true );
68
			wp_enqueue_style( 'kirki-dimension-css', trailingslashit( Kirki::$url ) . 'controls/dimension/dimension.css', null );
69
		}
70
		wp_localize_script( $script_to_localize, 'dimensionkirkiL10n', array(
71
			'invalid-value' => esc_attr__( 'Invalid Value', 'kirki' ),
72
		) );
73
	}
74
75
	/**
76
	 * Refresh the parameters passed to the JavaScript via JSON.
77
	 *
78
	 * @see WP_Customize_Control::to_json()
79
	 */
80
	public function to_json() {
81
		parent::to_json();
82
83
		$this->json['default'] = $this->setting->default;
84
		if ( isset( $this->default ) ) {
85
			$this->json['default'] = $this->default;
86
		}
87
		$this->json['output']  = $this->output;
88
		$this->json['value']   = $this->value();
89
		$this->json['choices'] = $this->choices;
90
		$this->json['link']    = $this->get_link();
91
		$this->json['id']      = $this->id;
92
93
		$this->json['inputAttrs'] = '';
94
		foreach ( $this->input_attrs as $attr => $value ) {
95
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
96
		}
97
98
	}
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 class="customizer-text">
114
			<# if ( data.label ) { #>
115
				<span class="customize-control-title">{{{ data.label }}}</span>
116
			<# } #>
117
			<# if ( data.description ) { #>
118
				<span class="description customize-control-description">{{{ data.description }}}</span>
119
			<# } #>
120
			<div class="input-wrapper">
121
				<input {{{ data.inputAttrs }}} type="text" value="{{ data.value }}"/>
122
			</div>
123
		</label>
124
		<?php
125
	}
126
}
127