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

Kirki_Control_Editor::content_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: editor.
4
 *
5
 * Creates a TinyMCE textarea.
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
 * A TinyMCE control.
21
 */
22
class Kirki_Control_Editor extends WP_Customize_Control {
23
24
	/**
25
	 * The control type.
26
	 *
27
	 * @access public
28
	 * @var string
29
	 */
30
	public $type = 'kirki-editor';
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
	 * The kirki_config we're using for this control
50
	 *
51
	 * @access public
52
	 * @var string
53
	 */
54
	public $kirki_config = 'global';
55
56
	/**
57
	 * Enqueue control related scripts/styles.
58
	 *
59
	 * @access public
60
	 */
61
	public function enqueue() {
62
63
		wp_enqueue_script( 'kirki-dynamic-control', trailingslashit( Kirki::$url ) . 'assets/js/dynamic-control.js', array( 'jquery', 'customize-base' ), false, true );
64
		wp_enqueue_script( 'kirki-editor', trailingslashit( Kirki::$url ) . 'controls/editor/editor.js', array( 'jquery', 'customize-base', 'kirki-dynamic-control' ), false, true );
65
		wp_enqueue_style( 'kirki-editor-css', trailingslashit( Kirki::$url ) . 'controls/editor/editor.css', null );
66
		wp_localize_script( 'kirki-editor', 'editorKirkiL10n', array(
67
			'open-editor'   => esc_attr__( 'Open Editor', 'kirki' ),
68
			'close-editor'  => esc_attr__( 'Close Editor', 'kirki' ),
69
			'switch-editor' => esc_attr__( 'Switch Editor', 'kirki' ),
70
		) );
71
	}
72
73
	/**
74
	 * Refresh the parameters passed to the JavaScript via JSON.
75
	 *
76
	 * @see WP_Customize_Control::to_json()
77
	 */
78
	public function to_json() {
79
		parent::to_json();
80
81
		$this->json['default'] = $this->setting->default;
82
		if ( isset( $this->default ) ) {
83
			$this->json['default'] = $this->default;
84
		}
85
		$this->json['output']  = $this->output;
86
		$this->json['value']   = $this->value();
87
		$this->json['choices'] = $this->choices;
88
		$this->json['link']    = $this->get_link();
89
		$this->json['id']      = $this->id;
90
91
		$this->json['inputAttrs'] = '';
92
		foreach ( $this->input_attrs as $attr => $value ) {
93
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
94
		}
95
96
	}
97
98
	/**
99
	 * An Underscore (JS) template for this control's content (but not its container).
100
	 *
101
	 * Class variables for this control class are available in the `data` JS object;
102
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
103
	 *
104
	 * The actual editor is added from the Kirki_Field_Editor class.
105
	 * All this template contains is a button that triggers the global editor on/off
106
	 * and a hidden textarea element that is used to mirror save the options.
107
	 *
108
	 * @see WP_Customize_Control::print_template()
109
	 *
110
	 * @access protected
111
	 */
112
	protected function content_template() {
113
		?>
114
		<label>
115
			<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
116
			<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
117
			<div class="customize-control-content">
118
				<a href="#" class="button button-primary toggle-editor"></a>
119
				<textarea {{{ data.inputAttrs }}} class="hidden" {{{ data.link }}}>{{ data.value }}</textarea>
120
			</div>
121
		</label>
122
		<?php
123
	}
124
}
125