PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.14
UiCore Elements – Free widgets and templates for Elementor v1.0.14
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / utils / animation-component.php

animation-component.php in UiCore Elements – Free widgets and templates for Elementor 1.0.14, at includes/utils/animation-component.php

228 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Removes requested animations from the options. (optional)
17 * @param string|null $custom_slug A custom slug for the control. If null, use $name as slug, formating it. (optional)
18 * @param bool $use_new Include new animations not globally available. (optional)
19 *
20 * @return void
21 */
22 function TRAIT_register_hover_animation_control($name, $conditions = [], $filter = [], $custom_slug = null, $use_new = false)
23 {
24 // Custom slug or name converted to slug
25 // TODO: use sanitize_title() instead of the 3 functions combined above
26 $slug = isset($custom_slug) ? $custom_slug : strtolower(preg_replace('/\s+/', '_', preg_replace('/[^a-zA-Z0-9\s]/', '', $name)));
27
28 $this->add_control(
29 $slug,
30 [
31 'label' => esc_html__( $name, 'uicore-elements' ),
32 'type' => Controls_Manager::SELECT,
33 'default' => '',
34 'label_block' => true,
35 'options' => $this->uicore_get_animations($filter, $use_new),
36 'condition' => $conditions
37 ]
38 );
39 }
40 // Entrance Animations Controls.
41 function TRAIT_register_entrance_animations_controls()
42 {
43 $this->add_control(
44 'animate_items',
45 [
46 'label' => esc_html__('Animate each Item', 'uicore-elements'),
47 'type' => Controls_Manager::SWITCHER,
48 'default' => '',
49 'return_value' => 'ui-e-grid-animate',
50 'render_type' => 'none',
51 'frontend_available' => true,
52 ]
53 );
54 $this->add_control(
55 'animate_item_type',
56 [
57 'label' => __( 'Animation', 'uicore-elements' ),
58 'type' => Controls_Manager::SELECT,
59 'default' => 'fadeInUp',
60 'options' => [
61 'fadeInUp' => __( 'Fade In Up', 'uicore-elements' ),
62 'fadeInDown' => __( 'Fade In Down', 'uicore-elements' ),
63 'fadeInLeft' => __( 'Fade In Left', 'uicore-elements' ),
64 'fadeInRight' => __( 'Fade In Right', 'uicore-elements' ),
65 'fadeIn' => __( 'Fade In', 'uicore-elements' ),
66 'zoomIn' => __( 'Zoom In', 'uicore-elements' ),
67 ],
68 'condition' => array(
69 'animate_items' => 'ui-e-grid-animate',
70 ),
71 'frontend_available' => true,
72 ]
73 );
74 $this->add_control(
75 'animate_item_speed',
76 [
77 'label' => __( 'Speed', 'uicore-elements' ),
78 'type' => Controls_Manager::SLIDER,
79 'condition' => array(
80 'animate_items' => 'ui-e-grid-animate',
81 ),
82 'default'=> [
83 'unit' => 'px',
84 'size' => 1500,
85 ],
86 'range' => [
87 'px' => [
88 'min' => 10,
89 'max' => 3000,
90 'step' => 50,
91 ],
92 ],
93 'selectors' => [
94 '{{WRAPPER}}' => '---ui-speed: {{SIZE}}ms',
95 ],
96 ]
97 );
98 $this->add_control(
99 'animate_item_delay',
100 [
101 'label' => __( 'Animation Delay', 'uicore-elements' ),
102 'type' => Controls_Manager::SLIDER,
103 'default'=> [
104 'unit' => 'px',
105 'size' => 200,
106 ],
107 'range' => [
108 'px' => [
109 'min' => 0,
110 'max' => 1500,
111 'step' => 10,
112 ],
113 ],
114 'selectors' => [
115 '{{WRAPPER}}' => '---ui-delay: {{SIZE}}ms',
116 ],
117 'condition' => [
118 'animate_items' => 'ui-e-grid-animate',
119 ],
120 ]
121 );
122 $this->add_control(
123 'animate_item_stagger',
124 [
125 'label' => __( 'Stagger', 'uicore-elements' ),
126 'type' => Controls_Manager::SLIDER,
127 'condition' => array(
128 'animate_items' => 'ui-e-grid-animate',
129 ),
130 'default'=> [
131 'unit' => 'px',
132 'size' => 16,
133 ],
134 'range' => [
135 'px' => [
136 'min' => 4,
137 'max' => 500,
138 'step' => 2,
139 ],
140 ],
141 'selectors' => [
142 '{{WRAPPER}}' => '---ui-stagger: {{SIZE}}ms',
143 ],
144 ]
145 );
146 $this->add_control(
147 'hr',
148 [
149 'type' => \Elementor\Controls_Manager::DIVIDER,
150 'condition' => array(
151 'animate_items' => 'ui-e-grid-animate',
152 ),
153 ]
154 );
155 }
156
157 /**
158 * Retrieves the animations list available for the widget.
159 *
160 * @param array $filter_list Optional. An array of animation names to filter the results.
161 * @param bool $use_new Optional. Include new animations not globally available. Default is false.
162 *
163 * @return array The list of animations available for the widget.
164 */
165 function uicore_get_animations($filter_list = [], $use_new = false)
166 {
167 // New animations (transfer to default animation_list only after testing and updating all affected widgets)
168 $new_animations = [
169 'show' => 'Show'
170 ];
171
172 // Solid animations
173 $animation_list = [
174 '' => 'None',
175 'translate' => 'Translate',
176 'zoom' => 'Zoom',
177 'fade' => 'Fade',
178 'underline' => 'Underline',
179 ];
180 $list = [];
181 $animation_list = wp_parse_args($this->animation, $animation_list);
182
183 // Add new animations if requested
184 if( $use_new ){
185 $animation_list = array_merge($animation_list, $new_animations);
186 }
187
188 // Filter the list of animations
189 if (!empty($filter_list)) {
190 $animation_list = array_diff_key($animation_list, array_flip($filter_list));
191 }
192
193 // Format the list of animations, with translated strings, to be used as elementor option's array
194 foreach ($animation_list as $key => $value) {
195 $slug = $key !== '' ? "ui-e-item-anim-$key" : '';
196 $list[$slug] = esc_html__($value, 'uicore-elements');
197 }
198
199 return $list;
200 }
201
202 /**
203 * Update an existent animation control with newest animations.
204 *
205 * This method is meant to progressively add new animation to the previous
206 * animations list without impacting all widgets at once. It must be removed
207 * after a given animation is globaly available.
208 *
209 * @param $name The name of the existent control to be updated.
210 * @param array $filter Animation Filter list. (optional)
211 *
212 * @return void
213 */
214 function TRAIT_extend_control_animations($name, $filter = [])
215 {
216
217 // Get animations with new animations enabled
218 $animations = $this->uicore_get_animations($filter, true);
219
220 // Update the required control
221 $this->update_control(
222 $name,
223 [
224 'options' => $animations
225 ]
226 );
227 }
228 }