Completed
Push — develop ( 656b88...85b7b9 )
by Aristeides
06:46
created

Kirki_Control_Date   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enqueue() 0 6 1
A to_json() 0 19 3
A content_template() 0 11 1
1
<?php
2
/**
3
 * Customizer Control: kirki-date.
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.2
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * A simple date control, using jQuery UI.
19
 */
20
class Kirki_Control_Date extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-date';
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
	 * Enqueue control related scripts/styles.
48
	 *
49
	 * @access public
50
	 */
51
	public function enqueue() {
52
53
		wp_enqueue_script( 'kirki-dynamic-control', trailingslashit( Kirki::$url ) . 'assets/js/dynamic-control.js', array( 'jquery', 'customize-base' ), false, true );
54
		wp_enqueue_script( 'kirki-date', trailingslashit( Kirki::$url ) . 'controls/date/date.js', array( 'jquery', 'customize-base', 'kirki-dynamic-control', 'jquery-ui-datepicker' ), false, true );
55
		wp_enqueue_style( 'kirki-date-css', trailingslashit( Kirki::$url ) . 'controls/date/date.css', null );
56
	}
57
58
	/**
59
	 * Refresh the parameters passed to the JavaScript via JSON.
60
	 *
61
	 * @see WP_Customize_Control::to_json()
62
	 */
63
	public function to_json() {
64
		parent::to_json();
65
66
		$this->json['default'] = $this->setting->default;
67
		if ( isset( $this->default ) ) {
68
			$this->json['default'] = $this->default;
69
		}
70
		$this->json['output']  = $this->output;
71
		$this->json['value']   = $this->value();
72
		$this->json['choices'] = $this->choices;
73
		$this->json['link']    = $this->get_link();
74
		$this->json['id']      = $this->id;
75
76
		$this->json['inputAttrs'] = '';
77
		foreach ( $this->input_attrs as $attr => $value ) {
78
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
79
		}
80
81
	}
82
83
	/**
84
	 * An Underscore (JS) template for this control's content (but not its container).
85
	 *
86
	 * Class variables for this control class are available in the `data` JS object;
87
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
88
	 *
89
	 * @see WP_Customize_Control::print_template()
90
	 *
91
	 * @access protected
92
	 */
93
	protected function content_template() {
94
		?>
95
		<label>
96
			<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
97
			<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
98
			<div class="customize-control-content">
99
				<input {{{ data.inputAttrs }}} class="datepicker" type="text" id="{{ data.id }}" value="{{ data.value }}" {{{ data.link }}} />
100
			</div>
101
		</label>
102
		<?php
103
	}
104
}
105