| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- <?php
- namespace Elementor;
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Elementor toggle widget.
- *
- * Elementor widget that displays a collapsible display of content in an toggle
- * style, allowing the user to open multiple items.
- *
- * @since 1.0.0
- */
- class Widget_Toggle extends Widget_Base {
- /**
- * Get widget name.
- *
- * Retrieve toggle widget name.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget name.
- */
- public function get_name() {
- return 'toggle';
- }
- /**
- * Get widget title.
- *
- * Retrieve toggle widget title.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget title.
- */
- public function get_title() {
- return __( 'Toggle', 'elementor' );
- }
- /**
- * Get widget icon.
- *
- * Retrieve toggle widget icon.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget icon.
- */
- public function get_icon() {
- return 'eicon-toggle';
- }
- /**
- * Get widget keywords.
- *
- * Retrieve the list of keywords the widget belongs to.
- *
- * @since 2.1.0
- * @access public
- *
- * @return array Widget keywords.
- */
- public function get_keywords() {
- return [ 'tabs', 'accordion', 'toggle' ];
- }
- /**
- * Register toggle widget controls.
- *
- * Adds different input fields to allow the user to change and customize the widget settings.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _register_controls() {
- $this->start_controls_section(
- 'section_toggle',
- [
- 'label' => __( 'Toggle', 'elementor' ),
- ]
- );
- $repeater = new Repeater();
- $repeater->add_control(
- 'tab_title',
- [
- 'label' => __( 'Title & Content', 'elementor' ),
- 'type' => Controls_Manager::TEXT,
- 'default' => __( 'Toggle Title', 'elementor' ),
- 'label_block' => true,
- ]
- );
- $repeater->add_control(
- 'tab_content',
- [
- 'label' => __( 'Content', 'elementor' ),
- 'type' => Controls_Manager::WYSIWYG,
- 'default' => __( 'Toggle Content', 'elementor' ),
- 'show_label' => false,
- ]
- );
- $this->add_control(
- 'tabs',
- [
- 'label' => __( 'Toggle Items', 'elementor' ),
- 'type' => Controls_Manager::REPEATER,
- 'fields' => $repeater->get_controls(),
- 'default' => [
- [
- 'tab_title' => __( 'Toggle #1', 'elementor' ),
- 'tab_content' => __( 'Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
- ],
- [
- 'tab_title' => __( 'Toggle #2', 'elementor' ),
- 'tab_content' => __( 'Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
- ],
- ],
- 'title_field' => '{{{ tab_title }}}',
- ]
- );
- $this->add_control(
- 'view',
- [
- 'label' => __( 'View', 'elementor' ),
- 'type' => Controls_Manager::HIDDEN,
- 'default' => 'traditional',
- ]
- );
- $this->add_control(
- 'icon',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'type' => Controls_Manager::ICON,
- 'default' => is_rtl() ? 'fa fa-caret-left' : 'fa fa-caret-right',
- 'separator' => 'before',
- ]
- );
- $this->add_control(
- 'icon_active',
- [
- 'label' => __( 'Active Icon', 'elementor' ),
- 'type' => Controls_Manager::ICON,
- 'default' => 'fa fa-caret-up',
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'title_html_tag',
- [
- 'label' => __( 'Title HTML Tag', 'elementor' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => [
- 'h1' => 'H1',
- 'h2' => 'H2',
- 'h3' => 'H3',
- 'h4' => 'H4',
- 'h5' => 'H5',
- 'h6' => 'H6',
- 'div' => 'div',
- ],
- 'default' => 'div',
- 'separator' => 'before',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_toggle_style',
- [
- 'label' => __( 'Toggle', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_control(
- 'border_width',
- [
- 'label' => __( 'Border Width', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 10,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title' => 'border-width: {{SIZE}}{{UNIT}};',
- '{{WRAPPER}} .elementor-toggle .elementor-tab-content' => 'border-width: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_control(
- 'border_color',
- [
- 'label' => __( 'Border Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-content' => 'border-bottom-color: {{VALUE}};',
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title' => 'border-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_responsive_control(
- 'space_between',
- [
- 'label' => __( 'Space Between', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 100,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-toggle-item:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}}',
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Box_Shadow::get_type(),
- [
- 'name' => 'box_shadow',
- 'selector' => '{{WRAPPER}} .elementor-toggle .elementor-toggle-item',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_toggle_style_title',
- [
- 'label' => __( 'Title', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_control(
- 'title_background',
- [
- 'label' => __( 'Background', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title' => 'background-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'title_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title' => 'color: {{VALUE}};',
- ],
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_1,
- ],
- ]
- );
- $this->add_control(
- 'tab_active_color',
- [
- 'label' => __( 'Active Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title.elementor-active' => 'color: {{VALUE}};',
- ],
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_4,
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Typography::get_type(),
- [
- 'name' => 'title_typography',
- 'selector' => '{{WRAPPER}} .elementor-toggle .elementor-tab-title',
- 'scheme' => Scheme_Typography::TYPOGRAPHY_1,
- ]
- );
- $this->add_responsive_control(
- 'title_padding',
- [
- 'label' => __( 'Padding', 'elementor' ),
- 'type' => Controls_Manager::DIMENSIONS,
- 'size_units' => [ 'px', 'em', '%' ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
- ],
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_toggle_style_icon',
- [
- 'label' => __( 'Icon', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'icon_align',
- [
- 'label' => __( 'Alignment', 'elementor' ),
- 'type' => Controls_Manager::CHOOSE,
- 'options' => [
- 'left' => [
- 'title' => __( 'Start', 'elementor' ),
- 'icon' => 'eicon-h-align-left',
- ],
- 'right' => [
- 'title' => __( 'End', 'elementor' ),
- 'icon' => 'eicon-h-align-right',
- ],
- ],
- 'default' => is_rtl() ? 'right' : 'left',
- 'toggle' => false,
- 'label_block' => false,
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'icon_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title .elementor-toggle-icon .fa:before' => 'color: {{VALUE}};',
- ],
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_control(
- 'icon_active_color',
- [
- 'label' => __( 'Active Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-title.elementor-active .elementor-toggle-icon .fa:before' => 'color: {{VALUE}};',
- ],
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->add_responsive_control(
- 'icon_space',
- [
- 'label' => __( 'Spacing', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 0,
- 'max' => 100,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-toggle-icon.elementor-toggle-icon-left' => 'margin-right: {{SIZE}}{{UNIT}};',
- '{{WRAPPER}} .elementor-toggle .elementor-toggle-icon.elementor-toggle-icon-right' => 'margin-left: {{SIZE}}{{UNIT}};',
- ],
- 'condition' => [
- 'icon!' => '',
- ],
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_toggle_style_content',
- [
- 'label' => __( 'Content', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->add_control(
- 'content_background_color',
- [
- 'label' => __( 'Background', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-content' => 'background-color: {{VALUE}};',
- ],
- ]
- );
- $this->add_control(
- 'content_color',
- [
- 'label' => __( 'Color', 'elementor' ),
- 'type' => Controls_Manager::COLOR,
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-content' => 'color: {{VALUE}};',
- ],
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_3,
- ],
- ]
- );
- $this->add_group_control(
- Group_Control_Typography::get_type(),
- [
- 'name' => 'content_typography',
- 'selector' => '{{WRAPPER}} .elementor-toggle .elementor-tab-content',
- 'scheme' => Scheme_Typography::TYPOGRAPHY_3,
- ]
- );
- $this->add_responsive_control(
- 'content_padding',
- [
- 'label' => __( 'Padding', 'elementor' ),
- 'type' => Controls_Manager::DIMENSIONS,
- 'size_units' => [ 'px', 'em', '%' ],
- 'selectors' => [
- '{{WRAPPER}} .elementor-toggle .elementor-tab-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
- ],
- ]
- );
- $this->end_controls_section();
- }
- /**
- * Render toggle widget output on the frontend.
- *
- * Written in PHP and used to generate the final HTML.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function render() {
- $settings = $this->get_settings_for_display();
- $id_int = substr( $this->get_id_int(), 0, 3 );
- ?>
- <div class="elementor-toggle" role="tablist">
- <?php
- foreach ( $settings['tabs'] as $index => $item ) :
- $tab_count = $index + 1;
- $tab_title_setting_key = $this->get_repeater_setting_key( 'tab_title', 'tabs', $index );
- $tab_content_setting_key = $this->get_repeater_setting_key( 'tab_content', 'tabs', $index );
- $this->add_render_attribute( $tab_title_setting_key, [
- 'id' => 'elementor-tab-title-' . $id_int . $tab_count,
- 'class' => [ 'elementor-tab-title' ],
- 'tabindex' => $id_int . $tab_count,
- 'data-tab' => $tab_count,
- 'role' => 'tab',
- 'aria-controls' => 'elementor-tab-content-' . $id_int . $tab_count,
- ] );
- $this->add_render_attribute( $tab_content_setting_key, [
- 'id' => 'elementor-tab-content-' . $id_int . $tab_count,
- 'class' => [ 'elementor-tab-content', 'elementor-clearfix' ],
- 'data-tab' => $tab_count,
- 'role' => 'tabpanel',
- 'aria-labelledby' => 'elementor-tab-title-' . $id_int . $tab_count,
- ] );
- $this->add_inline_editing_attributes( $tab_content_setting_key, 'advanced' );
- ?>
- <div class="elementor-toggle-item">
- <<?php echo esc_html( $settings['title_html_tag'] ); ?> <?php echo $this->get_render_attribute_string( $tab_title_setting_key ); ?>>
- <?php if ( $settings['icon'] ) : ?>
- <span class="elementor-toggle-icon elementor-toggle-icon-<?php echo esc_attr( $settings['icon_align'] ); ?>" aria-hidden="true">
- <i class="elementor-toggle-icon-closed <?php echo esc_attr( $settings['icon'] ); ?>"></i>
- <i class="elementor-toggle-icon-opened <?php echo esc_attr( $settings['icon_active'] ); ?>"></i>
- </span>
- <?php endif; ?>
- <?php echo $item['tab_title']; ?>
- </<?php echo esc_html( $settings['title_html_tag'] ); ?>>
- <div <?php echo $this->get_render_attribute_string( $tab_content_setting_key ); ?>><?php echo $this->parse_text_editor( $item['tab_content'] ); ?></div>
- </div>
- <?php endforeach; ?>
- </div>
- <?php
- }
- /**
- * Render toggle widget output in the editor.
- *
- * Written as a Backbone JavaScript template and used to generate the live preview.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _content_template() {
- ?>
- <div class="elementor-toggle" role="tablist">
- <#
- if ( settings.tabs ) {
- var tabindex = view.getIDInt().toString().substr( 0, 3 );
- _.each( settings.tabs, function( item, index ) {
- var tabCount = index + 1,
- tabTitleKey = view.getRepeaterSettingKey( 'tab_title', 'tabs', index ),
- tabContentKey = view.getRepeaterSettingKey( 'tab_content', 'tabs', index );
- view.addRenderAttribute( tabTitleKey, {
- 'id': 'elementor-tab-title-' + tabindex + tabCount,
- 'class': [ 'elementor-tab-title' ],
- 'tabindex': tabindex + tabCount,
- 'data-tab': tabCount,
- 'role': 'tab',
- 'aria-controls': 'elementor-tab-content-' + tabindex + tabCount
- } );
- view.addRenderAttribute( tabContentKey, {
- 'id': 'elementor-tab-content-' + tabindex + tabCount,
- 'class': [ 'elementor-tab-content', 'elementor-clearfix' ],
- 'data-tab': tabCount,
- 'role': 'tabpanel',
- 'aria-labelledby': 'elementor-tab-title-' + tabindex + tabCount
- } );
- view.addInlineEditingAttributes( tabContentKey, 'advanced' );
- #>
- <div class="elementor-toggle-item">
- <{{{ settings.title_html_tag }}} {{{ view.getRenderAttributeString( tabTitleKey ) }}}>
- <# if ( settings.icon ) { #>
- <span class="elementor-toggle-icon elementor-toggle-icon-{{ settings.icon_align }}" aria-hidden="true">
- <i class="elementor-toggle-icon-closed {{ settings.icon }}"></i>
- <i class="elementor-toggle-icon-opened {{ settings.icon_active }}"></i>
- </span>
- <# } #>
- {{{ item.tab_title }}}
- </{{{ settings.title_html_tag }}}>
- <div {{{ view.getRenderAttributeString( tabContentKey ) }}}>{{{ item.tab_content }}}</div>
- </div>
- <#
- } );
- } #>
- </div>
- <?php
- }
- }
|