| 1 |
<?php |
| 2 |
namespace UiCoreElements\Utils; |
| 3 |
use Elementor\Controls_Manager; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit(); |
| 6 |
|
| 7 |
trait Animation_Trait { |
| 8 |
|
| 9 |
private $animation; |
| 10 |
|
| 11 |
/** |
| 12 |
* Registers a hover animation control. |
| 13 |
* |
| 14 |
* @param string $name The name of the control. |
| 15 |
* @param array $conditions Control conditions. (optional) |
| 16 |
* @param array $filter Animation Filter list. (optional) |
| 17 |
* @param string|null $custom_slug A custom slug for the control. If null, use $name as slug, formating it. (optional) |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function TRAIT_register_hover_animation_control($name, $conditions = [], $filter = [], $custom_slug = null) |
| 21 |
{ |
| 22 |
// Custom slug or name converted to slug |
| 23 |
$slug = isset($custom_slug) ? $custom_slug : strtolower(preg_replace('/\s+/', '_', preg_replace('/[^a-zA-Z0-9\s]/', '', $name))); |
| 24 |
|
| 25 |
$this->add_control( |
| 26 |
$slug, |
| 27 |
[ |
| 28 |
'label' => esc_html__( $name, 'uicore-elements' ), |
| 29 |
'type' => Controls_Manager::SELECT, |
| 30 |
'default' => '', |
| 31 |
'label_block' => true, |
| 32 |
'options' => $this->uicore_get_animations($filter), |
| 33 |
'condition' => $conditions |
| 34 |
] |
| 35 |
); |
| 36 |
} |
| 37 |
// Entrance Animations Controls. |
| 38 |
function TRAIT_register_entrance_animations_controls() |
| 39 |
{ |
| 40 |
$this->add_control( |
| 41 |
'animate_items', |
| 42 |
[ |
| 43 |
'label' => esc_html__('Animate each Item', 'uicore-elements'), |
| 44 |
'type' => Controls_Manager::SWITCHER, |
| 45 |
'default' => '', |
| 46 |
'return_value' => 'ui-e-grid-animate', |
| 47 |
'render_type' => 'none', |
| 48 |
'frontend_available' => true, |
| 49 |
] |
| 50 |
); |
| 51 |
$this->add_control( |
| 52 |
'animate_item_type', |
| 53 |
[ |
| 54 |
'label' => __( 'Animation', 'uicore-elements' ), |
| 55 |
'type' => Controls_Manager::SELECT, |
| 56 |
'default' => 'fadeInUp', |
| 57 |
'options' => [ |
| 58 |
'fadeInUp' => __( 'Fade In Up', 'uicore-elements' ), |
| 59 |
'fadeInDown' => __( 'Fade In Down', 'uicore-elements' ), |
| 60 |
'fadeInLeft' => __( 'Fade In Left', 'uicore-elements' ), |
| 61 |
'fadeInRight' => __( 'Fade In Right', 'uicore-elements' ), |
| 62 |
'fadeIn' => __( 'Fade In', 'uicore-elements' ), |
| 63 |
'zoomIn' => __( 'Zoom In', 'uicore-elements' ), |
| 64 |
], |
| 65 |
'condition' => array( |
| 66 |
'animate_items' => 'ui-e-grid-animate', |
| 67 |
), |
| 68 |
'frontend_available' => true, |
| 69 |
] |
| 70 |
); |
| 71 |
$this->add_control( |
| 72 |
'animate_item_speed', |
| 73 |
[ |
| 74 |
'label' => __( 'Speed', 'uicore-elements' ), |
| 75 |
'type' => Controls_Manager::SLIDER, |
| 76 |
'condition' => array( |
| 77 |
'animate_items' => 'ui-e-grid-animate', |
| 78 |
), |
| 79 |
'default'=> [ |
| 80 |
'unit' => 'px', |
| 81 |
'size' => 1500, |
| 82 |
], |
| 83 |
'range' => [ |
| 84 |
'px' => [ |
| 85 |
'min' => 10, |
| 86 |
'max' => 3000, |
| 87 |
'step' => 50, |
| 88 |
], |
| 89 |
], |
| 90 |
'selectors' => [ |
| 91 |
'{{WRAPPER}}' => '---ui-speed: {{SIZE}}ms', |
| 92 |
], |
| 93 |
] |
| 94 |
); |
| 95 |
$this->add_control( |
| 96 |
'animate_item_delay', |
| 97 |
[ |
| 98 |
'label' => __( 'Animation Delay', 'uicore-elements' ), |
| 99 |
'type' => Controls_Manager::SLIDER, |
| 100 |
'default'=> [ |
| 101 |
'unit' => 'px', |
| 102 |
'size' => 200, |
| 103 |
], |
| 104 |
'range' => [ |
| 105 |
'px' => [ |
| 106 |
'min' => 0, |
| 107 |
'max' => 1500, |
| 108 |
'step' => 10, |
| 109 |
], |
| 110 |
], |
| 111 |
'selectors' => [ |
| 112 |
'{{WRAPPER}}' => '---ui-delay: {{SIZE}}ms', |
| 113 |
], |
| 114 |
'condition' => [ |
| 115 |
'animate_items' => 'ui-e-grid-animate', |
| 116 |
], |
| 117 |
] |
| 118 |
); |
| 119 |
$this->add_control( |
| 120 |
'animate_item_stagger', |
| 121 |
[ |
| 122 |
'label' => __( 'Stagger', 'uicore-elements' ), |
| 123 |
'type' => Controls_Manager::SLIDER, |
| 124 |
'condition' => array( |
| 125 |
'animate_items' => 'ui-e-grid-animate', |
| 126 |
), |
| 127 |
'default'=> [ |
| 128 |
'unit' => 'px', |
| 129 |
'size' => 16, |
| 130 |
], |
| 131 |
'range' => [ |
| 132 |
'px' => [ |
| 133 |
'min' => 4, |
| 134 |
'max' => 500, |
| 135 |
'step' => 2, |
| 136 |
], |
| 137 |
], |
| 138 |
'selectors' => [ |
| 139 |
'{{WRAPPER}}' => '---ui-stagger: {{SIZE}}ms', |
| 140 |
], |
| 141 |
] |
| 142 |
); |
| 143 |
$this->add_control( |
| 144 |
'hr', |
| 145 |
[ |
| 146 |
'type' => \Elementor\Controls_Manager::DIVIDER, |
| 147 |
'condition' => array( |
| 148 |
'animate_items' => 'ui-e-grid-animate', |
| 149 |
), |
| 150 |
] |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Retrieves the animations list available for the widget. |
| 156 |
* |
| 157 |
* @param array $filter_list Optional. An array of animation names to filter the results. |
| 158 |
* @return array The list of animations available for the widget. |
| 159 |
*/ |
| 160 |
function uicore_get_animations($filter_list = []) |
| 161 |
{ |
| 162 |
// Animations |
| 163 |
$animation_list = [ |
| 164 |
'' => 'None', |
| 165 |
'translate' => 'Translate', |
| 166 |
'zoom' => 'Zoom', |
| 167 |
'fade' => 'Fade', |
| 168 |
'underline' => 'Underline', |
| 169 |
]; |
| 170 |
$list = []; |
| 171 |
$animation_list = wp_parse_args($this->animation, $animation_list); |
| 172 |
|
| 173 |
// Filter the list of animations |
| 174 |
if (!empty($filter_list)) { |
| 175 |
$animation_list = array_diff_key($animation_list, array_flip($filter_list)); |
| 176 |
} |
| 177 |
|
| 178 |
// Format the list of animations, with translated strings, to be used as elementor option's array |
| 179 |
foreach ($animation_list as $key => $value) { |
| 180 |
$slug = $key !== '' ? "ui-e-item-anim-$key" : ''; |
| 181 |
$list[$slug] = esc_html__($value, 'uicore-elements'); |
| 182 |
} |
| 183 |
|
| 184 |
return $list; |
| 185 |
} |
| 186 |
} |