1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Customizer Control: kirki-fontawesome. |
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
|
|
|
* Select control. |
19
|
|
|
*/ |
20
|
|
|
class Kirki_Control_FontAwesome extends WP_Customize_Control { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The control type. |
24
|
|
|
* |
25
|
|
|
* @access public |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $type = 'kirki-fontawesome'; |
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-fontawesome', trailingslashit( Kirki::$url ) . 'controls/fontawesome/fontawesome.js', array( 'jquery', 'customize-base', 'select2', 'jquery-ui-sortable' ), false, true ); |
54
|
|
|
wp_enqueue_style( 'kirki-fontawesome-css', trailingslashit( Kirki::$url ) . 'controls/fontawesome/fontawesome.css', null ); |
55
|
|
|
wp_enqueue_style( 'kirki-fontawesome-font-css', trailingslashit( Kirki::$url ) . 'controls/fontawesome/font-awesome.css', null ); |
56
|
|
|
wp_enqueue_script( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/js/select2.full.js', array( 'jquery' ), '4.0.3', true ); |
57
|
|
|
wp_enqueue_style( 'select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/css/select2.css', array(), '4.0.3' ); |
58
|
|
|
wp_enqueue_style( 'kirki-select2', trailingslashit( Kirki::$url ) . 'assets/vendor/select2/kirki.css', null ); |
59
|
|
|
ob_start(); |
60
|
|
|
$json_path = wp_normalize_path( dirname( __FILE__ ) . '/fontawesome.json' ); |
61
|
|
|
include( $json_path ); |
62
|
|
|
$font_awesome_json = ob_get_clean(); |
63
|
|
|
wp_localize_script( 'kirki-fontawesome', 'fontAwesomeJSON', $font_awesome_json ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
68
|
|
|
* |
69
|
|
|
* @see WP_Customize_Control::to_json() |
70
|
|
|
*/ |
71
|
|
|
public function to_json() { |
72
|
|
|
parent::to_json(); |
73
|
|
|
|
74
|
|
|
$this->json['default'] = $this->setting->default; |
75
|
|
|
if ( isset( $this->default ) ) { |
76
|
|
|
$this->json['default'] = $this->default; |
77
|
|
|
} |
78
|
|
|
$this->json['output'] = $this->output; |
79
|
|
|
$this->json['value'] = $this->value(); |
80
|
|
|
$this->json['choices'] = $this->choices; |
81
|
|
|
$this->json['link'] = $this->get_link(); |
82
|
|
|
$this->json['id'] = $this->id; |
83
|
|
|
|
84
|
|
|
$this->json['inputAttrs'] = ''; |
85
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
86
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
93
|
|
|
* |
94
|
|
|
* Class variables for this control class are available in the `data` JS object; |
95
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
96
|
|
|
* |
97
|
|
|
* @see WP_Customize_Control::print_template() |
98
|
|
|
* |
99
|
|
|
* @access protected |
100
|
|
|
*/ |
101
|
|
|
protected function content_template() { |
102
|
|
|
?> |
103
|
|
|
<div class="kirki-controls-loading-spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div> |
104
|
|
|
<label> |
105
|
|
|
<# if ( data.label ) { #><span class="customize-control-title">{{ data.label }}</span><# } #> |
106
|
|
|
<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #> |
107
|
|
|
<select {{{ data.inputAttrs }}} {{{ data.link }}}></select> |
108
|
|
|
</label> |
109
|
|
|
<?php |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Render the control's content. |
114
|
|
|
* |
115
|
|
|
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
116
|
|
|
* |
117
|
|
|
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. |
118
|
|
|
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. |
119
|
|
|
* |
120
|
|
|
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
121
|
|
|
* |
122
|
|
|
* @since 3.0.0 |
123
|
|
|
*/ |
124
|
|
|
protected function render_content() {} |
125
|
|
|
} |
126
|
|
|
|