Edit: Tabs.php
<?php class DDBUILDER_Tabs_Module extends ET_Builder_Module { public $slug = 'dondivi_tabs'; public $vb_support = 'on'; public $icon_path; protected $module_credits = array( 'module_uri' => 'https://dondivi.com/tabs', 'author' => 'DonDivi', 'author_uri' => 'https://dondivi.com/', ); public function init() { $this->name = esc_html__( 'DonDivi Tabs', 'dd_builder' ); $this->child_slug = 'dondivi_tab'; $this->child_item_text = esc_html__( 'Tab', 'et_builder' ); $this->icon_path = plugin_dir_path( DDB_PLUGIN_PATH ) . 'builder/icon.svg'; $this->main_css_element = '%%order_class%%'; $this->settings_modal_toggles = array( 'general' => array( 'toggles' => array( 'main_content' => esc_html__( 'Tabs', 'et_builder' ), ), ), 'advanced' => array( 'toggles' => array( 'main_content' => esc_html__( 'Tabs', 'et_builder' ), 'tabs_text' => array( 'sub_toggles' => array( 'title' => array( 'name' => et_builder_i18n( 'Title' ), ), 'subtitle' => array( 'name' => et_builder_i18n( 'Subtitle' ), ), ), 'tabbed_subtoggles' => true, 'title' => sprintf( '%1$s %2$s', esc_html__( 'Tabs', 'et_builder' ), et_builder_i18n( 'Text' ) ), ), 'tabs_content' => esc_html__( 'Content', 'et_builder' ), 'effects' => sprintf( '%1$s %2$s', et_builder_i18n( 'Content' ), esc_html__( 'Animation', 'et_builder' ) ), ), ), ); $this->advanced_fields = array( 'borders' => array( 'default' => array(), 'tab' => array( 'css' => array( 'main' => array( 'border_radii' => '%%order_class%% .ddb-tab', 'border_styles' => '%%order_class%% .ddb-tab', 'border_radii_hover' => '%%order_class%% .ddb-tab:hover, %%order_class%% .ddb-tab.active', 'border_styles_hover' => '%%order_class%% .ddb-tab:hover, %%order_class%% .ddb-tab.active', ), ), 'label_prefix' => esc_html__( 'Tabs', 'et_builder' ), 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'content' => array( 'css' => array( 'main' => array( 'border_radii' => '%%order_class%% .ddb-tab-content > div', 'border_styles' => '%%order_class%% .ddb-tab-content > div', ), ), 'defaults' => array( 'border_styles' => array( 'width' => '1px', 'color' => '#d9d9d9', 'style' => 'solid', ), ), 'tab_slug' => 'advanced', 'toggle_slug' => 'tabs_content', ), ), 'box_shadow' => array( 'default' => array(), 'tab' => array ( 'label' => et_builder_i18n( 'Tabs' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab', ), ), 'content' => array ( 'label' => et_builder_i18n( 'Content' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab-content > div', ), ), ), 'fonts' => array( 'tab_title' => array( 'label' => et_builder_i18n( 'Title' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab-title', 'hover' => '%%order_class%% .ddb-tab:hover .ddb-tab-title, %%order_class%% .ddb-tab.active .ddb-tab-title', ), 'font_size' => array( 'default' => absint( et_get_option( 'body_font_size', '14' ) ) . 'px', ), 'line_height' => array( 'default' => floatval( et_get_option( 'body_font_height', '1.7' ) ) . 'em', ), 'hide_text_align' => true, 'toggle_slug' => 'tabs_text', 'sub_toggle' => 'title', ), 'subtitle' => array( 'label' => et_builder_i18n( 'Subtitle' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab-subtitle', 'hover' => '%%order_class%% .ddb-tab:hover .ddb-tab-subtitle, %%order_class%% .ddb-tab.active .ddb-tab-subtitle', ), 'font_size' => array( 'default' => absint( et_get_option( 'body_font_size', '14' ) ) . 'px', ), 'line_height' => array( 'default' => floatval( et_get_option( 'body_font_height', '1.7' ) ) . 'em', ), 'hide_text_align' => true, 'toggle_slug' => 'tabs_text', 'sub_toggle' => 'subtitle', ), ), 'image_icon' => array( 'image_icon' => array( 'label' => et_builder_i18n( 'Tabs' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab', ), 'margin_padding' => array( 'use_margin' => false, ), 'toggle_slug' => 'main_content', ), 'content' => array( 'label' => et_builder_i18n( 'Content' ), 'css' => array( 'main' => '%%order_class%% .ddb-tab-content > div', ), 'margin_padding' => array( 'custom_padding' => array( 'hover' => false, 'sticky' => false, ), 'use_margin' => false, ), 'toggle_slug' => 'tabs_content', ), ), 'text' => false, ); $this->custom_css_fields = array( 'tabs_container' => array( 'label' => esc_html__( 'Tabs Container', 'dd_builder' ), 'selector' => '%%order_class%% .ddb-tabs', ), 'tabs' => array( 'label' => esc_html__( 'Tabs', 'et_builder' ), 'selector' => '%%order_class%% .ddb-tab', ), 'active_tab' => array( 'label' => esc_html__( 'Active Tab', 'et_builder' ), 'selector' => '%%order_class%% .ddb-tab.active', ), ); } public function before_render() { global $ddbuilder_tabs, $ddbuilder_tab_active; $ddbuilder_tabs = array(); $ddbuilder_tab_active = 0; } public function get_fields() { $helper = new DonDiviBuilderFields(); $fields = array( 'tabs_position' => array( 'label' => esc_html__( 'Location', 'et_builder' ), 'type' => 'select', 'options' => array( 'column' => esc_html__('Top', 'et_builder'), 'row-reverse' => esc_html__('Right', 'et_builder'), 'column-reverse'=> esc_html__('Bottom', 'et_builder'), 'row' => esc_html__('Left', 'et_builder'), ), 'mobile_options' => true, 'default' => 'column', 'toggle_slug' => 'main_content', ), 'tabs_direction' => array( 'label' => esc_html__( 'Direction', 'dd_builder' ), 'type' => 'select', 'options' => array( 'row' => esc_html__('Row', 'et_builder'), 'column' => esc_html__('Column', 'et_builder'), ), 'mobile_options' => true, 'default' => 'row', 'toggle_slug' => 'main_content', ), 'tabs_background_color' => array( 'label' => esc_html__( 'Background Color', 'et_builder' ), 'type' => 'color-alpha', 'custom_color' => true, 'default' => '#f1f5f9', 'hover' => 'tabs', 'mobile_options' => true, 'sticky' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'tabs_active_background_color' => array( 'label' => esc_html__( 'Active Tab Background Color', 'et_builder' ), 'description' => esc_html__( 'Pick a color to be used for active tab backgrounds. You can assign a unique color to active tabs to differentiate them from inactive tabs.', 'et_builder' ), 'type' => 'color-alpha', 'custom_color' => true, 'default' => '#fff', 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', 'hover' => 'tabs', 'mobile_options' => true, 'sticky' => true, ), 'tabs_align' => array( 'label' => et_builder_i18n( 'Alignment' ), 'type' => 'text_align', 'options' => et_builder_get_text_orientation_options(), 'options_icon' => 'module_align', 'default' => 'left', 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'tabs_vertical_align' => array( 'label' => sprintf( '%1$s %2$s', esc_html__( 'Vertical', 'et_builder' ), et_builder_i18n( 'Alignment' ) ), 'type' => 'select', 'options' => array( 'flex-start' => et_builder_i18n( 'Top' ), 'center' => esc_html__( 'Middle', 'et_builder' ), 'flex-end' => esc_html__( 'Bottom', 'et_builder' ), 'space-between' => esc_html__( 'Space Between', 'et_builder' ), 'space-around' => esc_html__( 'Space Around', 'et_builder' ), ), 'default' => 'flex-start', 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'force_fullwidth' => array( 'label' => esc_html__( 'Force Fullwidth', 'et_builder' ), 'description' => esc_html__( "When enabled, this will force your tabs to extend 100% of the width of the container it's in.", 'dd_builder' ), 'type' => 'yes_no_button', 'options' => array( 'off' => et_builder_i18n( 'No' ), 'on' => et_builder_i18n( 'Yes' ), ), 'default' => 'off', 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'tabs_gap' => array( 'label' => sprintf( '%1$s %2$s', et_builder_i18n( 'Tabs' ), esc_html__('Gap', 'dd_builder') ), 'type' => 'range', 'fixed_unit' => 'px', 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', ), 'wrapper_gap' => array( 'label' => esc_html__( 'Offset', 'dd_builder' ), 'type' => 'range', 'fixed_unit' => 'px', 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'tabs_content', ), ); return array_merge($fields, $helper->get_effect_fields('effects', false, 'none', 'fade')); } public function get_transition_fields_css_props() { $fields = parent::get_transition_fields_css_props(); $fields['tabs_background_color'] = array( 'background-color' => '%%order_class%% .ddb-tab', ); return $fields; } public function render( $attrs, $content, $render_slug ) { wp_enqueue_script( 'ddb-tabs' ); $this->generate_styles( array( 'base_attr_name' => 'tabs_position', 'selector' => '%%order_class%% .ddb-tabs-wrapper', 'css_property' => 'flex-direction', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'wrapper_gap', 'selector' => '%%order_class%% .ddb-tabs-wrapper', 'css_property' => 'gap', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'tabs_direction', 'selector' => '%%order_class%% .ddb-tabs', 'css_property' => 'flex-direction', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'tabs_gap', 'selector' => '%%order_class%% .ddb-tabs', 'css_property' => 'gap', 'render_slug' => $render_slug, ) ); $helper = DonDiviBuilderHelper::get(); $dir = et_pb_responsive_options()-> get_property_values($this->props, 'tabs_direction', $this->props['tabs_direction'], true); $hali = et_pb_responsive_options()-> get_property_values($this->props, 'tabs_align', $this->props['tabs_align'], true); $vali = et_pb_responsive_options()-> get_property_values($this->props, 'tabs_vertical_align', $this->props['tabs_align'], true); foreach ( et_pb_responsive_options()->get_modes() as $device ) { $helper->set_style( $render_slug, '%%order_class%% .ddb-tabs', sprintf( 'justify-content: %1$s;', $helper->get_flex_alignment('justify', $dir[$device], $hali[$device], $vali[$device] ) ), substr($device, 0, 1) ); } $this->generate_styles( array( 'base_attr_name' => 'tabs_background_color', 'selector' => '%%order_class%% .ddb-tab', 'hover_selector' => '%%order_class%% .ddb-tab:hover', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', 'hover' => true, ) ); $this->generate_styles( array( 'base_attr_name' => 'tabs_active_background_color', 'selector' => '%%order_class%% .ddb-tab.active', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); $tabs_attrs = array( 'class' => 'ddb-tabs ddb-f'); $helper->set_effect_attrs( $tabs_attrs, $this->props ); $multi_view = et_pb_multi_view_options( $this ); $tabs = $multi_view->render_element( array( 'tag' => 'div', 'content' => $this->get_all_tabs(), 'attrs' => $tabs_attrs, 'classes' => array( 'ddb-column' => array( 'tabs_position' => array( 'row', 'row-reverse' ) ), 'ddb-fw' => array( 'force_fullwidth' => 'on' ), ), ) ); return sprintf( '<div class="ddb-tabs-wrapper ddb-f">%2$s<div class="ddb-tab-content ddb-f">%1$s</div></div>', $this->props['content'], $tabs ); } private function get_all_tabs() { global $ddbuilder_tabs, $ddbuilder_tab_active; $tabs = ''; for( $i = 0; $i < count($ddbuilder_tabs); $i++) { if ( $i === $ddbuilder_tab_active ) { DonDiviBuilderHelper::get()->set_style( $this->slug, sprintf('%%order_class%% .ddb-tab-content > div:not(:nth-child(%s))', $i + 1), 'display:none' ); $ddbuilder_tabs[$i] = str_replace('class="ddb-tab ', 'class="ddb-tab active ', $ddbuilder_tabs[$i] ); } $tabs .= $ddbuilder_tabs[$i]; } return $tabs; } } new DDBUILDER_Tabs_Module;
Save
Back