box-shadow.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor box shadow control.
  8. *
  9. * A base control for creating box shadows control. Displays input fields for
  10. * horizontal shadow, vertical shadow, shadow blur, shadow spread and shadow
  11. * color.
  12. *
  13. * @since 1.0.0
  14. */
  15. class Control_Box_Shadow extends Control_Base_Multiple {
  16. /**
  17. * Get box shadow control type.
  18. *
  19. * Retrieve the control type, in this case `box_shadow`.
  20. *
  21. * @since 1.0.0
  22. * @access public
  23. *
  24. * @return string Control type.
  25. */
  26. public function get_type() {
  27. return 'box_shadow';
  28. }
  29. /**
  30. * Get box shadow control default value.
  31. *
  32. * Retrieve the default value of the box shadow control. Used to return the
  33. * default values while initializing the box shadow control.
  34. *
  35. * @since 1.0.0
  36. * @access public
  37. *
  38. * @return array Control default value.
  39. */
  40. public function get_default_value() {
  41. return [
  42. 'horizontal' => 0,
  43. 'vertical' => 0,
  44. 'blur' => 10,
  45. 'spread' => 0,
  46. 'color' => 'rgba(0,0,0,0.5)',
  47. ];
  48. }
  49. /**
  50. * Get box shadow control sliders.
  51. *
  52. * Retrieve the sliders of the box shadow control. Sliders are used while
  53. * rendering the control output in the editor.
  54. *
  55. * @since 1.0.0
  56. * @access public
  57. *
  58. * @return array Control sliders.
  59. */
  60. public function get_sliders() {
  61. return [
  62. 'horizontal' => [
  63. 'label' => __( 'Horizontal', 'elementor' ),
  64. 'min' => -100,
  65. 'max' => 100,
  66. ],
  67. 'vertical' => [
  68. 'label' => __( 'Vertical', 'elementor' ),
  69. 'min' => -100,
  70. 'max' => 100,
  71. ],
  72. 'blur' => [
  73. 'label' => __( 'Blur', 'elementor' ),
  74. 'min' => 0,
  75. 'max' => 100,
  76. ],
  77. 'spread' => [
  78. 'label' => __( 'Spread', 'elementor' ),
  79. 'min' => -100,
  80. 'max' => 100,
  81. ],
  82. ];
  83. }
  84. /**
  85. * Render box shadow control output in the editor.
  86. *
  87. * Used to generate the control HTML in the editor using Underscore JS
  88. * template. The variables for the class are available using `data` JS
  89. * object.
  90. *
  91. * @since 1.0.0
  92. * @access public
  93. */
  94. public function content_template() {
  95. ?>
  96. <#
  97. var defaultColorValue = '';
  98. if ( data.default.color ) {
  99. defaultColorValue = ' data-default-color=' + data.default.color; // Quotes added automatically.
  100. }
  101. #>
  102. <div class="elementor-control-field">
  103. <label class="elementor-control-title"><?php echo __( 'Color', 'elementor' ); ?></label>
  104. <div class="elementor-control-input-wrapper">
  105. <input data-setting="color" class="elementor-shadow-color-picker" type="text" placeholder="<?php echo esc_attr( 'Hex/rgba', 'elementor' ); ?>" data-alpha="true"{{{ defaultColorValue }}} />
  106. </div>
  107. </div>
  108. <?php
  109. foreach ( $this->get_sliders() as $slider_name => $slider ) :
  110. $control_uid = $this->get_control_uid( $slider_name );
  111. ?>
  112. <div class="elementor-shadow-slider">
  113. <label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title"><?php echo $slider['label']; ?></label>
  114. <div class="elementor-control-input-wrapper">
  115. <div class="elementor-slider" data-input="<?php echo esc_attr( $slider_name ); ?>"></div>
  116. <div class="elementor-slider-input">
  117. <input id="<?php echo esc_attr( $control_uid ); ?>" type="number" min="<?php echo esc_attr( $slider['min'] ); ?>" max="<?php echo esc_attr( $slider['max'] ); ?>" data-setting="<?php echo esc_attr( $slider_name ); ?>"/>
  118. </div>
  119. </div>
  120. </div>
  121. <?php endforeach; ?>
  122. <?php
  123. }
  124. }