PluginProbe
Contact Forms by Cimatti / 1.9.2
Contact Forms by Cimatti v1.9.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
← All changes | classes/Element/ColorPicker.php +83 -17 1.3.11.9.2 View file →
@@ -1,17 +1,83 @@
1 -<?php
2 -class AccuaForm_Element_ColorPicker extends Element {
3 - public function __construct($label, $name, array $properties = null) {
4 - parent::__construct($label,$name,$properties);
5 - $this->setValidation(new AccuaForm_Validation_Color());
6 - }
7 -
8 - public function jQueryDocumentReady() {
9 - parent::jQueryDocumentReady();
10 - echo 'jQuery("#', $this->attributes["id"], '").wpColorPicker();';
11 - }
12 -
13 - public function render() {
14 - $this->validation[] = new Validation_Date;
15 - parent::render();
16 - }
17 -}
1 +<?php
2 +class AccuaForm_Element_ColorPicker extends Element {
3 + /**
4 + * Status that changes to 1 if WordPress is ready to load javascripts, and changes to 2 when color picker scripts are loaded
5 + *
6 + * @var int
7 + */
8 + protected static $_cp_loaded_scripts = 0;
9 + /**
10 + * Status that changes to 1 if WordPress is ready to load styles, and changes to 2 when color picker styles are loaded
11 + *
12 + * @var int
13 + */
14 + protected static $_cp_loaded_styles = 0;
15 + /**
16 + * Status that changes to TRUE when a color picker field is rendered, meaning that scripts and styles are needed
17 + *
18 + * @var bool
19 + */
20 + protected static $_cp_required_script_styles = FALSE;
21 +
22 + public function __construct($label, $name, array $properties = null) {
23 + parent::__construct($label,$name,$properties);
24 + $this->setValidation(new AccuaForm_Validation_Color());
25 + }
26 +
27 + public function jQueryDocumentReady() {
28 + parent::jQueryDocumentReady();
29 + echo 'jQuery("#', $this->attributes["id"], '").colorPicker({opacity: false, renderCallback: function($elm, toggled){
30 + if ($elm.val() != "") {
31 + $elm.val("#"+this.color.colors.HEX);
32 + }
33 + }});';
34 + }
35 +
36 + /**
37 + * Loads scripts and styles for color picker only once, if needed, when WordPress is ready
38 + *
39 + * @return void
40 + */
41 + protected static function maybe_load_colorPicker_scripts_styles() {
42 + if (self::$_cp_required_script_styles) { // scripts and styles are needed
43 + if (self::$_cp_loaded_scripts == 1) { // WordPress is ready to load scripts
44 + self::$_cp_loaded_scripts = 2; // Change status to load them just once
45 + wp_enqueue_script('accua-jqColorPicker', plugins_url('/js/jqColorPicker.min.js', ACCUA_FORMS_FILE ), array( 'jquery' ), ACCUA_FORMS_JS_VERSION);
46 + }
47 + if (self::$_cp_loaded_styles == 1) { // WordPress is ready to load styles
48 + self::$_cp_loaded_styles = 2; // Change status to load them just once
49 + // wp_enqueue_style(...) here if needed
50 + }
51 + }
52 + }
53 +
54 + /**
55 + * Function called during action wp_print_scripts to change status of self::$_cp_loaded_scripts and load scripts if needed
56 + *
57 + * @return void
58 + */
59 + public static function maybe_load_colorPicker_scripts(){
60 + if (self::$_cp_loaded_scripts == 0) { // First time
61 + self::$_cp_loaded_scripts = 1; // When we are in this status, WordPress is ready to load scripts
62 + self::maybe_load_colorPicker_scripts_styles(); // Load scripts if they were previously set as needed
63 + }
64 + }
65 +
66 + /**
67 + * Function called during action wp_print_styles to change status of self::$_cp_loaded_styles and load styles if needed
68 + *
69 + * @return void
70 + */
71 + public static function maybe_load_colorPicker_styles(){
72 + if (self::$_cp_loaded_styles == 0) { // First time
73 + self::$_cp_loaded_styles = 1; // When we are in this status, WordPress is ready to load styles
74 + self::maybe_load_colorPicker_scripts_styles(); // Load styles if they were previously set as needed
75 + }
76 + }
77 +
78 + public function render() {
79 + self::$_cp_required_script_styles = TRUE; // Changing status meaning that script and styles are needed
80 + self::maybe_load_colorPicker_scripts_styles(); // Load script and styles once if WordPress is ready
81 + parent::render();
82 + }
83 +}