* @since 1.0.3 */ class HighlightedText extends UiCoreWidget { public function __construct($data = [], $args = null) { parent::__construct($data, $args); } public function get_name() { return 'highlighted-text'; } public function get_categories() { return ['uicore']; } public function get_title() { return __('Highlighted Text', 'uicore-elements'); } public function get_icon() { return 'eicon-animated-headline ui-e-widget'; } public function get_keywords() { return [ 'headline', 'heading', 'animation', 'title', 'text' ]; } public function get_styles() { return [ 'highlighted-text' ]; } public function get_scripts() { return [ 'highlighted-text' => [ 'condition' => [ 'shape_animation' => 'animate', ], ] ]; } public function has_widget_inner_wrapper(): bool { // TODO: remove after 3.30, when the full deprecation of widget innet wrapper is ready return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); } protected function register_controls() { $this->start_controls_section( 'text_elements', [ 'label' => __( 'Text', 'uicore-elements' ), ] ); $repeater = new Repeater(); $repeater->add_control( 'type', [ 'label' => esc_html__( 'Type', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'text', 'options' => [ 'text' => esc_html__( 'Text', 'uicore-elements' ), 'icon' => esc_html__( 'Icon', 'uicore-elements' ), 'image' => esc_html__( 'Image', 'uicore-elements' ), ], 'selectors' => [ '{{WRAPPER}} .uicore-repeater-selector' => 'border-style: {{VALUE}};', ], 'render_type' => 'template', ] ); $repeater->add_control( 'text', [ 'label' => __( 'Text', 'uicore-elements' ), 'type' => Controls_Manager::TEXT, 'label_block' => true, 'placeholder' => __( 'Some Text', 'uicore-elements' ), 'default' => __( 'Some Text', 'uicore-elements' ), 'condition' => [ 'type' => 'text' ], ] ); $repeater->add_control( 'headline_style', [ 'label' => __( 'Highlight Style', 'uicore-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'none', 'options' => [ 'none' => __( 'None', 'uicore-elements' ), 'color' => __( 'No Stroke', 'uicore-elements' ), 'stroke1' => __( 'Stroke 1', 'uicore-elements' ), 'stroke2' => __( 'Stroke 2', 'uicore-elements' ), 'stroke3' => __( 'Stroke 3', 'uicore-elements' ), 'stroke4' => __( 'Stroke 4', 'uicore-elements' ), 'stroke5' => __( 'Stroke 5', 'uicore-elements' ), 'stroke6' => __( 'Stroke 6', 'uicore-elements' ), 'stroke7' => __( 'Stroke 7', 'uicore-elements' ), 'stroke8' => __( 'Stroke 8', 'uicore-elements' ), 'stroke9' => __( 'Stroke 9', 'uicore-elements' ), ], 'render_type' => 'template', 'condition' => [ 'type' => 'text' ], ] ); $repeater->add_control( 'icon', [ 'label' => esc_html__( 'Icon', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::ICONS, 'default' => [ 'value' => 'fas fa-circle', 'library' => 'fa-solid', ], 'recommended' => [ 'fa-solid' => [ 'circle', 'dot-circle', 'square-full', ], 'fa-regular' => [ 'circle', 'dot-circle', 'square-full', ], ], 'condition' => [ 'type' => 'icon' ], ] ); $repeater->add_control( 'icon_color', [ 'label' => esc_html__( 'Color', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}}' => 'color: {{VALUE}}; fill: {{VALUE}}', //icon as a font + svg ], 'condition' => [ 'type' => ['icon','text'] ], ] ); $repeater->add_group_control( \Elementor\Group_Control_Background::get_type(), [ 'name' => 'background_color', 'condition' => [ 'type' => ['icon','text'] ], 'selector' => '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}} .ui-e-headline-text', ] ); $repeater->add_control( 'background_color_as_text', [ 'label' => esc_html__( 'Use Background Color as Text Color', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => false, 'render_type' => 'template', 'condition' => [ 'type' => ['icon','text'] ], 'selectors' => [ '{{WRAPPER}} {{CURRENT_ITEM}}.ui-e-highlight-icon, {{WRAPPER}} {{CURRENT_ITEM}} .ui-e-headline-text' => 'background-color: transparent;-webkit-background-clip: text;background-clip: text;-webkit-text-fill-color: transparent;', ], ] ); $repeater->add_control( 'stroke_color', [ 'label' => esc_html__( 'Stroke Color', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} {{CURRENT_ITEM}} svg path' => 'stroke: {{VALUE}}', ], 'condition' => [ 'headline_style!' => ['none','color'] ], ] ); $repeater->add_control( 'image', [ 'label' => esc_html__( 'Choose Image', 'uicore-elements' ), 'type' => \Elementor\Controls_Manager::MEDIA, 'default' => [ 'url' => \Elementor\Utils::get_placeholder_image_src(), ], 'condition' => [ 'type' => 'image' ], ] ); $repeater->add_control( 'size', [ 'label' => __('Size', 'uicore-elements'), 'type' => \Elementor\Controls_Manager::SLIDER, 'default' => [ 'size' => 100, 'unit' => '%', ], 'range' => [ '%' => [ 'min' => 0, 'max' => 150, ], ], 'selectors' => [ '{{WRAPPER}} {{CURRENT_ITEM}}' => '--ui-e-asset-size: calc({{SIZE}} / 100);', ], 'condition' => [ 'type' => ['icon', 'image'] ], ] ); $this->add_control( 'content', [ 'label' => __( 'Content', 'uicore-elements' ), 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls(), 'default' => [ [ 'text' => __( 'This is my awesome', 'uicore-elements' ), 'headline_style' => 'none', ], [ 'text' => __( 'highlight', 'uicore-elements' ), 'headline_style' => 'stroke1', ], [ 'text' => __( 'text.', 'uicore-elements' ), 'headline_style' => 'none', ], ], 'title_field' => '{{{ type == "text" ? text : type }}}', 'render_type' => 'template', ] ); $this->add_responsive_control( 'alignment', [ 'label' => __( 'Alignment', 'uicore-elements' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => __( 'Left', 'uicore-elements' ), 'icon' => 'eicon-text-align-left', ], 'center' => [ 'title' => __( 'Center', 'uicore-elements' ), 'icon' => 'eicon-text-align-center', ], 'right' => [ 'title' => __( 'Right', 'uicore-elements' ), 'icon' => 'eicon-text-align-right', ], ], 'default' => 'center', 'selectors' => [ '{{WRAPPER}}' => 'text-align: {{VALUE}}', ], ] ); $this->add_control( 'tag', [ 'label' => __( 'HTML Tag', 'uicore-elements' ), 'type' => Controls_Manager::SELECT, 'options' => [ 'h1' => 'H1', 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'div' => 'div', 'span' => 'span', 'p' => 'p', ], 'default' => 'h2', ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_marker', [ 'label' => __( 'Shape', 'uicore-elements' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'marker_color', [ 'label' => __( 'Color', 'uicore-elements' ), 'type' => Controls_Manager::COLOR, 'global' => [ 'default' => '#F1F200', ], 'selectors' => [ '{{WRAPPER}} .ui-e-headline-text path' => 'stroke: {{VALUE}}', ], ] ); $this->add_control( 'stroke_width', [ 'label' => __( 'Width', 'uicore-elements' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 1, 'max' => 100, ], ], 'default' => [ 'size' => '40', 'unit' => 'px' ], 'selectors' => [ '{{WRAPPER}} .ui-e-headline-text path' => 'stroke-width: {{SIZE}}', ], ] ); $this->add_control( 'vertical_offset', [ 'label' => __( 'Vertical Offset', 'uicore-elements' ), 'type' => Controls_Manager::SLIDER, 'range' => [ '%' => [ 'min' => -100, 'max' => 100, ], 'px' => [ 'min' => -100, 'max' => 100, ], ], 'default' => [ 'size' => '0', 'unit' => '%', ], 'size_units'=>['%', 'px'], 'selectors' => [ '{{WRAPPER}} .ui-e-headline-text svg' => 'bottom: {{SIZE}}{{UNIT}}', ], ] ); $this->add_control( 'shape_animation', [ 'label' => __( 'Animation', 'uicore-elements' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'On', 'uicore-elements' ), 'label_off' => __( 'Off', 'uicore-elements' ), 'default' => 'animate', 'separator' => 'before', 'return_value' =>'animate', 'prefix_class' => 'ui-e-a-', ] ); $this->add_control( 'shape_animation_delay', [ 'label' => __( 'Animation Delay', 'uicore-elements' ) . ' (ms)', 'type' => Controls_Manager::NUMBER, 'default' => '', 'min' => 0, 'step' => 100, 'condition' => [ 'shape_animation' => 'animate', ], 'render_type' => 'template' ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style_text', [ 'label' => __( 'Headline', 'uicore-elements' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'title_color', [ 'label' => __( 'Text Color', 'uicore-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ui-e-highlight-icon, {{WRAPPER}} .ui-e-headline-text' => 'color: {{VALUE}}', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'title_typography', 'selector' => '{{WRAPPER}} .ui-e-highlight-icon, {{WRAPPER}} .ui-e-headline-text, {{WRAPPER}} .ui-e-highlight-image', ] ); $this->add_control( 'higlighted_title_color', [ 'label' => __( 'Highlighted Text Color', 'uicore-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ui-e-headline-highlighted' => 'color: {{VALUE}}', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'higlighted_title_typography', 'selector' => '{{WRAPPER}} .ui-e-headline-highlighted', ] ); $this->end_controls_section(); } protected function get_svg($return,$type='') { $paths = [ 'none'=> null, 'color'=> null, 'stroke1'=>"", 'stroke2'=>"", 'stroke3'=>"", 'stroke4'=>" ", 'stroke5'=>" ", 'stroke6'=>"", 'stroke7'=>"", 'stroke8'=>'', 'stroke9'=>' ' ]; if($return === 'list'){ foreach($paths as $name => $path){ if($name === 'none'){ $svg[$name] = ""; }else{ $svg[$name] = ''.$path.''; } } }else{ if($type === 'none'){ $svg = ""; }else{ $svg = ''.$paths[$type].''; } } return $svg; } protected function render() { $settings = $this->get_settings_for_display(); $tag = $settings['tag']; $content = $settings['content']; $delay = $settings['shape_animation_delay']; ?> < class="ui-e--highlighted-text" > ' . Helper::esc_string($item['text']) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped . ''; }else{ $svg_markup = $this->get_svg('single',$item['headline_style']); echo ' ' . Helper::esc_string($item['text']) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped .'' . Helper::esc_svg($svg_markup) //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped .' '; } break; case 'icon': echo ""; \Elementor\Icons_Manager::render_icon($item['icon'], ['aria-hidden' => 'true', 'class'=>'char']); echo ""; break; case 'image': echo ''.wp_get_attachment_image($item['image']['id'], "medium", false, ["loading" => false, "class"=>'char']).''; break; default: break; } } ?> > <# var svgs = get_svg('list')); ?>; #> <{{{ settings.tag }}} class="ui-e--highlighted-text"> <# settings.content.forEach( function (item){ switch (item.type) { case 'text': if(item.headline_style === 'none'){ #>{{{ item.text }}}<# }else{ #> {{{ item.text }}}{{{svgs[item.headline_style]}}} <# } break; case 'icon': #>{{{ elementor.helpers.renderIcon( view, item.icon, { 'aria-hidden': true }, 'i' , 'value' ) }}}<# break; case 'image': var image = { id: item.image.id, url: item.image.url, size: item.thumbnail_size, dimension: item.thumbnail_custom_dimension, model: view.getEditModel() }; var image_url = elementor.imagesManager.getImageUrl( image ); #><# break; default: break; } }); #> widgets_manager->register(new HighlightedText());