Slider.php
102 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The slider control. |
| 4 | * |
| 5 | * Creates a slider control. |
| 6 | * |
| 7 | * @package kirki-framework/control-slider |
| 8 | * @license MIT (https://oss.ninja/mit?organization=Kirki%20Framework) |
| 9 | * @since 1.0 |
| 10 | */ |
| 11 | |
| 12 | namespace Kirki\Control; |
| 13 | |
| 14 | use Kirki\Control\Base; |
| 15 | use Kirki\URL; |
| 16 | |
| 17 | /** |
| 18 | * Slider control. |
| 19 | * |
| 20 | * @since 1.0 |
| 21 | */ |
| 22 | class Slider extends Base { |
| 23 | |
| 24 | /** |
| 25 | * The control type. |
| 26 | * |
| 27 | * @since 1.0 |
| 28 | * @access public |
| 29 | * @var string |
| 30 | */ |
| 31 | public $type = 'kirki-slider'; |
| 32 | |
| 33 | /** |
| 34 | * The control version. |
| 35 | * |
| 36 | * @since 1.0 |
| 37 | * @access public |
| 38 | * @var string |
| 39 | */ |
| 40 | public static $control_ver = '1.0.4'; |
| 41 | |
| 42 | /** |
| 43 | * Enqueue control related styles/scripts. |
| 44 | * |
| 45 | * @since 1.0 |
| 46 | * @access public |
| 47 | */ |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * Refresh the parameters passed to the JavaScript via JSON. |
| 52 | * |
| 53 | * @see WP_Customize_Control::to_json() |
| 54 | * |
| 55 | * @since 1.0 |
| 56 | * @access public |
| 57 | */ |
| 58 | public function to_json() { |
| 59 | |
| 60 | parent::to_json(); |
| 61 | |
| 62 | $this->json['choices'] = wp_parse_args( |
| 63 | $this->json['choices'], |
| 64 | [ |
| 65 | 'min' => 0, |
| 66 | 'max' => 100, |
| 67 | 'step' => 1, |
| 68 | ] |
| 69 | ); |
| 70 | |
| 71 | if ( isset( $this->json['label'] ) ) { |
| 72 | $this->json['label'] = html_entity_decode( $this->json['label'] ); |
| 73 | } |
| 74 | |
| 75 | if ( isset( $this->json['description'] ) ) { |
| 76 | $this->json['description'] = html_entity_decode( $this->json['description'] ); |
| 77 | } |
| 78 | |
| 79 | $this->json['choices']['min'] = (float) $this->json['choices']['min']; |
| 80 | $this->json['choices']['max'] = (float) $this->json['choices']['max']; |
| 81 | $this->json['choices']['step'] = (float) $this->json['choices']['step']; |
| 82 | |
| 83 | $this->json['value'] = $this->json['value'] < $this->json['choices']['min'] ? $this->json['choices']['min'] : $this->json['value']; |
| 84 | $this->json['value'] = $this->json['value'] > $this->json['choices']['max'] ? $this->json['choices']['max'] : $this->json['value']; |
| 85 | $this->json['value'] = (float) $this->json['value']; |
| 86 | |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * An Underscore (JS) template for this control's content (but not its container). |
| 91 | * |
| 92 | * Class variables for this control class are available in the `data` JS object; |
| 93 | * export custom variables by overriding WP_Customize_Control::to_json(). |
| 94 | * |
| 95 | * @see WP_Customize_Control::print_template() |
| 96 | * |
| 97 | * @since 1.0 |
| 98 | */ |
| 99 | protected function content_template() {} |
| 100 | |
| 101 | } |
| 102 |