PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.3
Elementor Website Builder – more than just a page builder v3.32.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / icon.php

icon.php in Elementor Website Builder – more than just a page builder 3.32.3, at includes/widgets/icon.php

520 lines 12.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9
10 /**
11 * Elementor icon widget.
12 *
13 * Elementor widget that displays an icon from over 600+ icons.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Icon extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve icon widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'icon';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve icon widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return esc_html__( 'Icon', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve icon widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-favorite';
59 }
60
61 /**
62 * Get widget categories.
63 *
64 * Retrieve the list of categories the icon widget belongs to.
65 *
66 * Used to determine where to display the widget in the editor.
67 *
68 * @since 2.0.0
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories() {
74 return [ 'basic' ];
75 }
76
77 public function has_widget_inner_wrapper(): bool {
78 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
79 }
80
81 /**
82 * Get widget keywords.
83 *
84 * Retrieve the list of keywords the widget belongs to.
85 *
86 * @since 2.1.0
87 * @access public
88 *
89 * @return array Widget keywords.
90 */
91 public function get_keywords() {
92 return [ 'icon' ];
93 }
94
95 protected function is_dynamic_content(): bool {
96 return false;
97 }
98
99 /**
100 * Register icon widget controls.
101 *
102 * Adds different input fields to allow the user to change and customize the widget settings.
103 *
104 * @since 3.1.0
105 * @access protected
106 */
107 protected function register_controls() {
108 $this->start_controls_section(
109 'section_icon',
110 [
111 'label' => esc_html__( 'Icon', 'elementor' ),
112 ]
113 );
114
115 $this->add_control(
116 'selected_icon',
117 [
118 'label' => esc_html__( 'Icon', 'elementor' ),
119 'type' => Controls_Manager::ICONS,
120 'fa4compatibility' => 'icon',
121 'default' => [
122 'value' => 'fas fa-star',
123 'library' => 'fa-solid',
124 ],
125 ]
126 );
127
128 $this->add_control(
129 'view',
130 [
131 'label' => esc_html__( 'View', 'elementor' ),
132 'type' => Controls_Manager::SELECT,
133 'options' => [
134 'default' => esc_html__( 'Default', 'elementor' ),
135 'stacked' => esc_html__( 'Stacked', 'elementor' ),
136 'framed' => esc_html__( 'Framed', 'elementor' ),
137 ],
138 'default' => 'default',
139 'prefix_class' => 'elementor-view-',
140 ]
141 );
142
143 $this->add_control(
144 'shape',
145 [
146 'label' => esc_html__( 'Shape', 'elementor' ),
147 'type' => Controls_Manager::SELECT,
148 'options' => [
149 'square' => esc_html__( 'Square', 'elementor' ),
150 'rounded' => esc_html__( 'Rounded', 'elementor' ),
151 'circle' => esc_html__( 'Circle', 'elementor' ),
152 ],
153 'default' => 'circle',
154 'condition' => [
155 'view!' => 'default',
156 ],
157 'prefix_class' => 'elementor-shape-',
158 ]
159 );
160
161 $this->add_control(
162 'link',
163 [
164 'label' => esc_html__( 'Link', 'elementor' ),
165 'type' => Controls_Manager::URL,
166 'dynamic' => [
167 'active' => true,
168 ],
169 ]
170 );
171
172 $this->end_controls_section();
173
174 $this->start_controls_section(
175 'section_style_icon',
176 [
177 'label' => esc_html__( 'Icon', 'elementor' ),
178 'tab' => Controls_Manager::TAB_STYLE,
179 ]
180 );
181
182 $this->add_responsive_control(
183 'align',
184 [
185 'label' => esc_html__( 'Alignment', 'elementor' ),
186 'type' => Controls_Manager::CHOOSE,
187 'options' => [
188 'left' => [
189 'title' => esc_html__( 'Left', 'elementor' ),
190 'icon' => 'eicon-text-align-left',
191 ],
192 'center' => [
193 'title' => esc_html__( 'Center', 'elementor' ),
194 'icon' => 'eicon-text-align-center',
195 ],
196 'right' => [
197 'title' => esc_html__( 'Right', 'elementor' ),
198 'icon' => 'eicon-text-align-right',
199 ],
200 ],
201 'default' => 'center',
202 'selectors' => [
203 '{{WRAPPER}} .elementor-icon-wrapper' => 'text-align: {{VALUE}};',
204 ],
205 ]
206 );
207
208 $this->start_controls_tabs( 'icon_colors' );
209
210 $this->start_controls_tab(
211 'icon_colors_normal',
212 [
213 'label' => esc_html__( 'Normal', 'elementor' ),
214 ]
215 );
216
217 $this->add_control(
218 'primary_color',
219 [
220 'label' => esc_html__( 'Primary Color', 'elementor' ),
221 'type' => Controls_Manager::COLOR,
222 'default' => '',
223 'selectors' => [
224 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
225 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
226 '{{WRAPPER}}.elementor-view-framed .elementor-icon, {{WRAPPER}}.elementor-view-default .elementor-icon svg' => 'fill: {{VALUE}};',
227 ],
228 'global' => [
229 'default' => Global_Colors::COLOR_PRIMARY,
230 ],
231 ]
232 );
233
234 $this->add_control(
235 'secondary_color',
236 [
237 'label' => esc_html__( 'Secondary Color', 'elementor' ),
238 'type' => Controls_Manager::COLOR,
239 'default' => '',
240 'condition' => [
241 'view!' => 'default',
242 ],
243 'selectors' => [
244 '{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
245 '{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
246 '{{WRAPPER}}.elementor-view-stacked .elementor-icon svg' => 'fill: {{VALUE}};',
247 ],
248 ]
249 );
250
251 $this->end_controls_tab();
252
253 $this->start_controls_tab(
254 'icon_colors_hover',
255 [
256 'label' => esc_html__( 'Hover', 'elementor' ),
257 ]
258 );
259
260 $this->add_control(
261 'hover_primary_color',
262 [
263 'label' => esc_html__( 'Primary Color', 'elementor' ),
264 'type' => Controls_Manager::COLOR,
265 'default' => '',
266 'selectors' => [
267 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
268 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
269 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, {{WRAPPER}}.elementor-view-default .elementor-icon:hover svg' => 'fill: {{VALUE}};',
270 ],
271 ]
272 );
273
274 $this->add_control(
275 'hover_secondary_color',
276 [
277 'label' => esc_html__( 'Secondary Color', 'elementor' ),
278 'type' => Controls_Manager::COLOR,
279 'default' => '',
280 'condition' => [
281 'view!' => 'default',
282 ],
283 'selectors' => [
284 '{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
285 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
286 '{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover svg' => 'fill: {{VALUE}};',
287 ],
288 ]
289 );
290
291 $this->add_control(
292 'hover_animation',
293 [
294 'label' => esc_html__( 'Hover Animation', 'elementor' ),
295 'type' => Controls_Manager::HOVER_ANIMATION,
296 ]
297 );
298
299 $this->end_controls_tab();
300
301 $this->end_controls_tabs();
302
303 $this->add_responsive_control(
304 'size',
305 [
306 'label' => esc_html__( 'Size', 'elementor' ),
307 'type' => Controls_Manager::SLIDER,
308 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
309 'range' => [
310 'px' => [
311 'min' => 6,
312 'max' => 300,
313 ],
314 ],
315 'selectors' => [
316 '{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
317 '{{WRAPPER}} .elementor-icon svg' => 'height: {{SIZE}}{{UNIT}};',
318 ],
319 'separator' => 'before',
320 ]
321 );
322
323 $this->add_control(
324 'fit_to_size',
325 [
326 'label' => esc_html__( 'Fit to Size', 'elementor' ),
327 'type' => Controls_Manager::SWITCHER,
328 'description' => 'Avoid gaps around icons when width and height aren\'t equal',
329 'label_off' => esc_html__( 'Off', 'elementor' ),
330 'label_on' => esc_html__( 'On', 'elementor' ),
331 'condition' => [
332 'selected_icon[library]' => 'svg',
333 ],
334 'selectors' => [
335 '{{WRAPPER}} .elementor-icon-wrapper svg' => 'width: auto;',
336 ],
337 ]
338 );
339
340 $this->add_control(
341 'icon_padding',
342 [
343 'label' => esc_html__( 'Padding', 'elementor' ),
344 'type' => Controls_Manager::SLIDER,
345 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
346 'selectors' => [
347 '{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
348 ],
349 'range' => [
350 'px' => [
351 'max' => 50,
352 ],
353 'em' => [
354 'min' => 0,
355 'max' => 5,
356 ],
357 'rem' => [
358 'min' => 0,
359 'max' => 5,
360 ],
361 ],
362 'condition' => [
363 'view!' => 'default',
364 ],
365 ]
366 );
367
368 $this->add_responsive_control(
369 'rotate',
370 [
371 'label' => esc_html__( 'Rotate', 'elementor' ),
372 'type' => Controls_Manager::SLIDER,
373 'size_units' => [ 'deg', 'grad', 'rad', 'turn', 'custom' ],
374 'default' => [
375 'unit' => 'deg',
376 ],
377 'tablet_default' => [
378 'unit' => 'deg',
379 ],
380 'mobile_default' => [
381 'unit' => 'deg',
382 ],
383 'selectors' => [
384 '{{WRAPPER}} .elementor-icon i, {{WRAPPER}} .elementor-icon svg' => 'transform: rotate({{SIZE}}{{UNIT}});',
385 ],
386 ]
387 );
388
389 $this->add_control(
390 'border_width',
391 [
392 'label' => esc_html__( 'Border Width', 'elementor' ),
393 'type' => Controls_Manager::DIMENSIONS,
394 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
395 'selectors' => [
396 '{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
397 ],
398 'condition' => [
399 'view' => 'framed',
400 ],
401 ]
402 );
403
404 $this->add_responsive_control(
405 'border_radius',
406 [
407 'label' => esc_html__( 'Border Radius', 'elementor' ),
408 'type' => Controls_Manager::DIMENSIONS,
409 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
410 'selectors' => [
411 '{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
412 ],
413 'condition' => [
414 'view!' => 'default',
415 ],
416 ]
417 );
418
419 $this->end_controls_section();
420 }
421
422 /**
423 * Render icon widget output on the frontend.
424 *
425 * Written in PHP and used to generate the final HTML.
426 *
427 * @since 1.0.0
428 * @access protected
429 */
430 protected function render() {
431 $settings = $this->get_settings_for_display();
432
433 if ( empty( $settings['selected_icon']['value'] ) ) {
434 return;
435 }
436
437 $this->add_render_attribute( 'wrapper', 'class', 'elementor-icon-wrapper' );
438
439 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-icon' );
440
441 if ( ! empty( $settings['hover_animation'] ) ) {
442 $this->add_render_attribute( 'icon-wrapper', 'class', 'elementor-animation-' . $settings['hover_animation'] );
443 }
444
445 $icon_tag = 'div';
446
447 if ( ! empty( $settings['link']['url'] ) ) {
448 $this->add_link_attributes( 'icon-wrapper', $settings['link'] );
449
450 $icon_tag = 'a';
451 }
452
453 if ( empty( $settings['icon'] ) && ! Icons_Manager::is_migration_allowed() ) {
454 // add old default
455 $settings['icon'] = 'fa fa-star';
456 }
457
458 if ( ! empty( $settings['icon'] ) ) {
459 $this->add_render_attribute( 'icon', 'class', $settings['icon'] );
460 $this->add_render_attribute( 'icon', 'aria-hidden', 'true' );
461 }
462
463 $migrated = isset( $settings['__fa4_migrated']['selected_icon'] );
464 $is_new = empty( $settings['icon'] ) && Icons_Manager::is_migration_allowed();
465
466 ?>
467 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
468 <<?php Utils::print_unescaped_internal_string( $icon_tag . ' ' . $this->get_render_attribute_string( 'icon-wrapper' ) ); ?>>
469 <?php if ( $is_new || $migrated ) :
470 Icons_Manager::render_icon( $settings['selected_icon'], [ 'aria-hidden' => 'true' ] );
471 else : ?>
472 <i <?php $this->print_render_attribute_string( 'icon' ); ?>></i>
473 <?php endif; ?>
474 </<?php Utils::print_unescaped_internal_string( $icon_tag ); ?>>
475 </div>
476 <?php
477 }
478
479 /**
480 * Render icon widget output in the editor.
481 *
482 * Written as a Backbone JavaScript template and used to generate the live preview.
483 *
484 * @since 2.9.0
485 * @access protected
486 */
487 protected function content_template() {
488 ?>
489 <#
490 if ( '' === settings.selected_icon.value ) {
491 return;
492 }
493
494 if ( settings.link?.url ) {
495 view.addRenderAttribute( 'link_url', 'href', elementor.helpers.sanitizeUrl( settings.link?.url ) );
496 }
497
498 const iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'i' , 'object' ),
499 migrated = elementor.helpers.isIconMigrated( settings, 'selected_icon' ),
500 iconTag = settings.link?.url ? 'a' : 'div';
501
502 view.addRenderAttribute( 'icon', 'class', 'elementor-icon' );
503
504 if ( '' !== settings.hover_animation ) {
505 view.addRenderAttribute( 'icon', 'class', 'elementor-animation-' + settings.hover_animation );
506 }
507 #>
508 <div class="elementor-icon-wrapper">
509 <{{{ iconTag }}} {{{ view.getRenderAttributeString( 'icon' ) }}} {{{ view.getRenderAttributeString( 'link_url' ) }}}>
510 <# if ( iconHTML && iconHTML.rendered && ( ! settings.icon || migrated ) ) { #>
511 {{{ iconHTML.value }}}
512 <# } else { #>
513 <i class="{{ settings.icon }}" aria-hidden="true"></i>
514 <# } #>
515 </{{{ iconTag }}}>
516 </div>
517 <?php
518 }
519 }
520