* @copyright Copyright (c) 2016, Soderlind * @link https://github.com/soderlind/class-customizer-range-value-control/blob/master/README.md * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ if ( ! class_exists( 'WP_Customize_Control' ) ) { return; } /** * Class Customizer_Range_Value_Control * * @since 1.1.31 * @modified 1.1.38 * @access public */ class Business_a_Customizer_Range_Value_Control extends WP_Customize_Control { /** * Control type * * @var string */ public $type = 'range-value'; /** * Flag that enables media queries * * @var bool */ public $media_query = false; /** * Settings for range inputs. * * @var array|mixed */ public $input_attr = array(); /** * Business_a_Customizer_Range_Value_Control constructor. * * @param WP_Customize_Manager $manager Customize manager. * @param string $id Control id. * @param array $args Control arguments. */ public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); if ( ! empty( $args['media_query'] ) ) { $this->media_query = (bool) $args['media_query']; } if ( ! empty( $args['input_attr'] ) ) { $this->input_attr = $args['input_attr']; } } /** * Enqueue scripts/styles. * * @access public */ public function enqueue() { wp_enqueue_script( 'customizer-range-value-control', get_template_directory_uri() . '/functions/customizer/customizer-range-value/js/customizer-range-value-control.js', array( 'jquery', 'customize-base' ) , '1.5.4', true ); wp_enqueue_style( 'customizer-range-value-control', get_template_directory_uri() . '/functions/customizer/customizer-range-value/css/customizer-range-value-control.css',array(), '1.5.4' ); } /** * Handles input value. * * @return array */ public function json() { $json = parent::json(); $json['value'] = $this->value(); $json['default_value'] = ! empty( $this->setting->default ) ? $this->setting->default : 0; $json['desktop_value'] = ! $this->is_json( $json['value'] ) ? $json['value'] : $json['default_value']; $json['tablet_value'] = $json['default_value']; $json['mobile_value'] = $json['default_value']; if ( $this->is_json( $json['value'] ) ) { $decoded_value = json_decode( $json['value'], true ); $json['desktop_value'] = $decoded_value['desktop']; $json['tablet_value'] = $decoded_value['tablet']; $json['mobile_value'] = $decoded_value['mobile']; } else { $json['desktop_value'] = $json['value']; } $json['media_query'] = $this->media_query; $json['link'] = $this->get_link(); $json['vals'] = json_encode( $this->input_attr ); $json['min'] = ! empty( $this->input_attr['min'] ) ? $this->input_attr['min'] : 0; $json['max'] = ! empty( $this->input_attr['max'] ) ? $this->input_attr['max'] : 1; $json['step'] = ! empty( $this->input_attr['step'] ) ? $this->input_attr['step'] : 1; return $json; } /** * Check if a string is in json format * * @param string $string Input. * * @access public * @return bool */ public function is_json( $string ) { return is_string( $string ) && is_array( json_decode( $string, true ) ) ? true : false; } /** * Render the control's content. * * @access public */ protected function content_template() { ?> <# if ( data.label ) { #> {{{ data.label }}} <# if ( data.media_query ) { #>