slider.php (3574B)
1 <?php 2 namespace Elementor; 3 4 use Elementor\Modules\DynamicTags\Module as TagsModule; 5 6 if ( ! defined( 'ABSPATH' ) ) { 7 exit; // Exit if accessed directly. 8 } 9 10 /** 11 * Elementor slider control. 12 * 13 * A base control for creating slider control. Displays a draggable range slider. 14 * The slider control can optionally have a number of unit types (`size_units`) 15 * for the user to choose from. The control also accepts a range argument that 16 * allows you to set the `min`, `max` and `step` values per unit type. 17 * 18 * @since 1.0.0 19 */ 20 class Control_Slider extends Control_Base_Units { 21 22 /** 23 * Get slider control type. 24 * 25 * Retrieve the control type, in this case `slider`. 26 * 27 * @since 1.0.0 28 * @access public 29 * 30 * @return string Control type. 31 */ 32 public function get_type() { 33 return 'slider'; 34 } 35 36 /** 37 * Get slider control default values. 38 * 39 * Retrieve the default value of the slider control. Used to return the default 40 * values while initializing the slider control. 41 * 42 * @since 1.0.0 43 * @access public 44 * 45 * @return array Control default value. 46 */ 47 public function get_default_value() { 48 return array_merge( 49 parent::get_default_value(), [ 50 'size' => '', 51 'sizes' => [], 52 ] 53 ); 54 } 55 56 /** 57 * Get slider control default settings. 58 * 59 * Retrieve the default settings of the slider control. Used to return the 60 * default settings while initializing the slider control. 61 * 62 * @since 1.0.0 63 * @access protected 64 * 65 * @return array Control default settings. 66 */ 67 protected function get_default_settings() { 68 return array_merge( 69 parent::get_default_settings(), [ 70 'label_block' => true, 71 'labels' => [], 72 'scales' => 0, 73 'handles' => 'default', 74 'dynamic' => [ 75 'categories' => [ TagsModule::NUMBER_CATEGORY ], 76 'property' => 'size', 77 ], 78 ] 79 ); 80 } 81 82 /** 83 * Render slider control output in the editor. 84 * 85 * Used to generate the control HTML in the editor using Underscore JS 86 * template. The variables for the class are available using `data` JS 87 * object. 88 * 89 * @since 1.0.0 90 * @access public 91 */ 92 public function content_template() { 93 ?> 94 <div class="elementor-control-field"> 95 <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> 96 <?php $this->print_units_template(); ?> 97 <div class="elementor-control-input-wrapper elementor-control-dynamic-switcher-wrapper elementor-clearfix elementor-control-tag-area"> 98 <# if ( isMultiple && ( data.labels.length || data.scales ) ) { #> 99 <div class="elementor-slider__extra"> 100 <# if ( data.labels.length ) { #> 101 <div class="elementor-slider__labels"> 102 <# jQuery.each( data.labels, ( index, label ) => { #> 103 <div class="elementor-slider__label">{{{ label }}}</div> 104 <# } ); #> 105 </div> 106 <# } if ( data.scales ) { #> 107 <div class="elementor-slider__scales"> 108 <# for ( var i = 0; i < data.scales; i++ ) { #> 109 <div class="elementor-slider__scale"></div> 110 <# } #> 111 </div> 112 <# } #> 113 </div> 114 <# } #> 115 <div class="elementor-slider"></div> 116 <# if ( ! isMultiple ) { #> 117 <div class="elementor-slider-input"> 118 <input id="<?php $this->print_control_uid(); ?>" type="number" min="{{ data.min }}" max="{{ data.max }}" step="{{ data.step }}" placeholder="{{ view.getControlPlaceholder()?.size }}" data-setting="size" /> 119 </div> 120 <# } #> 121 </div> 122 </div> 123 <# if ( data.description ) { #> 124 <div class="elementor-control-field-description">{{{ data.description }}}</div> 125 <# } #> 126 <?php 127 } 128 }