ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-kirki-controls-spacing-control.php (2686B)


      1 <?php
      2 /**
      3  * Customizer Control: spacing.
      4  *
      5  * @package     Kirki
      6  * @subpackage  Controls
      7  * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
      8  * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
      9  * @since       2.1
     10  */
     11 
     12 // Exit if accessed directly.
     13 if ( ! defined( 'ABSPATH' ) ) {
     14 	exit;
     15 }
     16 
     17 if ( ! class_exists( 'Kirki_Controls_Spacing_Control' ) ) {
     18 
     19 	/**
     20 	 * Spacing control.
     21 	 * multiple checkboxes with CSS units validation.
     22 	 */
     23 	class Kirki_Controls_Spacing_Control extends Kirki_Customize_Control {
     24 
     25 		/**
     26 		 * The control type.
     27 		 *
     28 		 * @access public
     29 		 * @var string
     30 		 */
     31 		public $type = 'kirki-spacing';
     32 
     33 		/**
     34 		 * Refresh the parameters passed to the JavaScript via JSON.
     35 		 *
     36 		 * @access public
     37 		 */
     38 		public function to_json() {
     39 			parent::to_json();
     40 			if ( is_array( $this->choices ) ) {
     41 				foreach ( $this->choices as $choice => $value ) {
     42 					if ( true === $value ) {
     43 						$this->json['choices'][ $choice ] = true;
     44 					}
     45 				}
     46 			}
     47 
     48 			if ( is_array( $this->json['default'] ) ) {
     49 				foreach ( $this->json['default'] as $key => $value ) {
     50 					if ( isset( $this->json['choices'][ $key ] ) && ! isset( $this->json['value'][ $key ] ) ) {
     51 						$this->json['value'][ $key ] = $value;
     52 					}
     53 				}
     54 			}
     55 		}
     56 
     57 		/**
     58 		 * Enqueue control related scripts/styles.
     59 		 *
     60 		 * @access public
     61 		 */
     62 		public function enqueue() {
     63 			wp_enqueue_script( 'kirki-spacing' );
     64 		}
     65 
     66 		/**
     67 		 * An Underscore (JS) template for this control's content (but not its container).
     68 		 *
     69 		 * Class variables for this control class are available in the `data` JS object;
     70 		 * export custom variables by overriding {@see Kirki_Customize_Control::to_json()}.
     71 		 *
     72 		 * @see WP_Customize_Control::print_template()
     73 		 *
     74 		 * @access protected
     75 		 */
     76 		protected function content_template() {
     77 			?>
     78 			<# if ( data.tooltip ) { #>
     79 				<a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span class='dashicons dashicons-info'></span></a>
     80 			<# } #>
     81 			<label>
     82 				<# if ( data.label ) { #>
     83 					<span class="customize-control-title">{{{ data.label }}}</span>
     84 				<# } #>
     85 				<# if ( data.description ) { #>
     86 					<span class="description customize-control-description">{{{ data.description }}}</span>
     87 				<# } #>
     88 				<div class="wrapper">
     89 					<div class="control">
     90 						<# for ( choiceKey in data.default ) { #>
     91 							<div class="{{ choiceKey }}">
     92 								<h5>{{ data.l10n[ choiceKey ] }}</h5>
     93 								<div class="{{ choiceKey }} input-wrapper">
     94 									<input {{{ data.inputAttrs }}} type="text" value="{{ data.value[ choiceKey ] }}"/>
     95 								</div>
     96 							</div>
     97 						<# } #>
     98 					</div>
     99 				</div>
    100 			</label>
    101 			<?php
    102 		}
    103 	}
    104 }