← All changes
|
modules/nested-tabs/widgets/nested-tabs.php
+152
-186
4.1.1
→
3.20.0-dev3
View file →
| @@ -14,19 +14,18 @@ | ||
| 14 | 14 | use Elementor\Modules\NestedElements\Base\Widget_Nested_Base; |
| 15 | 15 | use Elementor\Modules\NestedElements\Controls\Control_Nested_Repeater; |
| 16 | 16 | use Elementor\Plugin; |
| 17 | 17 | use Elementor\Repeater; |
| 18 | +use Elementor\Modules\DynamicTags\Module as TagsModule; | |
| 19 | +use Elementor\Utils; | |
| 20 | +use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; | |
| 18 | 21 | |
| 19 | 22 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | - exit; // Exit if accessed directly. | |
| 23 | + exit; // Exit if accessed directly | |
| 21 | 24 | } |
| 22 | 25 | |
| 23 | 26 | class NestedTabs extends Widget_Nested_Base { |
| 24 | 27 | |
| 25 | - private $tab_item_settings = []; | |
| 26 | - private $optimized_markup = null; | |
| 27 | - private $widget_container_selector = ''; | |
| 28 | - | |
| 29 | 28 | public function get_name() { |
| 30 | 29 | return 'nested-tabs'; |
| 31 | 30 | } |
| 32 | 31 | |
| @@ -41,29 +40,13 @@ | ||
| 41 | 40 | public function get_keywords() { |
| 42 | 41 | return [ 'nested', 'tabs', 'accordion', 'toggle' ]; |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | - public function get_style_depends(): array { | |
| 46 | - return [ 'widget-nested-tabs' ]; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public function has_widget_inner_wrapper(): bool { | |
| 50 | - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); | |
| 51 | - } | |
| 52 | - | |
| 53 | - public function show_in_panel(): bool { | |
| 54 | - return Plugin::$instance->experiments->is_feature_active( 'nested-elements', true ); | |
| 55 | - } | |
| 56 | - | |
| 57 | 44 | protected function tab_content_container( int $index ) { |
| 58 | 45 | return [ |
| 59 | 46 | 'elType' => 'container', |
| 60 | 47 | 'settings' => [ |
| 61 | - '_title' => sprintf( | |
| 62 | - /* translators: %d: Tab index. */ | |
| 63 | - __( 'Tab #%d', 'elementor' ), | |
| 64 | - $index | |
| 65 | - ), | |
| 48 | + '_title' => sprintf( __( 'Tab #%s', 'elementor' ), $index ), | |
| 66 | 49 | 'content_width' => 'full', |
| 67 | 50 | ], |
| 68 | 51 | ]; |
| 69 | 52 | } |
| @@ -80,9 +63,8 @@ | ||
| 80 | 63 | return 'tab_title'; |
| 81 | 64 | } |
| 82 | 65 | |
| 83 | 66 | protected function get_default_children_title() { |
| 84 | - /* translators: %d: Tab index. */ | |
| 85 | 67 | return esc_html__( 'Tab #%d', 'elementor' ); |
| 86 | 68 | } |
| 87 | 69 | |
| 88 | 70 | protected function get_default_children_placeholder_selector() { |
| @@ -93,21 +75,18 @@ | ||
| 93 | 75 | return 'elementor-widget-n-tabs'; |
| 94 | 76 | } |
| 95 | 77 | |
| 96 | 78 | protected function register_controls() { |
| 97 | - if ( null === $this->optimized_markup ) { | |
| 98 | - $this->optimized_markup = Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ) && ! $this->has_widget_inner_wrapper(); | |
| 99 | - $this->widget_container_selector = $this->optimized_markup ? '' : ' > .elementor-widget-container'; | |
| 100 | - } | |
| 101 | - | |
| 102 | 79 | $start = is_rtl() ? 'right' : 'left'; |
| 103 | 80 | $end = is_rtl() ? 'left' : 'right'; |
| 104 | 81 | $start_logical = is_rtl() ? 'end' : 'start'; |
| 105 | 82 | $end_logical = is_rtl() ? 'start' : 'end'; |
| 106 | - $heading_selector_non_touch_device = "{{WRAPPER}}.elementor-widget-n-tabs{$this->widget_container_selector} > .e-n-tabs[data-touch-mode='false'] > .e-n-tabs-heading"; | |
| 107 | - $heading_selector_touch_device = "{{WRAPPER}}.elementor-widget-n-tabs{$this->widget_container_selector} > .e-n-tabs[data-touch-mode='true'] > .e-n-tabs-heading"; | |
| 108 | - $heading_selector = "{{WRAPPER}}.elementor-widget-n-tabs{$this->widget_container_selector} > .e-n-tabs > .e-n-tabs-heading"; | |
| 109 | - $content_selector = ":where( {{WRAPPER}}.elementor-widget-n-tabs{$this->widget_container_selector} > .e-n-tabs > .e-n-tabs-content ) > .e-con"; | |
| 83 | + $logical_dimensions_inline_start = is_rtl() ? '{{RIGHT}}{{UNIT}}' : '{{LEFT}}{{UNIT}}'; | |
| 84 | + $logical_dimensions_inline_end = is_rtl() ? '{{LEFT}}{{UNIT}}' : '{{RIGHT}}{{UNIT}}'; | |
| 85 | + $heading_selector_non_touch_device = '{{WRAPPER}} > .elementor-widget-container > .e-n-tabs[data-touch-mode="false"] > .e-n-tabs-heading'; | |
| 86 | + $heading_selector_touch_device = '{{WRAPPER}} > .elementor-widget-container > .e-n-tabs[data-touch-mode="true"] > .e-n-tabs-heading'; | |
| 87 | + $heading_selector = '{{WRAPPER}} > .elementor-widget-container > .e-n-tabs > .e-n-tabs-heading'; | |
| 88 | + $content_selector = ':where( {{WRAPPER}} > .elementor-widget-container > .e-n-tabs > .e-n-tabs-content ) > .e-con'; | |
| 110 | 89 | |
| 111 | 90 | $this->start_controls_section( 'section_tabs', [ |
| 112 | 91 | 'label' => esc_html__( 'Tabs', 'elementor' ), |
| 113 | 92 | ] ); |
| @@ -183,9 +162,9 @@ | ||
| 183 | 162 | 'tab_title' => esc_html__( 'Tab #3', 'elementor' ), |
| 184 | 163 | ], |
| 185 | 164 | ], |
| 186 | 165 | 'title_field' => '{{{ tab_title }}}', |
| 187 | - 'button_text' => esc_html__( 'Add Tab', 'elementor' ), | |
| 166 | + 'button_text' => 'Add Tab', | |
| 188 | 167 | ] ); |
| 189 | 168 | |
| 190 | 169 | $styling_block_start = '--n-tabs-direction: column; --n-tabs-heading-direction: row; --n-tabs-heading-width: initial; --n-tabs-title-flex-basis: content; --n-tabs-title-flex-shrink: 0;'; |
| 191 | 170 | $styling_block_end = '--n-tabs-direction: column-reverse; --n-tabs-heading-direction: row; --n-tabs-heading-width: initial; --n-tabs-title-flex-basis: content; --n-tabs-title-flex-shrink: 0'; |
| @@ -227,9 +206,8 @@ | ||
| 227 | 206 | ], |
| 228 | 207 | 'selectors' => [ |
| 229 | 208 | '{{WRAPPER}}' => '{{VALUE}}', |
| 230 | 209 | ], |
| 231 | - 'control_type' => 'content', | |
| 232 | 210 | ] ); |
| 233 | 211 | |
| 234 | 212 | $this->add_responsive_control( 'tabs_justify_horizontal', [ |
| 235 | 213 | 'label' => esc_html__( 'Justify', 'elementor' ), |
| @@ -504,9 +482,9 @@ | ||
| 504 | 482 | [ |
| 505 | 483 | 'name' => 'tabs_title_background_color', |
| 506 | 484 | 'types' => [ 'classic', 'gradient' ], |
| 507 | 485 | 'exclude' => [ 'image' ], |
| 508 | - 'selector' => "{{WRAPPER}}{$this->widget_container_selector} > .e-n-tabs > .e-n-tabs-heading > .e-n-tab-title[aria-selected='false']:not( :hover )", | |
| 486 | + 'selector' => '{{WRAPPER}} > .elementor-widget-container > .e-n-tabs > .e-n-tabs-heading > .e-n-tab-title[aria-selected="false"]:not( :hover )', | |
| 509 | 487 | 'fields_options' => [ |
| 510 | 488 | 'color' => [ |
| 511 | 489 | 'label' => esc_html__( 'Background Color', 'elementor' ), |
| 512 | 490 | 'selectors' => [ |
| @@ -536,8 +514,9 @@ | ||
| 536 | 514 | $this->add_group_control( |
| 537 | 515 | Group_Control_Box_Shadow::get_type(), |
| 538 | 516 | [ |
| 539 | 517 | 'name' => 'tabs_title_box_shadow', |
| 518 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 540 | 519 | 'separator' => 'after', |
| 541 | 520 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"false\"]:not( :hover )", |
| 542 | 521 | ] |
| 543 | 522 | ); |
| @@ -594,8 +573,9 @@ | ||
| 594 | 573 | $this->add_group_control( |
| 595 | 574 | Group_Control_Box_Shadow::get_type(), |
| 596 | 575 | [ |
| 597 | 576 | 'name' => 'tabs_title_box_shadow_hover', |
| 577 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 598 | 578 | 'separator' => 'after', |
| 599 | 579 | 'selector' => "{$heading_selector_non_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover", |
| 600 | 580 | ] |
| 601 | 581 | ); |
| @@ -678,8 +658,9 @@ | ||
| 678 | 658 | $this->add_group_control( |
| 679 | 659 | Group_Control_Box_Shadow::get_type(), |
| 680 | 660 | [ |
| 681 | 661 | 'name' => 'tabs_title_box_shadow_active', |
| 662 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 682 | 663 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"true\"], {$heading_selector_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover", |
| 683 | 664 | ] |
| 684 | 665 | ); |
| 685 | 666 | |
| @@ -706,9 +687,9 @@ | ||
| 706 | 687 | 'label' => esc_html__( 'Padding', 'elementor' ), |
| 707 | 688 | 'type' => Controls_Manager::DIMENSIONS, |
| 708 | 689 | 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ], |
| 709 | 690 | 'selectors' => [ |
| 710 | - '{{WRAPPER}}' => '--n-tabs-title-padding-top: {{TOP}}{{UNIT}}; --n-tabs-title-padding-right: {{RIGHT}}{{UNIT}}; --n-tabs-title-padding-bottom: {{BOTTOM}}{{UNIT}}; --n-tabs-title-padding-left: {{LEFT}}{{UNIT}};', | |
| 691 | + '{{WRAPPER}}' => "--n-tabs-title-padding-block-start: {{TOP}}{{UNIT}}; --n-tabs-title-padding-inline-end: $logical_dimensions_inline_end; --n-tabs-title-padding-block-end: {{BOTTOM}}{{UNIT}}; --n-tabs-title-padding-inline-start: $logical_dimensions_inline_start;", | |
| 711 | 692 | ], |
| 712 | 693 | ] |
| 713 | 694 | ); |
| 714 | 695 | |
| @@ -758,8 +739,13 @@ | ||
| 758 | 739 | Group_Control_Text_Shadow::get_type(), |
| 759 | 740 | [ |
| 760 | 741 | 'name' => 'title_text_shadow', |
| 761 | 742 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"false\"]:not( :hover )", |
| 743 | + 'fields_options' => [ | |
| 744 | + 'text_shadow_type' => [ | |
| 745 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 746 | + ], | |
| 747 | + ], | |
| 762 | 748 | ] |
| 763 | 749 | ); |
| 764 | 750 | |
| 765 | 751 | $this->add_group_control( |
| @@ -766,8 +752,13 @@ | ||
| 766 | 752 | Group_Control_Text_Stroke::get_type(), |
| 767 | 753 | [ |
| 768 | 754 | 'name' => 'title_text_stroke', |
| 769 | 755 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"false\"]:not( :hover ) :is( span, a, i )", |
| 756 | + 'fields_options' => [ | |
| 757 | + 'text_stroke_type' => [ | |
| 758 | + 'label' => esc_html__( 'Stroke', 'elementor' ), | |
| 759 | + ], | |
| 760 | + ], | |
| 770 | 761 | ] |
| 771 | 762 | ); |
| 772 | 763 | |
| 773 | 764 | $this->end_controls_tab(); |
| @@ -794,8 +785,14 @@ | ||
| 794 | 785 | Group_Control_Text_Shadow::get_type(), |
| 795 | 786 | [ |
| 796 | 787 | 'name' => 'title_text_shadow_hover', |
| 797 | 788 | 'selector' => "{$heading_selector_non_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover", |
| 789 | + 'fields_options' => [ | |
| 790 | + 'text_shadow_type' => [ | |
| 791 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 792 | + ], | |
| 793 | + ], | |
| 794 | + | |
| 798 | 795 | ] |
| 799 | 796 | ); |
| 800 | 797 | |
| 801 | 798 | $this->add_group_control( |
| @@ -802,8 +799,13 @@ | ||
| 802 | 799 | Group_Control_Text_Stroke::get_type(), |
| 803 | 800 | [ |
| 804 | 801 | 'name' => 'title_text_stroke_hover', |
| 805 | 802 | 'selector' => "{$heading_selector_non_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover :is( span, a, i )", |
| 803 | + 'fields_options' => [ | |
| 804 | + 'text_stroke_type' => [ | |
| 805 | + 'label' => esc_html__( 'Stroke', 'elementor' ), | |
| 806 | + ], | |
| 807 | + ], | |
| 806 | 808 | ] |
| 807 | 809 | ); |
| 808 | 810 | |
| 809 | 811 | $this->end_controls_tab(); |
| @@ -830,8 +832,13 @@ | ||
| 830 | 832 | Group_Control_Text_Shadow::get_type(), |
| 831 | 833 | [ |
| 832 | 834 | 'name' => 'title_text_shadow_active', |
| 833 | 835 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"true\"], {$heading_selector_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover", |
| 836 | + 'fields_options' => [ | |
| 837 | + 'text_shadow_type' => [ | |
| 838 | + 'label' => esc_html__( 'Shadow', 'elementor' ), | |
| 839 | + ], | |
| 840 | + ], | |
| 834 | 841 | ] |
| 835 | 842 | ); |
| 836 | 843 | |
| 837 | 844 | $this->add_group_control( |
| @@ -838,8 +845,13 @@ | ||
| 838 | 845 | Group_Control_Text_Stroke::get_type(), |
| 839 | 846 | [ |
| 840 | 847 | 'name' => 'title_text_stroke_active', |
| 841 | 848 | 'selector' => "{$heading_selector} > .e-n-tab-title[aria-selected=\"true\"] :is( span, a, i ), {$heading_selector_touch_device} > .e-n-tab-title[aria-selected=\"false\"]:hover :is( span, a, i )", |
| 849 | + 'fields_options' => [ | |
| 850 | + 'text_stroke_type' => [ | |
| 851 | + 'label' => esc_html__( 'Stroke', 'elementor' ), | |
| 852 | + ], | |
| 853 | + ], | |
| 842 | 854 | ] |
| 843 | 855 | ); |
| 844 | 856 | |
| 845 | 857 | $this->end_controls_tab(); |
| @@ -1056,9 +1068,9 @@ | ||
| 1056 | 1068 | 'label' => esc_html__( 'Padding', 'elementor' ), |
| 1057 | 1069 | 'type' => Controls_Manager::DIMENSIONS, |
| 1058 | 1070 | 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ], |
| 1059 | 1071 | 'selectors' => [ |
| 1060 | - $content_selector => '--padding-top: {{TOP}}{{UNIT}}; --padding-right: {{RIGHT}}{{UNIT}}; --padding-bottom: {{BOTTOM}}{{UNIT}}; --padding-left: {{LEFT}}{{UNIT}};', | |
| 1072 | + $content_selector => "--padding-block-start: {{TOP}}{{UNIT}}; --padding-inline-end: $logical_dimensions_inline_end; --padding-block-end: {{BOTTOM}}{{UNIT}}; --padding-inline-start: $logical_dimensions_inline_start;", | |
| 1061 | 1073 | ], |
| 1062 | 1074 | ] |
| 1063 | 1075 | ); |
| 1064 | 1076 | |
| @@ -1064,9 +1076,9 @@ | ||
| 1064 | 1076 | |
| 1065 | 1077 | $this->end_controls_section(); |
| 1066 | 1078 | } |
| 1067 | 1079 | |
| 1068 | - protected function render_tab_titles_html( $item_settings ): void { | |
| 1080 | + protected function render_tab_titles_html( $item_settings ): string { | |
| 1069 | 1081 | $setting_key = $this->get_repeater_setting_key( 'tab_title', 'tabs', $item_settings['index'] ); |
| 1070 | 1082 | $title = $item_settings['item']['tab_title']; |
| 1071 | 1083 | $css_classes = [ 'e-n-tab-title' ]; |
| 1072 | 1084 | |
| @@ -1075,9 +1087,8 @@ | ||
| 1075 | 1087 | } |
| 1076 | 1088 | |
| 1077 | 1089 | $this->add_render_attribute( $setting_key, [ |
| 1078 | 1090 | 'id' => $item_settings['tab_id'], |
| 1079 | - 'data-tab-title-id' => $item_settings['tab_title_id'], | |
| 1080 | 1091 | 'class' => $css_classes, |
| 1081 | 1092 | 'aria-selected' => 1 === $item_settings['tab_count'] ? 'true' : 'false', |
| 1082 | 1093 | 'data-tab-index' => $item_settings['tab_count'], |
| 1083 | 1094 | 'role' => 'tab', |
| @@ -1084,41 +1095,39 @@ | ||
| 1084 | 1095 | 'tabindex' => 1 === $item_settings['tab_count'] ? '0' : '-1', |
| 1085 | 1096 | 'aria-controls' => $item_settings['container_id'], |
| 1086 | 1097 | 'style' => '--n-tabs-title-order: ' . $item_settings['tab_count'] . ';', |
| 1087 | 1098 | ] ); |
| 1088 | - ?> | |
| 1089 | - <button <?php $this->print_render_attribute_string( $setting_key ); ?>> | |
| 1090 | - <?php $this->maybe_render_tab_icons_html( $item_settings ); ?> | |
| 1091 | - <span <?php $this->print_render_attribute_string( 'tab-title-text' ); ?>> | |
| 1092 | - <?php echo wp_kses_post( $title ); ?> | |
| 1093 | - </span> | |
| 1094 | - </button> | |
| 1095 | - <?php | |
| 1096 | - } | |
| 1097 | 1099 | |
| 1098 | - protected function maybe_render_tab_icons_html( $item_settings ): void { | |
| 1099 | - $icon_settings = $item_settings['item']['tab_icon']; | |
| 1100 | + $render_attributes = $this->get_render_attribute_string( $setting_key ); | |
| 1101 | + $text_class = $this->get_render_attribute_string( 'tab-title-text' ); | |
| 1102 | + $icon_class = $this->get_render_attribute_string( 'tab-icon' ); | |
| 1100 | 1103 | |
| 1101 | - if ( empty( $icon_settings['value'] ) ) { | |
| 1102 | - return; | |
| 1104 | + $icon_html = Icons_Manager::try_get_icon_html( $item_settings['item']['tab_icon'], [ 'aria-hidden' => 'true' ] ); | |
| 1105 | + $icon_active_html = $icon_html; | |
| 1106 | + | |
| 1107 | + if ( $this->is_active_icon_exist( $item_settings['item'] ) ) { | |
| 1108 | + $icon_active_html = Icons_Manager::try_get_icon_html( $item_settings['item']['tab_icon_active'], [ 'aria-hidden' => 'true' ] ); | |
| 1103 | 1109 | } |
| 1104 | 1110 | |
| 1105 | - $active_icon_settings = $this->is_active_icon_exist( $item_settings['item'] ) | |
| 1106 | - ? $item_settings['item']['tab_icon_active'] | |
| 1107 | - : $icon_settings; | |
| 1111 | + ob_start(); | |
| 1108 | 1112 | ?> |
| 1109 | - <span <?php $this->print_render_attribute_string( 'tab-icon' ); ?>> | |
| 1110 | - <?php Icons_Manager::render_icon( $icon_settings, [ 'aria-hidden' => 'true' ] ); ?> | |
| 1111 | - <?php Icons_Manager::render_icon( $active_icon_settings, [ 'aria-hidden' => 'true' ] ); ?> | |
| 1112 | - </span> | |
| 1113 | + <button <?php echo $render_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 1114 | + <span <?php echo $icon_class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 1115 | + <?php echo $icon_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 1116 | + <?php echo $icon_active_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 1117 | + </span> | |
| 1118 | + <span <?php echo $text_class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 1119 | + <?php echo wp_kses_post( $title ); ?> | |
| 1120 | + </span> | |
| 1121 | + </button> | |
| 1113 | 1122 | <?php |
| 1123 | + return ob_get_clean(); | |
| 1114 | 1124 | } |
| 1115 | 1125 | |
| 1116 | - protected function render_tab_containers_html( $settings ): void { | |
| 1117 | - foreach ( $settings['tabs'] as $index => $item ) { | |
| 1118 | - $item_settings = $this->tab_item_settings[ $index ]; | |
| 1119 | - $this->print_child( $item_settings['index'], $item_settings ); | |
| 1120 | - } | |
| 1126 | + protected function render_tab_containers_html( $item_settings ): string { | |
| 1127 | + ob_start(); | |
| 1128 | + $this->print_child( $item_settings['index'], $item_settings ); | |
| 1129 | + return ob_get_clean(); | |
| 1121 | 1130 | } |
| 1122 | 1131 | |
| 1123 | 1132 | |
| 1124 | 1133 | /** |
| @@ -1123,9 +1132,9 @@ | ||
| 1123 | 1132 | |
| 1124 | 1133 | /** |
| 1125 | 1134 | * Print the content area. |
| 1126 | 1135 | * |
| 1127 | - * @param int $index | |
| 1136 | + * @param int $index | |
| 1128 | 1137 | * @param array $item_settings |
| 1129 | 1138 | */ |
| 1130 | 1139 | public function print_child( $index, $item_settings = [] ) { |
| 1131 | 1140 | $children = $this->get_children(); |
| @@ -1144,11 +1153,9 @@ | ||
| 1144 | 1153 | return $should_render; |
| 1145 | 1154 | }; |
| 1146 | 1155 | |
| 1147 | 1156 | add_filter( 'elementor/frontend/container/should_render', $add_attribute_to_container, 10, 3 ); |
| 1148 | - if ( isset( $children[ $index ] ) ) { | |
| 1149 | - $children[ $index ]->print_element(); | |
| 1150 | - } | |
| 1157 | + $children[ $index ]->print_element(); | |
| 1151 | 1158 | remove_filter( 'elementor/frontend/container/should_render', $add_attribute_to_container ); |
| 1152 | 1159 | } |
| 1153 | 1160 | |
| 1154 | 1161 | protected function add_attributes_to_container( $container, $item_settings ) { |
| @@ -1163,9 +1170,9 @@ | ||
| 1163 | 1170 | } |
| 1164 | 1171 | |
| 1165 | 1172 | protected function render() { |
| 1166 | 1173 | $settings = $this->get_settings_for_display(); |
| 1167 | - $widget_number = $this->get_id_int(); | |
| 1174 | + $widget_number = substr( $this->get_id_int(), 0, 3 ); | |
| 1168 | 1175 | |
| 1169 | 1176 | if ( ! empty( $settings['link'] ) ) { |
| 1170 | 1177 | $this->add_link_attributes( 'elementor-tabs', $settings['link'] ); |
| 1171 | 1178 | } |
| @@ -1178,147 +1185,106 @@ | ||
| 1178 | 1185 | |
| 1179 | 1186 | $this->add_render_attribute( 'tab-title-text', 'class', 'e-n-tab-title-text' ); |
| 1180 | 1187 | $this->add_render_attribute( 'tab-icon', 'class', 'e-n-tab-icon' ); |
| 1181 | 1188 | $this->add_render_attribute( 'tab-icon-active', 'class', [ 'e-n-tab-icon' ] ); |
| 1189 | + | |
| 1190 | + $tab_titles_html = ''; | |
| 1191 | + $tab_containers_html = ''; | |
| 1192 | + | |
| 1193 | + foreach ( $settings['tabs'] as $index => $item ) { | |
| 1194 | + $tab_count = $index + 1; | |
| 1195 | + | |
| 1196 | + $tab_id = empty( $item['element_id'] ) | |
| 1197 | + ? 'e-n-tabs-title-' . $widget_number . $tab_count | |
| 1198 | + : $item['element_id']; | |
| 1199 | + | |
| 1200 | + $item_settings = [ | |
| 1201 | + 'index' => $index, | |
| 1202 | + 'tab_count' => $tab_count, | |
| 1203 | + 'tab_id' => $tab_id, | |
| 1204 | + 'container_id' => 'e-n-tab-content-' . $widget_number . $tab_count, | |
| 1205 | + 'widget_number' => $widget_number, | |
| 1206 | + 'item' => $item, | |
| 1207 | + 'settings' => $settings, | |
| 1208 | + ]; | |
| 1209 | + | |
| 1210 | + $tab_titles_html .= $this->render_tab_titles_html( $item_settings ); | |
| 1211 | + $tab_containers_html .= $this->render_tab_containers_html( $item_settings ); | |
| 1212 | + } | |
| 1182 | 1213 | ?> |
| 1183 | 1214 | <div <?php $this->print_render_attribute_string( 'elementor-tabs' ); ?>> |
| 1184 | 1215 | <div class="e-n-tabs-heading" role="tablist"> |
| 1185 | - <?php | |
| 1186 | - foreach ( $settings['tabs'] as $index => $item ) { | |
| 1187 | - $tab_count = $index + 1; | |
| 1188 | - $tab_title_id = 'e-n-tab-title-' . $widget_number . $tab_count; | |
| 1189 | - $tab_id = empty( $item['element_id'] ) | |
| 1190 | - ? $tab_title_id | |
| 1191 | - : $item['element_id']; | |
| 1192 | - | |
| 1193 | - $item_settings = [ | |
| 1194 | - 'index' => $index, | |
| 1195 | - 'tab_count' => $tab_count, | |
| 1196 | - 'tab_id' => $tab_id, | |
| 1197 | - 'tab_title_id' => $tab_title_id, | |
| 1198 | - 'container_id' => 'e-n-tab-content-' . $widget_number . $tab_count, | |
| 1199 | - 'widget_number' => $widget_number, | |
| 1200 | - 'item' => $item, | |
| 1201 | - 'settings' => $settings, | |
| 1202 | - ]; | |
| 1203 | - | |
| 1204 | - $this->tab_item_settings[] = $item_settings; | |
| 1205 | - | |
| 1206 | - $this->render_tab_titles_html( $item_settings ); | |
| 1207 | - } | |
| 1208 | - ?> | |
| 1216 | + <?php echo $tab_titles_html;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 1209 | 1217 | </div> |
| 1210 | 1218 | <div class="e-n-tabs-content"> |
| 1211 | - <?php $this->render_tab_containers_html( $settings ); ?> | |
| 1219 | + <?php echo $tab_containers_html;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 1212 | 1220 | </div> |
| 1213 | 1221 | </div> |
| 1214 | 1222 | <?php |
| 1215 | 1223 | } |
| 1216 | 1224 | |
| 1217 | - protected function get_initial_config(): array { | |
| 1218 | - return array_merge( parent::get_initial_config(), [ | |
| 1219 | - 'support_improved_repeaters' => true, | |
| 1220 | - 'target_container' => [ '.e-n-tabs-heading' ], | |
| 1221 | - 'node' => 'button', | |
| 1222 | - ] ); | |
| 1223 | - } | |
| 1224 | - | |
| 1225 | - protected function content_template_single_repeater_item() { | |
| 1226 | - ?> | |
| 1227 | - <# | |
| 1228 | - const tabIndex = view.collection.length, | |
| 1229 | - elementUid = view.getIDInt().toString(), | |
| 1230 | - item = data, | |
| 1231 | - hoverAnimationSetting = view?.container?.settings?.attributes?.hover_animation; | |
| 1232 | - hoverAnimationClass = hoverAnimationSetting | |
| 1233 | - ? `elementor-animation-${ hoverAnimationSetting }` | |
| 1234 | - : ''; | |
| 1235 | - #> | |
| 1236 | - <?php $this->content_template_single_item( '{{ tabIndex }}', '{{ item }}', '{{ elementUid }}', '{{ hoverAnimationClass }}' ); | |
| 1237 | - } | |
| 1238 | - | |
| 1239 | 1225 | protected function content_template() { |
| 1240 | 1226 | ?> |
| 1241 | - <# const elementUid = view.getIDInt().toString(); #> | |
| 1227 | + <# const elementUid = view.getIDInt().toString().substr( 0, 3 ); #> | |
| 1242 | 1228 | <div class="e-n-tabs" data-widget-number="{{ elementUid }}" aria-label="<?php echo esc_html__( 'Tabs. Open items with Enter or Space, close with Escape and navigate using the Arrow keys.', 'elementor' ); ?>"> |
| 1243 | 1229 | <# if ( settings['tabs'] ) { #> |
| 1244 | 1230 | <div class="e-n-tabs-heading" role="tablist"> |
| 1245 | 1231 | <# _.each( settings['tabs'], function( item, index ) { |
| 1246 | - const tabIndex = index, | |
| 1247 | - hoverAnimationSetting = settings['hover_animation'], | |
| 1248 | - hoverAnimationClass = hoverAnimationSetting | |
| 1249 | - ? `elementor-animation-${ hoverAnimationSetting }` | |
| 1250 | - : ''; | |
| 1232 | + const tabCount = index + 1, | |
| 1233 | + tabUid = elementUid + tabCount, | |
| 1234 | + tabWrapperKey = tabUid, | |
| 1235 | + tabTitleKey = 'tab-title-' + tabUid, | |
| 1236 | + tabIconKey = 'tab-icon-' + tabUid, | |
| 1237 | + tabIcon = elementor.helpers.renderIcon( view, item.tab_icon, { 'aria-hidden': true }, 'i' , 'object' ), | |
| 1238 | + hoverAnimationClass = settings['hover_animation'] ? `elementor-animation-${ settings['hover_animation'] }` : ''; | |
| 1239 | + | |
| 1240 | + let tabActiveIcon = tabIcon, | |
| 1241 | + tabId = 'e-n-tab-title-' + tabUid; | |
| 1242 | + | |
| 1243 | + if ( '' !== item.tab_icon_active.value ) { | |
| 1244 | + tabActiveIcon = elementor.helpers.renderIcon( view, item.tab_icon_active, { 'aria-hidden': true }, 'i' , 'object' ); | |
| 1245 | + } | |
| 1246 | + | |
| 1247 | + if ( '' !== item.element_id ) { | |
| 1248 | + tabId = item.element_id; | |
| 1249 | + } | |
| 1250 | + | |
| 1251 | + view.addRenderAttribute( tabWrapperKey, { | |
| 1252 | + 'id': tabId, | |
| 1253 | + 'class': [ 'e-n-tab-title',hoverAnimationClass ], | |
| 1254 | + 'data-tab-index': tabCount, | |
| 1255 | + 'role': 'tab', | |
| 1256 | + 'aria-selected': 1 === tabCount ? 'true' : 'false', | |
| 1257 | + 'tabindex': 1 === tabCount ? '0' : '-1', | |
| 1258 | + 'aria-controls': 'e-n-tab-content-' + tabUid, | |
| 1259 | + 'style': '--n-tabs-title-order: ' + tabCount + ';', | |
| 1260 | + } ); | |
| 1261 | + | |
| 1262 | + view.addRenderAttribute( tabTitleKey, { | |
| 1263 | + 'class': [ 'e-n-tab-title-text' ], | |
| 1264 | + 'data-binding-type': 'repeater-item', | |
| 1265 | + 'data-binding-repeater-name': 'tabs', | |
| 1266 | + 'data-binding-setting': [ 'tab_title' ], | |
| 1267 | + 'data-binding-index': tabCount, | |
| 1268 | + } ); | |
| 1269 | + | |
| 1270 | + view.addRenderAttribute( tabIconKey, { | |
| 1271 | + 'class': [ 'e-n-tab-icon' ], | |
| 1272 | + 'data-binding-type': 'repeater-item', | |
| 1273 | + 'data-binding-repeater-name': 'tabs', | |
| 1274 | + 'data-binding-setting': [ 'tab_icon.value', 'tab_icon_active.value' ], | |
| 1275 | + 'data-binding-index': tabCount, | |
| 1276 | + } ); | |
| 1251 | 1277 | #> |
| 1252 | - <?php $this->content_template_single_item( '{{ tabIndex }}', '{{ item }}', '{{ elementUid }}', '{{ hoverAnimationClass }}' ); ?> | |
| 1278 | + <button {{{ view.getRenderAttributeString( tabWrapperKey ) }}}> | |
| 1279 | + <span {{{ view.getRenderAttributeString( tabIconKey ) }}}>{{{ tabIcon.value }}}{{{ tabActiveIcon.value }}}</span> | |
| 1280 | + <span {{{ view.getRenderAttributeString( tabTitleKey ) }}}>{{{ item.tab_title }}}</span> | |
| 1281 | + </button> | |
| 1253 | 1282 | <# } ); #> |
| 1254 | 1283 | </div> |
| 1255 | 1284 | <div class="e-n-tabs-content"></div> |
| 1256 | 1285 | <# } #> |
| 1257 | 1286 | </div> |
| 1258 | - <?php | |
| 1259 | - } | |
| 1260 | - | |
| 1261 | - private function content_template_single_item( $tab_index, $item, $element_uid, $hover_animation_class ) { | |
| 1262 | - ?> | |
| 1263 | - <# | |
| 1264 | - const tabCount = tabIndex + 1, | |
| 1265 | - tabTitleId = 'e-n-tab-title-' + elementUid + tabCount, | |
| 1266 | - tabId = item.element_id | |
| 1267 | - ? item.element_id | |
| 1268 | - : tabTitleId, | |
| 1269 | - tabUid = elementUid + tabCount, | |
| 1270 | - tabIcon = elementor.helpers.renderIcon( view, item.tab_icon, { 'aria-hidden': true }, 'i' , 'object' ), | |
| 1271 | - activeTabIcon = item.tab_icon_active.value | |
| 1272 | - ? elementor.helpers.renderIcon( view, item.tab_icon_active, { 'aria-hidden': true }, 'i' , 'object' ) | |
| 1273 | - : tabIcon, | |
| 1274 | - escapedHoverAnimationClass = _.escape( hoverAnimationClass ); | |
| 1275 | - | |
| 1276 | - view.addRenderAttribute( 'tab-title', { | |
| 1277 | - 'id': tabId, | |
| 1278 | - 'data-tab-title-id': tabTitleId, | |
| 1279 | - 'class': [ 'e-n-tab-title',escapedHoverAnimationClass ], | |
| 1280 | - 'data-tab-index': tabCount, | |
| 1281 | - 'role': 'tab', | |
| 1282 | - 'aria-selected': 1 === tabCount ? 'true' : 'false', | |
| 1283 | - 'tabindex': 1 === tabCount ? '0' : '-1', | |
| 1284 | - 'aria-controls': 'e-n-tab-content-' + tabUid, | |
| 1285 | - 'style': '--n-tabs-title-order: ' + tabCount + ';', | |
| 1286 | - }, null, true ); | |
| 1287 | - | |
| 1288 | - view.addRenderAttribute( 'tab-title-text', { | |
| 1289 | - 'class': [ 'e-n-tab-title-text' ], | |
| 1290 | - 'data-binding-type': 'repeater-item', | |
| 1291 | - 'data-binding-repeater-name': 'tabs', | |
| 1292 | - 'data-binding-setting': [ 'tab_title', 'element_id' ], | |
| 1293 | - 'data-binding-index': tabCount, | |
| 1294 | - 'data-binding-config': JSON.stringify({ | |
| 1295 | - 'element_id': { | |
| 1296 | - attr: 'id', | |
| 1297 | - selector: 'button', | |
| 1298 | - editType: 'attribute', | |
| 1299 | - }, | |
| 1300 | - 'tab_title': { | |
| 1301 | - editType: 'text', | |
| 1302 | - }, | |
| 1303 | - }), | |
| 1304 | - }, null, true ); | |
| 1305 | - | |
| 1306 | - view.addRenderAttribute( 'tab-icon', { | |
| 1307 | - 'class': [ 'e-n-tab-icon' ], | |
| 1308 | - 'data-binding-type': 'repeater-item', | |
| 1309 | - 'data-binding-repeater-name': 'tabs', | |
| 1310 | - 'data-binding-index': tabCount, | |
| 1311 | - }, null, true ); | |
| 1312 | - #> | |
| 1313 | - | |
| 1314 | - <button {{{ view.getRenderAttributeString( 'tab-title' ) }}}> | |
| 1315 | - <# if ( !! item.tab_icon.value ) { #> | |
| 1316 | - <span {{{ view.getRenderAttributeString( 'tab-icon' ) }}}>{{{ tabIcon.value }}}{{{ activeTabIcon.value }}}</span> | |
| 1317 | - <# } #> | |
| 1318 | - | |
| 1319 | - <span {{{ view.getRenderAttributeString( 'tab-title-text' ) }}}>{{{ item.tab_title }}}</span> | |
| 1320 | - </button> | |
| 1321 | 1287 | <?php |
| 1322 | 1288 | } |
| 1323 | 1289 | |
| 1324 | 1290 | /** |