hover-animation.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Elementor;
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. exit; // Exit if accessed directly.
  5. }
  6. /**
  7. * Elementor hover animation control.
  8. *
  9. * A base control for creating hover animation control. Displays a select box
  10. * with the available hover animation effects @see Control_Hover_Animation::get_animations()
  11. *
  12. * @since 1.0.0
  13. */
  14. class Control_Hover_Animation extends Base_Data_Control {
  15. /**
  16. * Animations.
  17. *
  18. * Holds all the available hover animation effects of the control.
  19. *
  20. * @access private
  21. * @static
  22. *
  23. * @var array
  24. */
  25. private static $_animations;
  26. /**
  27. * Get hover animation control type.
  28. *
  29. * Retrieve the control type, in this case `hover_animation`.
  30. *
  31. * @since 1.0.0
  32. * @access public
  33. *
  34. * @return string Control type.
  35. */
  36. public function get_type() {
  37. return 'hover_animation';
  38. }
  39. /**
  40. * Get animations.
  41. *
  42. * Retrieve the available hover animation effects.
  43. *
  44. * @since 1.0.0
  45. * @access public
  46. * @static
  47. *
  48. * @return array Available hover animation.
  49. */
  50. public static function get_animations() {
  51. if ( is_null( self::$_animations ) ) {
  52. self::$_animations = [
  53. 'grow' => 'Grow',
  54. 'shrink' => 'Shrink',
  55. 'pulse' => 'Pulse',
  56. 'pulse-grow' => 'Pulse Grow',
  57. 'pulse-shrink' => 'Pulse Shrink',
  58. 'push' => 'Push',
  59. 'pop' => 'Pop',
  60. 'bounce-in' => 'Bounce In',
  61. 'bounce-out' => 'Bounce Out',
  62. 'rotate' => 'Rotate',
  63. 'grow-rotate' => 'Grow Rotate',
  64. 'float' => 'Float',
  65. 'sink' => 'Sink',
  66. 'bob' => 'Bob',
  67. 'hang' => 'Hang',
  68. 'skew' => 'Skew',
  69. 'skew-forward' => 'Skew Forward',
  70. 'skew-backward' => 'Skew Backward',
  71. 'wobble-vertical' => 'Wobble Vertical',
  72. 'wobble-horizontal' => 'Wobble Horizontal',
  73. 'wobble-to-bottom-right' => 'Wobble To Bottom Right',
  74. 'wobble-to-top-right' => 'Wobble To Top Right',
  75. 'wobble-top' => 'Wobble Top',
  76. 'wobble-bottom' => 'Wobble Bottom',
  77. 'wobble-skew' => 'Wobble Skew',
  78. 'buzz' => 'Buzz',
  79. 'buzz-out' => 'Buzz Out',
  80. ];
  81. }
  82. return self::$_animations;
  83. }
  84. /**
  85. * Render hover animation 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. $control_uid = $this->get_control_uid();
  96. ?>
  97. <div class="elementor-control-field">
  98. <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
  99. <div class="elementor-control-input-wrapper">
  100. <select id="<?php echo $control_uid; ?>" data-setting="{{ data.name }}">
  101. <option value=""><?php echo __( 'None', 'elementor' ); ?></option>
  102. <?php foreach ( self::get_animations() as $animation_name => $animation_title ) : ?>
  103. <option value="<?php echo $animation_name; ?>"><?php echo $animation_title; ?></option>
  104. <?php endforeach; ?>
  105. </select>
  106. </div>
  107. </div>
  108. <# if ( data.description ) { #>
  109. <div class="elementor-control-field-description">{{{ data.description }}}</div>
  110. <# } #>
  111. <?php
  112. }
  113. /**
  114. * Get hover animation control default settings.
  115. *
  116. * Retrieve the default settings of the hover animation control. Used to return
  117. * the default settings while initializing the hover animation control.
  118. *
  119. * @since 1.0.0
  120. * @access protected
  121. *
  122. * @return array Control default settings.
  123. */
  124. protected function get_default_settings() {
  125. return [
  126. 'label_block' => true,
  127. ];
  128. }
  129. }