slider.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor slider control.
  8. *
  9. * A base control for creating slider control. Displays a draggable range slider.
  10. * The slider control can optionally have a number of unit types (`size_units`)
  11. * for the user to choose from. The control also accepts a range argument that
  12. * allows you to set the `min`, `max` and `step` values per unit type.
  13. *
  14. * @since 1.0.0
  15. */
  16. class Control_Slider extends Control_Base_Units {
  17. /**
  18. * Get slider control type.
  19. *
  20. * Retrieve the control type, in this case `slider`.
  21. *
  22. * @since 1.0.0
  23. * @access public
  24. *
  25. * @return string Control type.
  26. */
  27. public function get_type() {
  28. return 'slider';
  29. }
  30. /**
  31. * Get slider control default values.
  32. *
  33. * Retrieve the default value of the slider control. Used to return the default
  34. * values while initializing the slider control.
  35. *
  36. * @since 1.0.0
  37. * @access public
  38. *
  39. * @return array Control default value.
  40. */
  41. public function get_default_value() {
  42. return array_merge(
  43. parent::get_default_value(), [
  44. 'size' => '',
  45. ]
  46. );
  47. }
  48. /**
  49. * Get slider control default settings.
  50. *
  51. * Retrieve the default settings of the slider control. Used to return the
  52. * default settings while initializing the slider control.
  53. *
  54. * @since 1.0.0
  55. * @access protected
  56. *
  57. * @return array Control default settings.
  58. */
  59. protected function get_default_settings() {
  60. return array_merge(
  61. parent::get_default_settings(), [
  62. 'label_block' => true,
  63. ]
  64. );
  65. }
  66. /**
  67. * Render slider control output in the editor.
  68. *
  69. * Used to generate the control HTML in the editor using Underscore JS
  70. * template. The variables for the class are available using `data` JS
  71. * object.
  72. *
  73. * @since 1.0.0
  74. * @access public
  75. */
  76. public function content_template() {
  77. $control_uid = $this->get_control_uid();
  78. ?>
  79. <div class="elementor-control-field">
  80. <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
  81. <?php $this->print_units_template(); ?>
  82. <div class="elementor-control-input-wrapper elementor-clearfix">
  83. <div class="elementor-slider"></div>
  84. <div class="elementor-slider-input">
  85. <input id="<?php echo $control_uid; ?>" type="number" min="{{ data.min }}" max="{{ data.max }}" step="{{ data.step }}" data-setting="size" />
  86. </div>
  87. </div>
  88. </div>
  89. <# if ( data.description ) { #>
  90. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  91. <# } #>
  92. <?php
  93. }
  94. }