'https://dondivi.com/timeline', 'author' => 'DonDivi', 'author_uri' => 'https://dondivi.com/', ); public function init() { $this->name = esc_html__( 'DonDivi Timeline', 'dd_builder' ); $this->child_slug = 'dondivi_timeline_item'; $this->child_item_text = esc_html__( 'Event', '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__( 'Timeline', 'dd_builder' ), 'cards' => esc_html__( 'Cards', 'dd_builder' ), ), ), 'advanced' => array( 'toggles' => array( 'main_content' => esc_html__( 'Timeline', 'dd_builder' ), 'labels' => esc_html__( 'Labels', 'dd_builder' ), 'markers' => esc_html__( 'Markers', 'dd_builder' ), 'cards' => esc_html__( 'Cards', 'dd_builder' ), ), ), ); $this->advanced_fields = array( 'borders' => array( 'default' => array( 'css' => array( 'main' => array( 'border_radii' => '%%order_class%% .ddb-card-content', 'border_styles' => '%%order_class%% .ddb-card-content', ), ), 'label_prefix' => esc_html__( 'Card', 'dd_builder' ), 'toggle_slug' => 'cards', ), 'markers' => array( 'label_prefix' => esc_html__( 'Markers', 'dd_builder' ), 'css' => array( 'main' => array( 'border_radii' => '%%order_class%% .ddb-event-item', 'border_styles' => '%%order_class%% .ddb-event-item', ), ), 'defaults' => array( 'border_radii' => 'on|50%|50%|50%|50%', ), 'toggle_slug' => 'markers', ), ), 'box_shadow' => array( 'default' => array(), 'labels' => array ( 'label' => esc_html__( 'Labels', 'dd_builder' ), 'css' => array( 'main' => "{$this->main_css_element} .ddb-label-item" ), ), 'markers' => array ( 'label' => esc_html__( 'Markers', 'dd_builder' ), 'css' => array( 'main' => "{$this->main_css_element} .ddb-event-item" ), ), 'cards' => array ( 'label' => esc_html__( 'Cards', 'dd_builder' ), 'css' => array( 'main' => "{$this->main_css_element} .ddb-card-content" ), ), ), 'fonts' => array( 'label' => array( 'label' => esc_html__( 'Label', 'et_builder' ), 'css' => array( 'main' => '%%order_class%% .ddb-label-item', ), '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' => 'labels', ), ), 'image_icon' => array( 'image_icon' => array( 'label' => esc_html__( 'Card', 'dd_builder' ), 'css' => array( 'main' => '%%order_class%% .ddb-card-content', ), 'margin_padding' => array( 'use_margin' => false, ), 'toggle_slug' => 'cards', ), 'label' => array( 'label' => et_builder_i18n( 'Label' ), 'css' => array( 'main' => '%%order_class%% .ddb-label-item', ), 'toggle_slug' => 'labels', ), 'marker' => array( 'label' => esc_html__( 'Marker', 'dd_builder' ), 'css' => array( 'main' => '%%order_class%% .ddb-event-item', ), 'margin_padding' => array( 'use_margin' => false, ), 'toggle_slug' => 'markers', ), ), 'text' => false, ); $this->custom_css_fields = array( 'marker_scroll_css' => array( 'label' => esc_html__( 'Marker Scroll Active', 'dd_builder' ), 'selector' => '%%order_class%% .ddb-timeline .ddb-events .ddb-scroll-active .ddb-event-item', 'show_if' => array( 'line_scroll' => 'on'), ), 'marker_content_scroll_css' => array( 'label' => esc_html__( 'Marker Content Scroll Active', 'dd_builder' ), 'selector' => '%%order_class%% .ddb-events .ddb-scroll-active .ddb-event-item >*', 'show_if' => array( 'line_scroll' => 'on'), ), ); } public function get_fields() { $fields = array( 'line_scroll' => array( 'label' => esc_html__( 'Scroll Animation', 'dd_builder' ), 'type' => 'yes_no_button', 'options' => array( 'off' => et_builder_i18n( 'No' ), 'on' => et_builder_i18n( 'Yes' ), ), 'default' => 'off', 'mobile_options' => true, 'toggle_slug' => 'main_content', ), 'card_position' => array( 'label' => esc_html__( 'Card Location', 'dd_builder' ), 'type' => 'select', 'options' => array( 'alternate' => esc_html__('Alternate', 'dd_builder'), 'right' => esc_html__('Right', 'et_builder'), 'center' => esc_html__('Center', 'et_builder'), 'left' => esc_html__('Left', 'et_builder'), ), 'affects' => array('marker_offset', 'label_alignment'), 'mobile_options' => true, 'default' => 'alternate', 'toggle_slug' => 'cards', ), 'card_position_tablet' => array( 'type' => 'skip', 'affects'=> array('marker_offset', 'label_alignment'), ), 'card_position_phone' => array( 'type' => 'skip', 'affects'=> array('marker_offset', 'label_alignment'), ), 'label_background_color' => array( 'label' => esc_html__( 'Background Color', 'et_builder' ), 'type' => 'color-alpha', 'sticky' => true, 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'labels', ), 'label_alignment' => array( 'label' => esc_html__( 'Alignment', 'et_builder' ), 'type' => 'text_align', 'options' => et_builder_get_text_orientation_options( array( 'justified' ) ), 'options_icon' => 'module_align', 'depends_show_if_not' => array( 'alternate' ), 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'labels', ), 'card_arrows' => array( 'label' => esc_html__( 'Show Arrow', 'dd_builder' ), 'type' => 'yes_no_button', 'options' => array( 'off' => et_builder_i18n( 'No' ), 'on' => et_builder_i18n( 'Yes' ), ), 'default' => 'off', 'affects' => array( 'arrows_color', 'arrows_width' ), 'mobile_options' => true, 'toggle_slug' => 'cards', ), 'card_arrows_tablet' => array( 'type' => 'skip', 'affects' => array( 'arrows_color', 'arrows_width' ), ), 'card_arrows_phone' => array( 'type' => 'skip', 'affects' => array( 'arrows_color', 'arrows_width' ), ), 'line_scroll_color' => array( 'label' => esc_html__( 'Line Scroll Color', 'dd_builder' ), 'type' => 'color-alpha', 'default' => '#000', 'show_if' => array( 'line_scroll' => 'on'), 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', 'hover' => 'tabs', 'mobile_options' => true, 'sticky' => true, ), 'line_color' => array( 'label' => esc_html__( 'Line Color', 'dd_builder' ), 'type' => 'color-alpha', 'default' => et_builder_accent_color(), 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', 'hover' => 'tabs', 'mobile_options' => true, 'sticky' => true, ), 'line_width' => array( 'label' => esc_html__( 'Line Width', 'dd_builder' ), 'type' => 'range', 'default' => '3px', 'tab_slug' => 'advanced', 'toggle_slug' => 'main_content', 'mobile_options' => true, 'validate_unit' => true, 'allowed_units' => array( '%', 'em', 'rem', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ex', 'vh', 'vw' ), 'responsive' => true, 'mobile_options' => true, 'sticky' => true, ), 'marker_width' => array( 'label' => sprintf( '%1$s %2$s', esc_html__( 'Container', 'et_builder' ), esc_html__( 'Width', 'et_builder' ) ), // Container from CountdownTimer.php 'type' => 'range', 'range_settings' => array( 'min' => '50', 'max' => '200', 'step' => '1', ), 'default' => '100px', 'tab_slug' => 'advanced', 'toggle_slug' => 'markers', 'mobile_options' => true, 'validate_unit' => true, 'allowed_units' => array( '%', 'em', 'rem', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'ex', 'vh', 'vw' ), 'responsive' => true, 'mobile_options' => true, 'sticky' => true, ), 'marker_background_color' => array( 'label' => esc_html__( 'Background Color', 'et_builder' ), 'type' => 'color-alpha', 'tab_slug' => 'advanced', 'toggle_slug' => 'markers', 'hover' => 'tabs', 'mobile_options' => true, 'sticky' => true, ), 'marker_offset' => array( 'label' => esc_html__( 'Offset', 'dd_builder' ), 'type' => 'range', 'range_settings' => array( 'max' => 50, 'max_limit' => 50, 'step' => 1, ), 'default' => '0%', 'default_unit' => '%', 'depends_show_if_not' => array( 'center', 'alternate' ), 'mobile_options' => true, 'validate_unit' => true, 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'markers', ), 'card_background_color' => array( 'label' => esc_html__( 'Background Color', 'et_builder' ), 'type' => 'color-alpha', 'default' => '#f1f5f9', 'sticky' => true, 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'cards', ), 'card_width' => array( 'label' => esc_html__( 'Width', 'et_builder' ), 'type' => 'range', 'allowed_values' => et_builder_get_acceptable_css_string_values( 'width' ), 'default' => '100%', 'default_unit' => '%', 'mobile_options' => true, 'hover' => 'tabs', 'sticky' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'cards', ), 'arrows_color' => array( 'label' => esc_html__( 'Arrow Color', 'dd_builder' ), 'type' => 'color-alpha', 'default' => '#f1f5f9', 'depends_show_if_not' => 'off', 'sticky' => true, 'mobile_options' => true, 'tab_slug' => 'advanced', 'toggle_slug' => 'cards', ), 'arrows_width' => array( 'label' => sprintf('%1$s %2$s', esc_html__( 'Arrow', 'dd_builder' ), esc_html__( 'Width', 'et_builder' ) ), 'default' => '15px', 'type' => 'range', 'default_unit' => 'px', 'fixed_unit' => 'px', 'mobile_options' => true, 'sticky' => true, 'depends_show_if_not' => 'off', 'tab_slug' => 'advanced', 'toggle_slug' => 'cards' ), ); return $fields; } public function render( $attrs, $content, $render_slug ) { wp_enqueue_script( 'ddb-timeline' ); $devices = array( 'desktop', 'tablet', 'phone' ); $helper = DonDiviBuilderHelper::get(); $multi_view = et_pb_multi_view_options( $this ); $pos = et_pb_responsive_options()-> get_property_values($this->props, 'card_position', $this->props['card_position'], true); $offset = et_pb_responsive_options()-> get_property_values($this->props, 'marker_offset', $this->props['marker_offset'], true); $mile = et_pb_responsive_options()-> get_property_values($this->props, 'marker_width', $this->props['marker_width'], true); foreach ($devices as $device) { $card = $flex = $left = ''; if ( $pos[$device] === 'left' ) $left = sprintf( 'left:calc(100%% - %1$s - %2$dpx/2)', $offset[$device], $mile[$device] ); else if ( $pos[$device] === 'right' ) $left = sprintf( 'left:calc(%1$s + %2$dpx/2)', $offset[$device], $mile[$device] ); $helper->set_style( $render_slug, '%%order_class%% .ddb-timeline-bar', $left, substr($device, 0, 1) ); if ( $pos[$device] === 'left' || $pos[$device] === 'right' ) { $card = sprintf('flex-basis:calc(100%% - %s)', $offset[$device] ); $flex = sprintf('flex:1 0 %s', $offset[$device] ); } else $flex = 'flex: 1 1 50%'; $helper->set_style( $render_slug, '%%order_class%% .ddb-timeline-event > .ddb-event-label', $flex, substr($device, 0, 1) ); $helper->set_style( $render_slug, '%%order_class%% .ddb-card', $card, substr($device, 0, 1) ); } $this->generate_styles( array( 'base_attr_name' => 'label_background_color', 'selector' => '%%order_class%% .ddb-label-item', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); $this->generate_styles( array( 'base_attr_name' => 'label_alignment', 'selector' => '%%order_class%% .ddb-card .ddb-event-label', 'css_property' => 'text-align', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'line_color', 'selector' => '%%order_class%% .ddb-timeline-bar, %%order_class%% .ddb-event-item', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); $this->generate_styles( array( 'base_attr_name' => 'line_width', 'selector' => '%%order_class%% .ddb-timeline-bar', 'css_property' => 'width', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'marker_width', 'selector' => '%%order_class%% .ddb-event-line', 'css_property' => 'width', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'marker_background_color', 'selector' => '%%order_class%% .ddb-events .ddb-event-item', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); $this->generate_styles( array( 'base_attr_name' => 'card_background_color', 'selector' => '%%order_class%% .ddb-card-content', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); $this->generate_styles( array( 'base_attr_name' => 'card_width', 'selector' => '%%order_class%% .ddb-card-content', 'css_property' => 'width', 'render_slug' => $render_slug, ) ); if ( $multi_view->has_value( 'card_arrows', 'on' ) ) { foreach ($devices as $device) { $helper->set_style( $render_slug, '%%order_class%% .ddb-arrows .ddb-card:after', $this->set_card_arrow_css( $pos[$device]), substr($device, 0, 1) ); $helper->set_style( $render_slug, '%%order_class%% .ddb-events.alternate > div:nth-child(even) .ddb-card:after', $this->set_card_arrow_css( 'left' ), substr($device, 0, 1) ); } $this->generate_styles( array( 'base_attr_name' => 'arrows_color', 'selector' => '%%order_class%% .ddb-card:after', 'css_property' => '--ddb-arrow-color', 'render_slug' => $render_slug, ) ); $this->generate_styles( array( 'base_attr_name' => 'arrows_width', 'selector' => '%%order_class%% .ddb-card:after', 'css_property' => 'border-width', 'render_slug' => $render_slug, ) ); } $scroll = ''; if ( $multi_view->has_value( 'line_scroll', 'on' ) ) { $scroll = $multi_view->render_element( array( 'tag' => 'div', 'attrs' => array('class' => 'ddb-timeline-scroll'), 'visibility' => array( 'line_scroll' => 'on') ) ); $this->generate_styles( array( 'base_attr_name' => 'line_scroll_color', 'selector' => '%%order_class%% .ddb-timeline-scroll, %%order_class%% .ddb-events .ddb-scroll-active .ddb-event-item', 'css_property' => 'background-color', 'render_slug' => $render_slug, 'type' => 'color', ) ); } $cards = $multi_view->render_element( array( 'tag' => 'div', 'content' => '{{content}}', 'attrs' => array( 'class' => 'ddb-events' ), 'classes' => array( 'alternate' => array('card_position' => 'alternate' ), 'left' => array('card_position' => 'left' ), 'right' => array('card_position' => 'right' ), 'center' => array('card_position' => 'center' ), 'ddb-arrows' => array('card_arrows' => 'on' ) ) ) ); return sprintf( '
%1$s
%2$s
', $scroll, $cards ); } private function set_card_arrow_css($placement) { switch ($placement) { case 'alternate': case 'right': return 'top:50%;right:100%;transform:translateY(-50%);'; case 'left': return 'top:50%;left:100%;transform:translateY(-50%);'; default: return 'bottom:100%; left:50%;transform:translate(-50%);'; } } } new DDBUILDER_Timeline_Module;