ru-se.com

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

class-kirki-controls-slider-control.php (2708B)


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