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

Kirki_Control_Editor::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: 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
		Kirki_Custom_Build::register_dependency( 'jquery' );
64
		Kirki_Custom_Build::register_dependency( 'customize-base' );
65
66
		$script_to_localize = 'kirki-build';
67
		if ( ! Kirki_Custom_Build::is_custom_build() ) {
68
			$script_to_localize = 'kirki-editor';
69
			wp_enqueue_script( 'kirki-editor', trailingslashit( Kirki::$url ) . 'controls/editor/editor.js', array( 'jquery', 'customize-base' ), false, true );
70
			wp_enqueue_style( 'kirki-editor-css', trailingslashit( Kirki::$url ) . 'controls/editor/editor.css', null );
71
		}
72
		wp_localize_script( $script_to_localize, 'editorKirkiL10n', array(
73
			'open-editor'   => esc_attr__( 'Open Editor', 'kirki' ),
74
			'close-editor'  => esc_attr__( 'Close Editor', 'kirki' ),
75
			'switch-editor' => esc_attr__( 'Switch Editor', '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
	 * The actual editor is added from the Kirki_Field_Editor class.
111
	 * All this template contains is a button that triggers the global editor on/off
112
	 * and a hidden textarea element that is used to mirror save the options.
113
	 *
114
	 * @see WP_Customize_Control::print_template()
115
	 *
116
	 * @access protected
117
	 */
118
	protected function content_template() {
119
		?>
120
		<div class="kirki-controls-loading-spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>
121
		<label>
122
			<# if ( data.label ) { #>
123
				<span class="customize-control-title">{{{ data.label }}}</span>
124
			<# } #>
125
			<# if ( data.description ) { #>
126
				<span class="description customize-control-description">{{{ data.description }}}</span>
127
			<# } #>
128
			<div class="customize-control-content">
129
				<a href="#" class="button button-primary toggle-editor"></a>
130
				<textarea {{{ data.inputAttrs }}} class="hidden" {{{ data.link }}}>{{ data.value }}</textarea>
131
			</div>
132
		</label>
133
		<?php
134
	}
135
}
136