PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.4
UiCore Elements – Free widgets and templates for Elementor v1.2.4
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.2.4, at includes/utils/animation-component.php

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