-
Notifications
You must be signed in to change notification settings - Fork 58
/
ui-colorpicker.php
executable file
·98 lines (85 loc) · 2.53 KB
/
ui-colorpicker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Class for the building ui-colorpicker elements.
*
* @package Cherry_Framework
* @subpackage Class
* @author Cherry Team <support@cherryframework.com>
* @copyright Copyright (c) 2012 - 2015, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'UI_Colorpicker' ) ) {
/**
* Class for the building UI_Colorpicker elements.
*/
class UI_Colorpicker extends UI_Element implements I_UI {
/**
* Default settings
*
* @var array
*/
private $defaults_settings = array(
'id' => 'cherry-ui-colorpicker-id',
'name' => 'cherry-ui-colorpicker-name',
'value' => '',
'label' => '',
'class' => '',
'master' => '',
);
/**
* Constructor method for the UI_Colorpicker class.
*
* @since 4.0.0
*/
function __construct( $args = array() ) {
$this->defaults_settings['id'] = 'cherry-ui-colorpicker-' . uniqid();
$this->settings = wp_parse_args( $args, $this->defaults_settings );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
}
/**
* Render html UI_Colorpicker.
*
* @since 4.0.0
*/
public function render() {
$html = '';
$class = $this->settings['class'];
$class .= ' ' . $this->settings['master'];
$html .= '<div class="cherry-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cherry-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<div class="cherry-ui-colorpicker-wrapper">';
$html .= '<input type="text" id="' . esc_attr( $this->settings['id'] ) . '" class="cherry-ui-colorpicker" name="' . esc_attr( $this->settings['name'] ) . '" value="' . esc_html( $this->settings['value'] ) . '"/>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
/**
* Enqueue javascript and stylesheet UI_Colorpicker
*
* @since 4.0.0
*/
public static function enqueue_assets() {
wp_enqueue_script(
'ui-colorpicker-min',
esc_url( Cherry_Core::base_url( 'assets/min/ui-colorpicker.min.js', __FILE__ ) ),
array( 'jquery', 'wp-color-picker' ),
'1.0.0',
true
);
wp_enqueue_style(
'ui-colorpicker-min',
esc_url( Cherry_Core::base_url( 'assets/min/ui-colorpicker.min.css', __FILE__ ) ),
array( 'wp-color-picker' ),
'1.0.0',
'all'
);
}
}
}