base-units.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor control base units.
  8. *
  9. * An abstract class for creating new unit controls in the panel.
  10. *
  11. * @since 1.0.0
  12. * @abstract
  13. */
  14. abstract class Control_Base_Units extends Control_Base_Multiple {
  15. /**
  16. * Get units control default value.
  17. *
  18. * Retrieve the default value of the units control. Used to return the default
  19. * values while initializing the units control.
  20. *
  21. * @since 1.0.0
  22. * @access public
  23. *
  24. * @return array Control default value.
  25. */
  26. public function get_default_value() {
  27. return [
  28. 'unit' => 'px',
  29. ];
  30. }
  31. /**
  32. * Get units control default settings.
  33. *
  34. * Retrieve the default settings of the units control. Used to return the default
  35. * settings while initializing the units control.
  36. *
  37. * @since 1.0.0
  38. * @access protected
  39. *
  40. * @return array Control default settings.
  41. */
  42. protected function get_default_settings() {
  43. return [
  44. 'size_units' => [ 'px' ],
  45. 'range' => [
  46. 'px' => [
  47. 'min' => 0,
  48. 'max' => 100,
  49. 'step' => 1,
  50. ],
  51. 'em' => [
  52. 'min' => 0.1,
  53. 'max' => 10,
  54. 'step' => 0.1,
  55. ],
  56. 'rem' => [
  57. 'min' => 0.1,
  58. 'max' => 10,
  59. 'step' => 0.1,
  60. ],
  61. '%' => [
  62. 'min' => 0,
  63. 'max' => 100,
  64. 'step' => 1,
  65. ],
  66. 'deg' => [
  67. 'min' => 0,
  68. 'max' => 360,
  69. 'step' => 1,
  70. ],
  71. 'vh' => [
  72. 'min' => 0,
  73. 'max' => 100,
  74. 'step' => 1,
  75. ],
  76. ],
  77. ];
  78. }
  79. /**
  80. * Print units control settings.
  81. *
  82. * Used to generate the units control template in the editor.
  83. *
  84. * @since 1.0.0
  85. * @access protected
  86. */
  87. protected function print_units_template() {
  88. ?>
  89. <# if ( data.size_units && data.size_units.length > 1 ) { #>
  90. <div class="elementor-units-choices">
  91. <# _.each( data.size_units, function( unit ) { #>
  92. <input id="elementor-choose-{{ data._cid + data.name + unit }}" type="radio" name="elementor-choose-{{ data.name }}" data-setting="unit" value="{{ unit }}">
  93. <label class="elementor-units-choices-label" for="elementor-choose-{{ data._cid + data.name + unit }}">{{{ unit }}}</label>
  94. <# } ); #>
  95. </div>
  96. <# } #>
  97. <?php
  98. }
  99. }