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

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