* * @version 1.0.0 * @package HFG */ namespace HFG\Core\Customizer; use HFG\Core\Settings\Config; use WP_Customize_Control; /** * Class SpacingControl * * @package HFG\Core\Customizer */ class SpacingControl extends WP_Customize_Control { /** * The control type. * * @access public * @var string */ public $type = 'hfg-responsive-spacing'; /** * The control type. * * @access public * @var string */ public $linked_choices = ''; /** * The unit type. * * @access public * @var array */ public $unit_choices = array( 'px' => 'px' ); /** * Enqueue control related scripts/styles. * * @access public */ public function enqueue() { $base = Config::get_url() . '/Core/Customizer/'; wp_enqueue_script( 'hfg-responsive-spacing', $base . 'responsive-spacing.js', array( 'jquery', 'customize-base' ), NEVE_VERSION, true ); wp_enqueue_style( 'hfg-responsive-spacing', $base . 'responsive-spacing.css', null, NEVE_VERSION ); } /** * Refresh the parameters passed to the JavaScript via JSON. * * @see WP_Customize_Control::to_json() */ public function json() { $json = parent::json(); $json['default'] = $this->setting->default; if ( isset( $this->default ) ) { $json['default'] = $this->default; } $val = maybe_unserialize( $this->value() ); if ( ! is_array( $val ) || is_numeric( $val ) ) { $val = array( 'desktop' => array( 'top' => $val, 'right' => '', 'bottom' => $val, 'left' => '', ), 'tablet' => array( 'top' => $val, 'right' => '', 'bottom' => $val, 'left' => '', ), 'mobile' => array( 'top' => $val, 'right' => '', 'bottom' => $val, 'left' => '', ), 'desktop-unit' => 'px', 'tablet-unit' => 'px', 'mobile-unit' => 'px', ); } /* Control Units */ $units = array( 'desktop-unit' => 'px', 'tablet-unit' => 'px', 'mobile-unit' => 'px', ); foreach ( $units as $unit_key => $unit_value ) { if ( ! isset( $val[ $unit_key ] ) ) { $val[ $unit_key ] = $unit_value; } } $json['value'] = $val; $json['choices'] = $this->choices; $json['link'] = $this->get_link(); $json['id'] = $this->id; $json['label'] = esc_html( $this->label ); $json['linked_choices'] = $this->linked_choices; $json['unit_choices'] = $this->unit_choices; $json['inputAttrs'] = ''; foreach ( $this->input_attrs as $attr => $value ) { $json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; } $json['inputAttrs'] = maybe_serialize( $this->input_attrs() ); return $json; } /** * An Underscore (JS) template for this control's content (but not its container). * * Class variables for this control class are available in the `data` JS object; * export custom variables by overriding {@see WP_Customize_Control::to_json()}. * * @see WP_Customize_Control::print_template() * * @access protected */ protected function content_template() { ?>