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

Kirki_Control_Number::l10n()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: number.
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
 * Create a simple number control
19
 */
20
class Kirki_Control_Number extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-number';
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
		Kirki_Custom_Build::register_dependency( 'jquery-ui-spinner' );
64
		Kirki_Custom_Build::register_dependency( 'jquery-ui-button' );
65
66
		$script_to_localize = 'kirki-build';
67
		if ( ! Kirki_Custom_Build::is_custom_build() ) {
68
			$script_to_localize = 'kirki-number';
69
			wp_enqueue_script( 'kirki-number', trailingslashit( Kirki::$url ) . 'controls/number/number.js', array( 'jquery', 'customize-base', 'jquery-ui-button', 'jquery-ui-spinner' ), false, true );
70
			wp_enqueue_style( 'kirki-number-css', trailingslashit( Kirki::$url ) . 'controls/number/number.css', null );
71
		}
72
		wp_localize_script( $script_to_localize, 'numberKirkiL10n', array(
73
			'min-error'  => esc_attr__( 'Value lower than allowed minimum', 'kirki' ),
74
			'max-error'  => esc_attr__( 'Value higher than allowed maximum', 'kirki' ),
75
			'step-error' => esc_attr__( 'Invalid Value', 'kirki' ),
76
		) );
77
	}
78
79
	/**
80
	 * Refresh the parameters passed to the JavaScript via JSON.
81
	 *
82
	 * @see WP_Customize_Control::to_json()
83
	 */
84
	public function to_json() {
85
		parent::to_json();
86
87
		$this->json['default'] = $this->setting->default;
88
		if ( isset( $this->default ) ) {
89
			$this->json['default'] = $this->default;
90
		}
91
		$this->json['output']  = $this->output;
92
		$this->json['value']   = $this->value();
93
		$this->json['choices'] = $this->choices;
94
		$this->json['link']    = $this->get_link();
95
		$this->json['id']      = $this->id;
96
97
		$this->json['inputAttrs'] = '';
98
		foreach ( $this->input_attrs as $attr => $value ) {
99
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
100
		}
101
102
	}
103
104
	/**
105
	 * An Underscore (JS) template for this control's content (but not its container).
106
	 *
107
	 * Class variables for this control class are available in the `data` JS object;
108
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
109
	 *
110
	 * @see WP_Customize_Control::print_template()
111
	 *
112
	 * @access protected
113
	 */
114
	protected function content_template() {
115
		?>
116
		<div class="kirki-controls-loading-spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>
117
		<label>
118
			<# if ( data.label ) { #>
119
				<span class="customize-control-title">{{{ data.label }}}</span>
120
			<# } #>
121
			<# if ( data.description ) { #>
122
				<span class="description customize-control-description">{{{ data.description }}}</span>
123
			<# } #>
124
			<div class="customize-control-content">
125
				<input {{{ data.inputAttrs }}} type="text" {{{ data.link }}} value="{{ data.value }}" />
126
			</div>
127
		</label>
128
		<?php
129
	}
130
}
131