a5dc5bd64604396344857238999f3184dc89199e.svn-base 1.8 KB
Newer Older
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
<?php if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access pages directly.
/**
 *
 * Field: Color
 *
 */
if ( ! class_exists( 'Exopite_Simple_Options_Framework_Field_color_wp' ) ) {

	class Exopite_Simple_Options_Framework_Field_color_wp extends Exopite_Simple_Options_Framework_Fields {

		public function __construct( $field, $value = '', $unique = '', $config = array(), $multilang ) {

			parent::__construct( $field, $value, $unique, $config, $multilang );
		}

		public function output() {

			$classes = ( isset( $this->field['class'] ) ) ? implode( ' ', explode( ' ', $this->field['class'] ) ) : '';

			/*
			 * Color Picker
			 *
			 * @link https://paulund.co.uk/adding-a-new-color-picker-with-wordpress-3-5
			 */

			echo $this->element_before();
			echo '<input type="text" class="colorpicker ' . $classes . '" ';
			if ( isset( $this->field['rgba'] ) && $this->field['rgba'] ) {
				echo 'data-alpha="true" ';
			}
			echo 'name="' . $this->element_name() . '" value="' . $this->element_value() . '"';
			echo $this->element_attributes() . '/>';

		}

		public static function enqueue( $args ) {

			// Add the color picker css file from WordPress
			wp_enqueue_style( 'wp-color-picker' );

			$resources = array(
				array(
					'name'       => 'wp-color-picker-alpha',
					'fn'         => 'wp-color-picker-alpha.min.js',
					'type'       => 'script',
					'dependency' => array( 'wp-color-picker' ),
					'version'    => '2.1.3',
					'attr'       => true,
				),
				array(
					'name'       => 'exopite-sof-wp-color-picker-loader',
					'fn'         => 'loader-color-picker.min.js',
					'type'       => 'script',
					'dependency' => array( 'wp-color-picker-alpha' ),
					'version'    => '20190407',
					'attr'       => true,
				),
			);

			parent::do_enqueue( $resources, $args );

		}

	}

}