spacer.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor spacer widget.
  8. *
  9. * Elementor widget that inserts a space that divides various elements.
  10. *
  11. * @since 1.0.0
  12. */
  13. class Widget_Spacer extends Widget_Base {
  14. /**
  15. * Get widget name.
  16. *
  17. * Retrieve spacer widget name.
  18. *
  19. * @since 1.0.0
  20. * @access public
  21. *
  22. * @return string Widget name.
  23. */
  24. public function get_name() {
  25. return 'spacer';
  26. }
  27. /**
  28. * Get widget title.
  29. *
  30. * Retrieve spacer widget title.
  31. *
  32. * @since 1.0.0
  33. * @access public
  34. *
  35. * @return string Widget title.
  36. */
  37. public function get_title() {
  38. return __( 'Spacer', 'elementor' );
  39. }
  40. /**
  41. * Get widget icon.
  42. *
  43. * Retrieve spacer widget icon.
  44. *
  45. * @since 1.0.0
  46. * @access public
  47. *
  48. * @return string Widget icon.
  49. */
  50. public function get_icon() {
  51. return 'eicon-spacer';
  52. }
  53. /**
  54. * Get widget categories.
  55. *
  56. * Retrieve the list of categories the spacer widget belongs to.
  57. *
  58. * Used to determine where to display the widget in the editor.
  59. *
  60. * @since 1.0.0
  61. * @access public
  62. *
  63. * @return array Widget categories.
  64. */
  65. public function get_categories() {
  66. return [ 'basic' ];
  67. }
  68. /**
  69. * Get widget keywords.
  70. *
  71. * Retrieve the list of keywords the widget belongs to.
  72. *
  73. * @since 2.1.0
  74. * @access public
  75. *
  76. * @return array Widget keywords.
  77. */
  78. public function get_keywords() {
  79. return [ 'space' ];
  80. }
  81. /**
  82. * Register spacer widget controls.
  83. *
  84. * Adds different input fields to allow the user to change and customize the widget settings.
  85. *
  86. * @since 1.0.0
  87. * @access protected
  88. */
  89. protected function _register_controls() {
  90. $this->start_controls_section(
  91. 'section_spacer',
  92. [
  93. 'label' => __( 'Spacer', 'elementor' ),
  94. ]
  95. );
  96. $this->add_responsive_control(
  97. 'space',
  98. [
  99. 'label' => __( 'Space', 'elementor' ),
  100. 'type' => Controls_Manager::SLIDER,
  101. 'default' => [
  102. 'size' => 50,
  103. ],
  104. 'range' => [
  105. 'px' => [
  106. 'min' => 10,
  107. 'max' => 600,
  108. ],
  109. ],
  110. 'selectors' => [
  111. '{{WRAPPER}} .elementor-spacer-inner' => 'height: {{SIZE}}{{UNIT}};',
  112. ],
  113. ]
  114. );
  115. $this->add_control(
  116. 'view',
  117. [
  118. 'label' => __( 'View', 'elementor' ),
  119. 'type' => Controls_Manager::HIDDEN,
  120. 'default' => 'traditional',
  121. ]
  122. );
  123. $this->end_controls_section();
  124. }
  125. /**
  126. * Render spacer widget output on the frontend.
  127. *
  128. * Written in PHP and used to generate the final HTML.
  129. *
  130. * @since 1.0.0
  131. * @access protected
  132. */
  133. protected function render() {
  134. ?>
  135. <div class="elementor-spacer">
  136. <div class="elementor-spacer-inner"></div>
  137. </div>
  138. <?php
  139. }
  140. /**
  141. * Render spacer widget output in the editor.
  142. *
  143. * Written as a Backbone JavaScript template and used to generate the live preview.
  144. *
  145. * @since 1.0.0
  146. * @access protected
  147. */
  148. protected function _content_template() {
  149. ?>
  150. <div class="elementor-spacer">
  151. <div class="elementor-spacer-inner"></div>
  152. </div>
  153. <?php
  154. }
  155. }