PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.1
Elementor Website Builder – more than just a page builder v3.4.1
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.4.1, at includes/widgets/icon-list.php

683 lines 17.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 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 esc_html__( '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' => esc_html__( 'Icon List', 'elementor' ),
89 ]
90 );
91
92 $this->add_control(
93 'view',
94 [
95 'label' => esc_html__( 'Layout', 'elementor' ),
96 'type' => Controls_Manager::CHOOSE,
97 'default' => 'traditional',
98 'options' => [
99 'traditional' => [
100 'title' => esc_html__( 'Default', 'elementor' ),
101 'icon' => 'eicon-editor-list-ul',
102 ],
103 'inline' => [
104 'title' => esc_html__( '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' => esc_html__( 'Text', 'elementor' ),
121 'type' => Controls_Manager::TEXT,
122 'label_block' => true,
123 'placeholder' => esc_html__( 'List Item', 'elementor' ),
124 'default' => esc_html__( 'List Item', 'elementor' ),
125 'dynamic' => [
126 'active' => true,
127 ],
128 ]
129 );
130
131 $repeater->add_control(
132 'selected_icon',
133 [
134 'label' => esc_html__( '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' => esc_html__( 'Link', 'elementor' ),
148 'type' => Controls_Manager::URL,
149 'dynamic' => [
150 'active' => true,
151 ],
152 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
153 ]
154 );
155
156 $this->add_control(
157 'icon_list',
158 [
159 'label' => esc_html__( 'Items', 'elementor' ),
160 'type' => Controls_Manager::REPEATER,
161 'fields' => $repeater->get_controls(),
162 'default' => [
163 [
164 'text' => esc_html__( 'List Item #1', 'elementor' ),
165 'selected_icon' => [
166 'value' => 'fas fa-check',
167 'library' => 'fa-solid',
168 ],
169 ],
170 [
171 'text' => esc_html__( 'List Item #2', 'elementor' ),
172 'selected_icon' => [
173 'value' => 'fas fa-times',
174 'library' => 'fa-solid',
175 ],
176 ],
177 [
178 'text' => esc_html__( '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' => esc_html__( 'Apply Link On', 'elementor' ),
193 'type' => Controls_Manager::SELECT,
194 'options' => [
195 'full_width' => esc_html__( 'Full Width', 'elementor' ),
196 'inline' => esc_html__( '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' => esc_html__( 'List', 'elementor' ),
210 'tab' => Controls_Manager::TAB_STYLE,
211 ]
212 );
213
214 $this->add_responsive_control(
215 'space_between',
216 [
217 'label' => esc_html__( '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' => esc_html__( 'Alignment', 'elementor' ),
239 'type' => Controls_Manager::CHOOSE,
240 'options' => [
241 'left' => [
242 'title' => esc_html__( 'Left', 'elementor' ),
243 'icon' => 'eicon-h-align-left',
244 ],
245 'center' => [
246 'title' => esc_html__( 'Center', 'elementor' ),
247 'icon' => 'eicon-h-align-center',
248 ],
249 'right' => [
250 'title' => esc_html__( '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' => esc_html__( 'Divider', 'elementor' ),
262 'type' => Controls_Manager::SWITCHER,
263 'label_off' => esc_html__( 'Off', 'elementor' ),
264 'label_on' => esc_html__( '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' => esc_html__( 'Style', 'elementor' ),
276 'type' => Controls_Manager::SELECT,
277 'options' => [
278 'solid' => esc_html__( 'Solid', 'elementor' ),
279 'double' => esc_html__( 'Double', 'elementor' ),
280 'dotted' => esc_html__( 'Dotted', 'elementor' ),
281 'dashed' => esc_html__( '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' => esc_html__( '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' => esc_html__( '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' => esc_html__( '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' => esc_html__( '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' => esc_html__( 'Icon', 'elementor' ),
389 'tab' => Controls_Manager::TAB_STYLE,
390 ]
391 );
392
393 $this->add_control(
394 'icon_color',
395 [
396 'label' => esc_html__( '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' => esc_html__( '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' => esc_html__( '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' => '--e-icon-list-icon-size: {{SIZE}}{{UNIT}};',
437 ],
438 ]
439 );
440
441 $this->add_responsive_control(
442 'icon_self_align',
443 [
444 'label' => esc_html__( 'Alignment', 'elementor' ),
445 'type' => Controls_Manager::CHOOSE,
446 'options' => [
447 'left' => [
448 'title' => esc_html__( 'Left', 'elementor' ),
449 'icon' => 'eicon-h-align-left',
450 ],
451 'center' => [
452 'title' => esc_html__( 'Center', 'elementor' ),
453 'icon' => 'eicon-h-align-center',
454 ],
455 'right' => [
456 'title' => esc_html__( 'Right', 'elementor' ),
457 'icon' => 'eicon-h-align-right',
458 ],
459 ],
460 'default' => '',
461 'selectors' => [
462 '{{WRAPPER}} .elementor-icon-list-icon' => 'text-align: {{VALUE}};',
463 ],
464 ]
465 );
466
467 $this->end_controls_section();
468
469 $this->start_controls_section(
470 'section_text_style',
471 [
472 'label' => esc_html__( 'Text', 'elementor' ),
473 'tab' => Controls_Manager::TAB_STYLE,
474 ]
475 );
476
477 $this->add_control(
478 'text_color',
479 [
480 'label' => esc_html__( 'Text Color', 'elementor' ),
481 'type' => Controls_Manager::COLOR,
482 'default' => '',
483 'selectors' => [
484 '{{WRAPPER}} .elementor-icon-list-text' => 'color: {{VALUE}};',
485 ],
486 'global' => [
487 'default' => Global_Colors::COLOR_SECONDARY,
488 ],
489 ]
490 );
491
492 $this->add_control(
493 'text_color_hover',
494 [
495 'label' => esc_html__( 'Hover', 'elementor' ),
496 'type' => Controls_Manager::COLOR,
497 'default' => '',
498 'selectors' => [
499 '{{WRAPPER}} .elementor-icon-list-item:hover .elementor-icon-list-text' => 'color: {{VALUE}};',
500 ],
501 ]
502 );
503
504 $this->add_control(
505 'text_indent',
506 [
507 'label' => esc_html__( 'Text Indent', 'elementor' ),
508 'type' => Controls_Manager::SLIDER,
509 'range' => [
510 'px' => [
511 'max' => 50,
512 ],
513 ],
514 'selectors' => [
515 '{{WRAPPER}} .elementor-icon-list-text' => is_rtl() ? 'padding-right: {{SIZE}}{{UNIT}};' : 'padding-left: {{SIZE}}{{UNIT}};',
516 ],
517 ]
518 );
519
520 $this->add_group_control(
521 Group_Control_Typography::get_type(),
522 [
523 'name' => 'icon_typography',
524 'selector' => '{{WRAPPER}} .elementor-icon-list-item > .elementor-icon-list-text, {{WRAPPER}} .elementor-icon-list-item > a',
525 'global' => [
526 'default' => Global_Typography::TYPOGRAPHY_TEXT,
527 ],
528 ]
529 );
530
531 $this->add_group_control(
532 Group_Control_Text_Shadow::get_type(),
533 [
534 'name' => 'text_shadow',
535 'selector' => '{{WRAPPER}} .elementor-icon-list-text',
536 ]
537 );
538
539 $this->end_controls_section();
540 }
541
542 /**
543 * Render icon list widget output on the frontend.
544 *
545 * Written in PHP and used to generate the final HTML.
546 *
547 * @since 1.0.0
548 * @access protected
549 */
550 protected function render() {
551 $settings = $this->get_settings_for_display();
552 $fallback_defaults = [
553 'fa fa-check',
554 'fa fa-times',
555 'fa fa-dot-circle-o',
556 ];
557
558 $this->add_render_attribute( 'icon_list', 'class', 'elementor-icon-list-items' );
559 $this->add_render_attribute( 'list_item', 'class', 'elementor-icon-list-item' );
560
561 if ( 'inline' === $settings['view'] ) {
562 $this->add_render_attribute( 'icon_list', 'class', 'elementor-inline-items' );
563 $this->add_render_attribute( 'list_item', 'class', 'elementor-inline-item' );
564 }
565 ?>
566 <ul <?php $this->print_render_attribute_string( 'icon_list' ); ?>>
567 <?php
568 foreach ( $settings['icon_list'] as $index => $item ) :
569 $repeater_setting_key = $this->get_repeater_setting_key( 'text', 'icon_list', $index );
570
571 $this->add_render_attribute( $repeater_setting_key, 'class', 'elementor-icon-list-text' );
572
573 $this->add_inline_editing_attributes( $repeater_setting_key );
574 $migration_allowed = Icons_Manager::is_migration_allowed();
575 ?>
576 <li <?php $this->print_render_attribute_string( 'list_item' ); ?>>
577 <?php
578 if ( ! empty( $item['link']['url'] ) ) {
579 $link_key = 'link_' . $index;
580
581 $this->add_link_attributes( $link_key, $item['link'] );
582 ?>
583 <a <?php $this->print_render_attribute_string( $link_key ); ?>>
584
585 <?php
586 }
587
588 // add old default
589 if ( ! isset( $item['icon'] ) && ! $migration_allowed ) {
590 $item['icon'] = isset( $fallback_defaults[ $index ] ) ? $fallback_defaults[ $index ] : 'fa fa-check';
591 }
592
593 $migrated = isset( $item['__fa4_migrated']['selected_icon'] );
594 $is_new = ! isset( $item['icon'] ) && $migration_allowed;
595 if ( ! empty( $item['icon'] ) || ( ! empty( $item['selected_icon']['value'] ) && $is_new ) ) :
596 ?>
597 <span class="elementor-icon-list-icon">
598 <?php
599 if ( $is_new || $migrated ) {
600 Icons_Manager::render_icon( $item['selected_icon'], [ 'aria-hidden' => 'true' ] );
601 } else { ?>
602 <i class="<?php echo esc_attr( $item['icon'] ); ?>" aria-hidden="true"></i>
603 <?php } ?>
604 </span>
605 <?php endif; ?>
606 <span <?php $this->print_render_attribute_string( $repeater_setting_key ); ?>><?php $this->print_unescaped_setting( 'text', 'icon_list', $index ); ?></span>
607 <?php if ( ! empty( $item['link']['url'] ) ) : ?>
608 </a>
609 <?php endif; ?>
610 </li>
611 <?php
612 endforeach;
613 ?>
614 </ul>
615 <?php
616 }
617
618 /**
619 * Render icon list widget output in the editor.
620 *
621 * Written as a Backbone JavaScript template and used to generate the live preview.
622 *
623 * @since 2.9.0
624 * @access protected
625 */
626 protected function content_template() {
627 ?>
628 <#
629 view.addRenderAttribute( 'icon_list', 'class', 'elementor-icon-list-items' );
630 view.addRenderAttribute( 'list_item', 'class', 'elementor-icon-list-item' );
631
632 if ( 'inline' == settings.view ) {
633 view.addRenderAttribute( 'icon_list', 'class', 'elementor-inline-items' );
634 view.addRenderAttribute( 'list_item', 'class', 'elementor-inline-item' );
635 }
636 var iconsHTML = {},
637 migrated = {};
638 #>
639 <# if ( settings.icon_list ) { #>
640 <ul {{{ view.getRenderAttributeString( 'icon_list' ) }}}>
641 <# _.each( settings.icon_list, function( item, index ) {
642
643 var iconTextKey = view.getRepeaterSettingKey( 'text', 'icon_list', index );
644
645 view.addRenderAttribute( iconTextKey, 'class', 'elementor-icon-list-text' );
646
647 view.addInlineEditingAttributes( iconTextKey ); #>
648
649 <li {{{ view.getRenderAttributeString( 'list_item' ) }}}>
650 <# if ( item.link && item.link.url ) { #>
651 <a href="{{ item.link.url }}">
652 <# } #>
653 <# if ( item.icon || item.selected_icon.value ) { #>
654 <span class="elementor-icon-list-icon">
655 <#
656 iconsHTML[ index ] = elementor.helpers.renderIcon( view, item.selected_icon, { 'aria-hidden': true }, 'i', 'object' );
657 migrated[ index ] = elementor.helpers.isIconMigrated( item, 'selected_icon' );
658 if ( iconsHTML[ index ] && iconsHTML[ index ].rendered && ( ! item.icon || migrated[ index ] ) ) { #>
659 {{{ iconsHTML[ index ].value }}}
660 <# } else { #>
661 <i class="{{ item.icon }}" aria-hidden="true"></i>
662 <# }
663 #>
664 </span>
665 <# } #>
666 <span {{{ view.getRenderAttributeString( iconTextKey ) }}}>{{{ item.text }}}</span>
667 <# if ( item.link && item.link.url ) { #>
668 </a>
669 <# } #>
670 </li>
671 <#
672 } ); #>
673 </ul>
674 <# } #>
675
676 <?php
677 }
678
679 public function on_import( $element ) {
680 return Icons_Manager::on_import_migration( $element, 'icon', 'selected_icon', true );
681 }
682 }
683