text-shadow.php 3.3 KB

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