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