]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/customize/class-wp-customize-color-control.php
WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-includes / customize / class-wp-customize-color-control.php
1 <?php
2 /**
3  * Customize API: WP_Customize_Color_Control class
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 4.4.0
8  */
9
10 /**
11  * Customize Color Control class.
12  *
13  * @since 3.4.0
14  *
15  * @see WP_Customize_Control
16  */
17 class WP_Customize_Color_Control extends WP_Customize_Control {
18         /**
19          * Type.
20          *
21          * @access public
22          * @var string
23          */
24         public $type = 'color';
25
26         /**
27          * Statuses.
28          *
29          * @access public
30          * @var array
31          */
32         public $statuses;
33
34         /**
35          * Mode.
36          *
37          * @since 4.7.0
38          * @access public
39          * @var string
40          */
41         public $mode = 'full';
42
43         /**
44          * Constructor.
45          *
46          * @since 3.4.0
47          * @uses WP_Customize_Control::__construct()
48          *
49          * @param WP_Customize_Manager $manager Customizer bootstrap instance.
50          * @param string               $id      Control ID.
51          * @param array                $args    Optional. Arguments to override class property defaults.
52          */
53         public function __construct( $manager, $id, $args = array() ) {
54                 $this->statuses = array( '' => __('Default') );
55                 parent::__construct( $manager, $id, $args );
56         }
57
58         /**
59          * Enqueue scripts/styles for the color picker.
60          *
61          * @since 3.4.0
62          */
63         public function enqueue() {
64                 wp_enqueue_script( 'wp-color-picker' );
65                 wp_enqueue_style( 'wp-color-picker' );
66         }
67
68         /**
69          * Refresh the parameters passed to the JavaScript via JSON.
70          *
71          * @since 3.4.0
72          * @uses WP_Customize_Control::to_json()
73          */
74         public function to_json() {
75                 parent::to_json();
76                 $this->json['statuses'] = $this->statuses;
77                 $this->json['defaultValue'] = $this->setting->default;
78                 $this->json['mode'] = $this->mode;
79         }
80
81         /**
82          * Don't render the control content from PHP, as it's rendered via JS on load.
83          *
84          * @since 3.4.0
85          */
86         public function render_content() {}
87
88         /**
89          * Render a JS template for the content of the color picker control.
90          *
91          * @since 4.1.0
92          */
93         public function content_template() {
94                 ?>
95                 <# var defaultValue = '',
96                         isHueSlider = data.mode === 'hue';
97
98                 if ( data.defaultValue && ! isHueSlider ) {
99                         if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
100                                 defaultValue = '#' + data.defaultValue;
101                         } else {
102                                 defaultValue = data.defaultValue;
103                         }
104                         defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
105                 } #>
106                 <label>
107                         <# if ( data.label ) { #>
108                                 <span class="customize-control-title">{{{ data.label }}}</span>
109                         <# } #>
110                         <# if ( data.description ) { #>
111                                 <span class="description customize-control-description">{{{ data.description }}}</span>
112                         <# } #>
113                         <div class="customize-control-content">
114                                 <# if ( isHueSlider ) { #>
115                                         <input class="color-picker-hue" type="text" data-type="hue" />
116                                 <# } else { #>
117                                         <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
118                                 <# } #>
119                         </div>
120                 </label>
121                 <?php
122         }
123 }