PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.0
Elementor Website Builder – more than just a page builder v3.1.0
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-list.php

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

674 lines 17.4 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 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
10
11 /**
12 * Elementor icon list widget.
13 *
14 * Elementor widget that displays a bullet list with any chosen icons and texts.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Icon_List extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve icon list widget name.
24 *
25 * @since 1.0.0
26 * @access public
27 *
28 * @return string Widget name.
29 */
30 public function get_name() {
31 return 'icon-list';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve icon list widget title.
38 *
39 * @since 1.0.0
40 * @access public
41 *
42 * @return string Widget title.
43 */
44 public function get_title() {
45 return __( 'Icon List', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve icon list widget icon.
52 *
53 * @since 1.0.0
54 * @access public
55 *
56 * @return string Widget icon.
57 */
58 public function get_icon() {
59 return 'eicon-bullet-list';
60 }
61
62 /**
63 * Get widget keywords.
64 *
65 * Retrieve the list of keywords the widget belongs to.
66 *
67 * @since 2.1.0
68 * @access public
69 *
70 * @return array Widget keywords.
71 */
72 public function get_keywords() {
73 return [ 'icon list', 'icon', 'list' ];
74 }
75
76 /**
77 * Register icon list widget controls.
78 *
79 * Adds different input fields to allow the user to change and customize the widget settings.
80 *
81 * @since 3.1.0
82 * @access protected
83 */
84 protected function register_controls() {
85 $this->start_controls_section(
86 'section_icon',
87 [
88 'label' => __( 'Icon List', 'elementor' ),
89 ]
90 );
91
92 $this->add_control(
93 'view',
94 [
95 'label' => __( 'Layout', 'elementor' ),
96 'type' => Controls_Manager::CHOOSE,
97 'default' => 'traditional',
98 'options' => [
99 'traditional' => [
100 'title' => __( 'Default', 'elementor' ),
101 'icon' => 'eicon-editor-list-ul',
102 ],
103 'inline' => [
104 'title' => __( 'Inline', 'elementor' ),
105 'icon' => 'eicon-ellipsis-h',
106 ],
107 ],
108 'render_type' => 'template',
109 'classes' => 'elementor-control-start-end',
110 'style_transfer' => true,
111 'prefix_class' => 'elementor-icon-list--layout-',
112 ]
113 );
114
115 $repeater = new Repeater();
116
117 $repeater->add_control(
118 'text',
119 [
120 'label' => __( 'Text', 'elementor' ),
121 'type' => Controls_Manager::TEXT,
122 'label_block' => true,
123 'placeholder' => __( 'List Item', 'elementor' ),
124 'default' => __( 'List Item', 'elementor' ),
125 'dynamic' => [
126 'active' => true,
127 ],
128 ]
129 );
130
131 $repeater->add_control(
132 'selected_icon',
133 [
134 'label' => __( 'Icon', 'elementor' ),
135 'type' => Controls_Manager::ICONS,
136 'default' => [
137 'value' => 'fas fa-check',
138 'library' => 'fa-solid',
139 ],
140 'fa4compatibility' => 'icon',
141 ]
142 );
143
144 $repeater->add_control(
145 'link',
146 [
147 'label' => __( 'Link', 'elementor' ),
148 'type' => Controls_Manager::URL,
149 'dynamic' => [
150 'active' => true,
151 ],
152 'placeholder' => __( 'https://your-link.com', 'elementor' ),
153 ]
154 );
155
156 $this->add_control(
157 'icon_list',
158 [
159 'label' => __( 'Items', 'elementor' ),
160 'type' => Controls_Manager::REPEATER,
161 'fields' => $repeater->get_controls(),
162 'default' => [
163 [
164 'text' => __( 'List Item #1', 'elementor' ),
165 'selected_icon' => [
166 'value' => 'fas fa-check',
167 'library' => 'fa-solid',
168 ],
169 ],
170 [
171 'text' => __( 'List Item #2', 'elementor' ),
172 'selected_icon' => [
173 'value' => 'fas fa-times',
174 'library' => 'fa-solid',
175 ],
176 ],
177 [
178 'text' => __( 'List Item #3', 'elementor' ),
179 'selected_icon' => [
180 'value' => 'fas fa-dot-circle',
181 'library' => 'fa-solid',
182 ],
183 ],
184 ],
185 'title_field' => '{{{ elementor.helpers.renderIcon( this, selected_icon, {}, "i", "panel" ) || \'<i class="{{ icon }}" aria-hidden="true"></i>\' }}} {{{ text }}}',
186 ]
187 );
188
189 $this->add_control(
190 'link_click',
191 [
192 'label' => __( 'Apply Link On', 'elementor' ),
193 'type' => Controls_Manager::SELECT,
194 'options' => [
195 'full_width' => __( 'Full Width', 'elementor' ),
196 'inline' => __( 'Inline', 'elementor' ),
197 ],
198 'default' => 'full_width',
199 'separator' => 'before',
200 'prefix_class' => 'elementor-list-item-link-',
201 ]
202 );
203
204 $this->end_controls_section();
205
206 $this->start_controls_section(
207 'section_icon_list',
208 [
209 'label' => __( 'List', 'elementor' ),
210 'tab' => Controls_Manager::TAB_STYLE,
211 ]
212 );
213
214 $this->add_responsive_control(
215 'space_between',
216 [
217 'label' => __( 'Space Between', 'elementor' ),
218 'type' => Controls_Manager::SLIDER,
219 'range' => [
220 'px' => [
221 'max' => 50,
222 ],
223 ],
224 'selectors' => [
225 '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child)' => 'padding-bottom: calc({{SIZE}}{{UNIT}}/2)',
226 '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:first-child)' => 'margin-top: calc({{SIZE}}{{UNIT}}/2)',
227 '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item' => 'margin-right: calc({{SIZE}}{{UNIT}}/2); margin-left: calc({{SIZE}}{{UNIT}}/2)',
228 '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items' => 'margin-right: calc(-{{SIZE}}{{UNIT}}/2); margin-left: calc(-{{SIZE}}{{UNIT}}/2)',
229 'body.rtl {{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:after' => 'left: calc(-{{SIZE}}{{UNIT}}/2)',
230 'body:not(.rtl) {{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:after' => 'right: calc(-{{SIZE}}{{UNIT}}/2)',
231 ],
232 ]
233 );
234
235 $this->add_responsive_control(
236 'icon_align',
237 [
238 'label' => __( 'Alignment', 'elementor' ),
239 'type' => Controls_Manager::CHOOSE,
240 'options' => [
241 'left' => [
242 'title' => __( 'Left', 'elementor' ),
243 'icon' => 'eicon-h-align-left',
244 ],
245 'center' => [
246 'title' => __( 'Center', 'elementor' ),
247 'icon' => 'eicon-h-align-center',
248 ],
249 'right' => [
250 'title' => __( 'Right', 'elementor' ),
251 'icon' => 'eicon-h-align-right',
252 ],
253 ],
254 'prefix_class' => 'elementor%s-align-',
255 ]
256 );
257
258 $this->add_control(
259 'divider',
260 [
261 'label' => __( 'Divider', 'elementor' ),
262 'type' => Controls_Manager::SWITCHER,
263 'label_off' => __( 'Off', 'elementor' ),
264 'label_on' => __( 'On', 'elementor' ),
265 'selectors' => [
266 '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'content: ""',
267 ],
268 'separator' => 'before',
269 ]
270 );
271
272 $this->add_control(
273 'divider_style',
274 [
275 'label' => __( 'Style', 'elementor' ),
276 'type' => Controls_Manager::SELECT,
277 'options' => [
278 'solid' => __( 'Solid', 'elementor' ),
279 'double' => __( 'Double', 'elementor' ),
280 'dotted' => __( 'Dotted', 'elementor' ),
281 'dashed' => __( 'Dashed', 'elementor' ),
282 ],
283 'default' => 'solid',
284 'condition' => [
285 'divider' => 'yes',
286 ],
287 'selectors' => [
288 '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child):after' => 'border-top-style: {{VALUE}}',
289 '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:not(:last-child):after' => 'border-left-style: {{VALUE}}',
290 ],
291 ]
292 );
293
294 $this->add_control(
295 'divider_weight',
296 [
297 'label' => __( 'Weight', 'elementor' ),
298 'type' => Controls_Manager::SLIDER,
299 'default' => [
300 'size' => 1,
301 ],
302 'range' => [
303 'px' => [
304 'min' => 1,
305 'max' => 20,
306 ],
307 ],
308 'condition' => [
309 'divider' => 'yes',
310 ],
311 'selectors' => [
312 '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child):after' => 'border-top-width: {{SIZE}}{{UNIT}}',
313 '{{WRAPPER}} .elementor-inline-items .elementor-icon-list-item:not(:last-child):after' => 'border-left-width: {{SIZE}}{{UNIT}}',
314 ],
315 ]
316 );
317
318 $this->add_control(
319 'divider_width',
320 [
321 'label' => __( 'Width', 'elementor' ),
322 'type' => Controls_Manager::SLIDER,
323 'default' => [
324 'unit' => '%',
325 ],
326 'condition' => [
327 'divider' => 'yes',
328 'view!' => 'inline',
329 ],
330 'selectors' => [
331 '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'width: {{SIZE}}{{UNIT}}',
332 ],
333 ]
334 );
335
336 $this->add_control(
337 'divider_height',
338 [
339 'label' => __( 'Height', 'elementor' ),
340 'type' => Controls_Manager::SLIDER,
341 'size_units' => [ '%', 'px' ],
342 'default' => [
343 'unit' => '%',
344 ],
345 'range' => [
346 'px' => [
347 'min' => 1,
348 'max' => 100,
349 ],
350 '%' => [
351 'min' => 1,
352 'max' => 100,
353 ],
354 ],
355 'condition' => [
356 'divider' => 'yes',
357 'view' => 'inline',
358 ],
359 'selectors' => [
360 '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'height: {{SIZE}}{{UNIT}}',
361 ],
362 ]
363 );
364
365 $this->add_control(
366 'divider_color',
367 [
368 'label' => __( 'Color', 'elementor' ),
369 'type' => Controls_Manager::COLOR,
370 'default' => '#ddd',
371 'global' => [
372 'default' => Global_Colors::COLOR_TEXT,
373 ],
374 'condition' => [
375 'divider' => 'yes',
376 ],
377 'selectors' => [
378 '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'border-color: {{VALUE}}',
379 ],
380 ]
381 );
382
383 $this->end_controls_section();
384
385 $this->start_controls_section(
386 'section_icon_style',
387 [
388 'label' => __( 'Icon', 'elementor' ),
389 'tab' => Controls_Manager::TAB_STYLE,
390 ]
391 );
392
393 $this->add_control(
394 'icon_color',
395 [
396 'label' => __( 'Color', 'elementor' ),
397 'type' => Controls_Manager::COLOR,
398 'default' => '',
399 'selectors' => [
400 '{{WRAPPER}} .elementor-icon-list-icon i' => 'color: {{VALUE}};',
401 '{{WRAPPER}} .elementor-icon-list-icon svg' => 'fill: {{VALUE}};',
402 ],
403 'global' => [
404 'default' => Global_Colors::COLOR_PRIMARY,
405 ],
406 ]
407 );
408
409 $this->add_control(
410 'icon_color_hover',
411 [
412 'label' => __( 'Hover', 'elementor' ),
413 'type' => Controls_Manager::COLOR,
414 'default' => '',
415 'selectors' => [
416 '{{WRAPPER}} .elementor-icon-list-item:hover .elementor-icon-list-icon i' => 'color: {{VALUE}};',
417 '{{WRAPPER}} .elementor-icon-list-item:hover .elementor-icon-list-icon svg' => 'fill: {{VALUE}};',
418 ],
419 ]
420 );
421
422 $this->add_responsive_control(
423 'icon_size',
424 [
425 'label' => __( 'Size', 'elementor' ),
426 'type' => Controls_Manager::SLIDER,
427 'default' => [
428 'size' => 14,
429 ],
430 'range' => [
431 'px' => [
432 'min' => 6,
433 ],
434 ],
435 'selectors' => [
436 '{{WRAPPER}} .elementor-icon-list-icon i' => 'font-size: {{SIZE}}{{UNIT}};',
437 '{{WRAPPER}} .elementor-icon-list-icon svg' => 'width: {{SIZE}}{{UNIT}};',
438 ],
439 ]
440 );
441
442 $this->add_responsive_control(
443 'icon_self_align',
444 [
445 'label' => __( 'Alignment', 'elementor' ),
446 'type' => Controls_Manager::CHOOSE,
447 'options' => [
448 'left' => [
449 'title' => __( 'Left', 'elementor' ),
450 'icon' => 'eicon-h-align-left',
451 ],
452 'center' => [
453 'title' => __( 'Center', 'elementor' ),
454 'icon' => 'eicon-h-align-center',
455 ],
456 'right' => [
457 'title' => __( 'Right', 'elementor' ),
458 'icon' => 'eicon-h-align-right',
459 ],
460 ],
461 'default' => '',
462 'selectors' => [
463 '{{WRAPPER}} .elementor-icon-list-icon' => 'text-align: {{VALUE}};',
464 ],
465 ]
466 );
467
468 $this->end_controls_section();
469
470 $this->start_controls_section(
471 'section_text_style',
472 [
473 'label' => __( 'Text', 'elementor' ),
474 'tab' => Controls_Manager::TAB_STYLE,
475 ]
476 );
477
478 $this->add_control(
479 'text_color',
480 [
481 'label' => __( 'Text Color', 'elementor' ),
482 'type' => Controls_Manager::COLOR,
483 'default' => '',
484 'selectors' => [
485 '{{WRAPPER}} .elementor-icon-list-text' => 'color: {{VALUE}};',
486 ],
487 'global' => [
488 'default' => Global_Colors::COLOR_SECONDARY,
489 ],
490 ]
491 );
492
493 $this->add_control(
494 'text_color_hover',
495 [
496 'label' => __( 'Hover', 'elementor' ),
497 'type' => Controls_Manager::COLOR,
498 'default' => '',
499 'selectors' => [
500 '{{WRAPPER}} .elementor-icon-list-item:hover .elementor-icon-list-text' => 'color: {{VALUE}};',
501 ],
502 ]
503 );
504
505 $this->add_control(
506 'text_indent',
507 [
508 'label' => __( 'Text Indent', 'elementor' ),
509 'type' => Controls_Manager::SLIDER,
510 'range' => [
511 'px' => [
512 'max' => 50,
513 ],
514 ],
515 'selectors' => [
516 '{{WRAPPER}} .elementor-icon-list-text' => is_rtl() ? 'padding-right: {{SIZE}}{{UNIT}};' : 'padding-left: {{SIZE}}{{UNIT}};',
517 ],
518 ]
519 );
520
521 $this->add_group_control(
522 Group_Control_Typography::get_type(),
523 [
524 'name' => 'icon_typography',
525 'selector' => '{{WRAPPER}} .elementor-icon-list-item, {{WRAPPER}} .elementor-icon-list-item a',
526 'global' => [
527 'default' => Global_Typography::TYPOGRAPHY_TEXT,
528 ],
529 ]
530 );
531
532 $this->end_controls_section();
533 }
534
535 /**
536 * Render icon list widget output on the frontend.
537 *
538 * Written in PHP and used to generate the final HTML.
539 *
540 * @since 1.0.0
541 * @access protected
542 */
543 protected function render() {
544 $settings = $this->get_settings_for_display();
545 $fallback_defaults = [
546 'fa fa-check',
547 'fa fa-times',
548 'fa fa-dot-circle-o',
549 ];
550
551 $this->add_render_attribute( 'icon_list', 'class', 'elementor-icon-list-items' );
552 $this->add_render_attribute( 'list_item', 'class', 'elementor-icon-list-item' );
553
554 if ( 'inline' === $settings['view'] ) {
555 $this->add_render_attribute( 'icon_list', 'class', 'elementor-inline-items' );
556 $this->add_render_attribute( 'list_item', 'class', 'elementor-inline-item' );
557 }
558 ?>
559 <ul <?php echo $this->get_render_attribute_string( 'icon_list' ); ?>>
560 <?php
561 foreach ( $settings['icon_list'] as $index => $item ) :
562 $repeater_setting_key = $this->get_repeater_setting_key( 'text', 'icon_list', $index );
563
564 $this->add_render_attribute( $repeater_setting_key, 'class', 'elementor-icon-list-text' );
565
566 $this->add_inline_editing_attributes( $repeater_setting_key );
567 $migration_allowed = Icons_Manager::is_migration_allowed();
568 ?>
569 <li <?php echo $this->get_render_attribute_string( 'list_item' ); ?>>
570 <?php
571 if ( ! empty( $item['link']['url'] ) ) {
572 $link_key = 'link_' . $index;
573
574 $this->add_link_attributes( $link_key, $item['link'] );
575
576 echo '<a ' . $this->get_render_attribute_string( $link_key ) . '>';
577 }
578
579 // add old default
580 if ( ! isset( $item['icon'] ) && ! $migration_allowed ) {
581 $item['icon'] = isset( $fallback_defaults[ $index ] ) ? $fallback_defaults[ $index ] : 'fa fa-check';
582 }
583
584 $migrated = isset( $item['__fa4_migrated']['selected_icon'] );
585 $is_new = ! isset( $item['icon'] ) && $migration_allowed;
586 if ( ! empty( $item['icon'] ) || ( ! empty( $item['selected_icon']['value'] ) && $is_new ) ) :
587 ?>
588 <span class="elementor-icon-list-icon">
589 <?php
590 if ( $is_new || $migrated ) {
591 Icons_Manager::render_icon( $item['selected_icon'], [ 'aria-hidden' => 'true' ] );
592 } else { ?>
593 <i class="<?php echo esc_attr( $item['icon'] ); ?>" aria-hidden="true"></i>
594 <?php } ?>
595 </span>
596 <?php endif; ?>
597 <span <?php echo $this->get_render_attribute_string( $repeater_setting_key ); ?>><?php echo $item['text']; ?></span>
598 <?php if ( ! empty( $item['link']['url'] ) ) : ?>
599 </a>
600 <?php endif; ?>
601 </li>
602 <?php
603 endforeach;
604 ?>
605 </ul>
606 <?php
607 }
608
609 /**
610 * Render icon list widget output in the editor.
611 *
612 * Written as a Backbone JavaScript template and used to generate the live preview.
613 *
614 * @since 2.9.0
615 * @access protected
616 */
617 protected function content_template() {
618 ?>
619 <#
620 view.addRenderAttribute( 'icon_list', 'class', 'elementor-icon-list-items' );
621 view.addRenderAttribute( 'list_item', 'class', 'elementor-icon-list-item' );
622
623 if ( 'inline' == settings.view ) {
624 view.addRenderAttribute( 'icon_list', 'class', 'elementor-inline-items' );
625 view.addRenderAttribute( 'list_item', 'class', 'elementor-inline-item' );
626 }
627 var iconsHTML = {},
628 migrated = {};
629 #>
630 <# if ( settings.icon_list ) { #>
631 <ul {{{ view.getRenderAttributeString( 'icon_list' ) }}}>
632 <# _.each( settings.icon_list, function( item, index ) {
633
634 var iconTextKey = view.getRepeaterSettingKey( 'text', 'icon_list', index );
635
636 view.addRenderAttribute( iconTextKey, 'class', 'elementor-icon-list-text' );
637
638 view.addInlineEditingAttributes( iconTextKey ); #>
639
640 <li {{{ view.getRenderAttributeString( 'list_item' ) }}}>
641 <# if ( item.link && item.link.url ) { #>
642 <a href="{{ item.link.url }}">
643 <# } #>
644 <# if ( item.icon || item.selected_icon.value ) { #>
645 <span class="elementor-icon-list-icon">
646 <#
647 iconsHTML[ index ] = elementor.helpers.renderIcon( view, item.selected_icon, { 'aria-hidden': true }, 'i', 'object' );
648 migrated[ index ] = elementor.helpers.isIconMigrated( item, 'selected_icon' );
649 if ( iconsHTML[ index ] && iconsHTML[ index ].rendered && ( ! item.icon || migrated[ index ] ) ) { #>
650 {{{ iconsHTML[ index ].value }}}
651 <# } else { #>
652 <i class="{{ item.icon }}" aria-hidden="true"></i>
653 <# }
654 #>
655 </span>
656 <# } #>
657 <span {{{ view.getRenderAttributeString( iconTextKey ) }}}>{{{ item.text }}}</span>
658 <# if ( item.link && item.link.url ) { #>
659 </a>
660 <# } #>
661 </li>
662 <#
663 } ); #>
664 </ul>
665 <# } #>
666
667 <?php
668 }
669
670 public function on_import( $element ) {
671 return Icons_Manager::on_import_migration( $element, 'icon', 'selected_icon', true );
672 }
673 }
674