<?php
use Elementor\Controls_Manager;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Text_Stroke;
use Elementor\Modules\DynamicTags\Module as TagsModule;
use Elementor\Utils;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
class Motiox_Animated_Headline extends Elementor\Widget_Base {
public function get_name() {
return 'motiox-animated-headline';
}
public function get_title() {
return esc_html__('Motiox Animated Headline', 'motiox');
}
public function get_icon() {
return 'eicon-animated-headline';
}
public function get_categories() {
return array('motiox-addons');
}
public function get_keywords() {
return ['headline', 'heading', 'animation', 'title', 'text'];
}
public function get_script_depends() {
return ['motiox-elementor-animated-headline'];
}
protected function register_controls() {
$this->start_controls_section(
'text_elements',
[
'label' => esc_html__('Headline', 'motiox'),
]
);
$this->add_control(
'headline_style',
[
'label' => esc_html__('Style', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => 'default',
'options' => [
'default' => esc_html__('Default', 'motiox'),
'highlight' => esc_html__('Highlighted', 'motiox'),
'rotate' => esc_html__('Rotating', 'motiox'),
],
'prefix_class' => 'motiox-elementor-headline--style-',
'render_type' => 'template',
'frontend_available' => true,
]
);
$this->add_control(
'animation_type',
[
'label' => esc_html__('Animation', 'motiox'),
'type' => Controls_Manager::SELECT,
'options' => [
'typing' => 'Typing',
'clip' => 'Clip',
'flip' => 'Flip',
'swirl' => 'Swirl',
'blinds' => 'Blinds',
'drop-in' => 'Drop-in',
'wave' => 'Wave',
'slide' => 'Slide',
'slide-down' => 'Slide Down',
],
'default' => 'typing',
'condition' => [
'headline_style' => 'rotate',
],
'frontend_available' => true,
]
);
$this->add_control(
'marker',
[
'label' => esc_html__('Shape', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => 'circle',
'options' => [
'circle' => _x('Circle', 'Shapes', 'motiox'),
'curly' => _x('Curly', 'Shapes', 'motiox'),
'underline' => _x('Underline', 'Shapes', 'motiox'),
'double' => _x('Double', 'Shapes', 'motiox'),
'double_underline' => _x('Double Underline', 'Shapes', 'motiox'),
'underline_zigzag' => _x('Underline Zigzag', 'Shapes', 'motiox'),
'diagonal' => _x('Diagonal', 'Shapes', 'motiox'),
'strikethrough' => _x('Strikethrough', 'Shapes', 'motiox'),
'x' => 'X',
],
'render_type' => 'template',
'condition' => [
'headline_style' => 'highlight',
],
'frontend_available' => true,
]
);
$this->add_control(
'before_text',
[
'label' => esc_html__('Before Text', 'motiox'),
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
'categories' => [
TagsModule::TEXT_CATEGORY,
],
],
'default' => esc_html__('This page is', 'motiox'),
'placeholder' => esc_html__('Enter your headline', 'motiox'),
'label_block' => true,
'separator' => 'before',
]
);
$this->add_control(
'main_text',
[
'label' => esc_html__('Main Text', 'motiox'),
'type' => Controls_Manager::TEXT,
'default' => esc_html__('Main', 'motiox'),
'label_block' => true,
'separator' => 'none',
'condition' => [
'headline_style' => 'default',
],
]
);
$this->add_control(
'highlighted_text',
[
'label' => esc_html__('Highlighted Text', 'motiox'),
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
'categories' => [
TagsModule::TEXT_CATEGORY,
],
],
'default' => esc_html__('Amazing', 'motiox'),
'label_block' => true,
'condition' => [
'headline_style' => 'highlight',
],
'separator' => 'none',
'frontend_available' => true,
]
);
$this->add_control(
'rotating_text',
[
'label' => esc_html__('Rotating Text', 'motiox'),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => esc_html__('Enter each word in a separate line', 'motiox'),
'separator' => 'none',
'default' => "Better\nBigger\nFaster",
'dynamic' => [
'active' => true,
'categories' => [
TagsModule::TEXT_CATEGORY,
],
],
'condition' => [
'headline_style' => 'rotate',
],
'frontend_available' => true,
]
);
$this->add_control(
'after_text',
[
'label' => esc_html__('After Text', 'motiox'),
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
'categories' => [
TagsModule::TEXT_CATEGORY,
],
],
'placeholder' => esc_html__('Enter your headline', 'motiox'),
'label_block' => true,
'separator' => 'none',
]
);
$this->add_control(
'loop',
[
'label' => esc_html__('Infinite Loop', 'motiox'),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
'render_type' => 'template',
'frontend_available' => true,
'selectors' => [
'{{WRAPPER}}' => '--iteration-count: infinite',
],
'separator' => 'before',
'condition' => [
'headline_style!' => 'default',
],
]
);
$this->add_control(
'highlight_animation_duration',
[
'label' => esc_html__('Duration', 'motiox') . ' (ms)',
'type' => Controls_Manager::NUMBER,
'default' => 1200,
'render_type' => 'template',
'frontend_available' => true,
'selectors' => [
'{{WRAPPER}}' => '--animation-duration: {{VALUE}}ms',
],
'condition' => [
'headline_style' => 'highlight',
],
]
);
$this->add_control(
'rotate_iteration_delay',
[
'label' => esc_html__('Duration', 'motiox') . ' (ms)',
'type' => Controls_Manager::NUMBER,
'default' => 2500,
'render_type' => 'template',
'frontend_available' => true,
'condition' => [
'headline_style' => 'rotate',
],
]
);
$this->add_control(
'link',
[
'label' => esc_html__('Link', 'motiox'),
'type' => Controls_Manager::URL,
'dynamic' => [
'active' => true,
],
'separator' => 'before',
]
);
$this->add_responsive_control(
'alignment',
[
'label' => esc_html__('Alignment', 'motiox'),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__('Left', 'motiox'),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__('Center', 'motiox'),
'icon' => 'eicon-text-align-center',
],
'right' => [
'title' => esc_html__('Right', 'motiox'),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'center',
'selectors' => [
'{{WRAPPER}} .elementor-headline' => 'text-align: {{VALUE}}',
],
]
);
$this->add_control(
'tag',
[
'label' => esc_html__('HTML Tag', 'motiox'),
'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->add_control(
'headline_text_gradient',
[
'label' => esc_html__('Gradient', 'motiox'),
'type' => Controls_Manager::SWITCHER,
'prefix_class' => 'headline-text-gradiant-'
]
);
$this->end_controls_section();
// highlight
$this->start_controls_section(
'section_style_marker',
[
'label' => esc_html__('Shape', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
'condition' => [
'headline_style' => 'highlight',
],
]
);
$this->add_control(
'marker_color',
[
'label' => esc_html__('Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'global' => [
'default' => Global_Colors::COLOR_ACCENT,
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-wrapper path' => 'stroke: {{VALUE}}',
],
]
);
$this->add_control(
'stroke_width',
[
'label' => esc_html__('Width', 'motiox'),
'type' => Controls_Manager::SLIDER,
'size_units' => ['px', 'em', 'rem', 'custom'],
'range' => [
'px' => [
'min' => 1,
'max' => 20,
],
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-wrapper path' => 'stroke-width: {{SIZE}}{{UNIT}}',
],
]
);
$this->add_control(
'above_content',
[
'label' => esc_html__('Bring to Front', 'motiox'),
'type' => Controls_Manager::SWITCHER,
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-wrapper svg' => 'z-index: 2',
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'z-index: auto',
],
]
);
$this->add_control(
'rounded_edges',
[
'label' => esc_html__('Rounded Edges', 'motiox'),
'type' => Controls_Manager::SWITCHER,
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-wrapper path' => 'stroke-linecap: round; stroke-linejoin: round',
],
]
);
$this->add_responsive_control(
'margin_animated',
[
'label' => esc_html__('Margin', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em'],
'selectors' => [
'{{WRAPPER}} .elementor-headline' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_style_text',
[
'label' => esc_html__('Headline', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__('Text Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'global' => [
'default' => Global_Colors::COLOR_SECONDARY,
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-plain-text' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'global' => [
'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
],
'selector' => '{{WRAPPER}} .elementor-headline',
]
);
$this->add_group_control(
Group_Control_Text_Stroke::get_type(),
[
'name' => 'text_stroke',
'selector' => '{{WRAPPER}} .elementor-headline .motiox-elementor-headline-plain-text',
]
);
$this->add_control(
'heading_words_style',
[
'type' => Controls_Manager::HEADING,
'label' => esc_html__('Animated Text', 'motiox'),
'separator' => 'before',
]
);
// $this->add_control(
// 'words_color',
// [
// 'label' => esc_html__('Text Color', 'motiox'),
// 'type' => Controls_Manager::COLOR,
// 'selectors' => [
// '{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'color: {{VALUE}}',
// ],
// ]
// );
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'words_typography',
'global' => [
'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
],
'selector' => '{{WRAPPER}} .motiox-elementor-headline-dynamic-text',
'exclude' => ['font_size'],
]
);
$this->add_group_control(
Group_Control_Text_Stroke::get_type(),
[
'name' => 'animated_text_stroke',
'selector' => '{{WRAPPER}} .elementor-headline .motiox-elementor-headline-dynamic-wrapper',
]
);
$this->add_control(
'typing_animation_highlight_colors',
[
'type' => Controls_Manager::HEADING,
'label' => esc_html__('Selected Text', 'motiox'),
'separator' => 'before',
'condition' => [
'headline_style' => 'rotate',
'animation_type' => 'typing',
],
]
);
$this->add_control(
'highlighted_text_background_color',
[
'label' => esc_html__('Selection Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}}' => '--typing-selected-bg-color: {{VALUE}}',
],
'condition' => [
'headline_style' => 'rotate',
'animation_type' => 'typing',
],
]
);
$this->add_control(
'heading_words_style_color',
[
'type' => Controls_Manager::HEADING,
'label' => esc_html__('Animated Color Gradient', 'motiox'),
'separator' => 'before',
]
);
$this->add_responsive_control(
'background_gradient_angle',
[
'label' => esc_html__('Gradient Angle', 'motiox'),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => ['deg'],
'range' => [
'deg' => [
'min' => 0,
'max' => 360,
'step' => 1,
],
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'background-image: linear-gradient({{SIZE}}deg, {{background_gradient_start.VALUE}} {{background_gradient_start_position.SIZE}}, {{background_gradient_end.VALUE}} {{background_gradient_end_position.SIZE}});',
],
]
);
$this->add_responsive_control(
'background_gradient_start',
[
'label' => esc_html__('Start Color', 'motiox'),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'background-image: linear-gradient({{background_gradient_angle.SIZE}}deg, {{VALUE}} {{background_gradient_start_position.SIZE}}, {{background_gradient_end.VALUE}} {{background_gradient_end_position.SIZE}});',
],
]
);
$this->add_responsive_control(
'background_gradient_start_position',
[
'label' => esc_html__('Start Color Position (%)', 'motiox'),
'type' => \Elementor\Controls_Manager::SLIDER,
'size_units' => ['%', 'px', 'vw'],
'range' => [
'%' => [
'min' => 0,
'max' => 100,
'step' => 1,
],
'px' => [
'min' => 0,
'max' => 1000,
'step' => 1,
],
'vw' => [
'min' => 0,
'max' => 100,
'step' => 1,
],
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'background-image: linear-gradient({{background_gradient_angle.SIZE}}deg, {{background_gradient_start.VALUE}} {{SIZE}}{{UNIT}}, {{background_gradient_end.VALUE}} {{background_gradient_end_position.SIZE}}{{background_gradient_end_position.UNIT}});',
],
]
);
$this->add_responsive_control(
'background_gradient_end',
[
'label' => esc_html__('End Color', 'motiox'),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'background-image: linear-gradient({{background_gradient_angle.SIZE}}deg, {{background_gradient_start.VALUE}} {{background_gradient_start_position.SIZE}}, {{VALUE}} {{background_gradient_end_position.SIZE});',
],
]
);
$this->add_responsive_control(
'background_gradient_end_position',
[
'label' => esc_html__('End Color Position (%)', 'motiox'),
'type' => Controls_Manager::SLIDER,
'default' => [
'unit' => '%',
],
'tablet_default' => [
'unit' => '%',
],
'mobile_default' => [
'unit' => '%',
],
'size_units' => ['%', 'px', 'vw'],
'range' => [
'%' => [
'min' => 1,
'max' => 100,
],
'px' => [
'min' => 1,
'max' => 1000,
],
'vw' => [
'min' => 1,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .motiox-elementor-headline-dynamic-text' => 'background-image: linear-gradient({{background_gradient_angle.SIZE}}deg, {{background_gradient_start.VALUE}} {{background_gradient_start_position.SIZE}}{{background_gradient_start_position.UNIT}}, {{background_gradient_end.VALUE}} {{SIZE}}{{UNIT}});',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$tag = Utils::validate_html_tag($settings['tag']);
$this->add_render_attribute('headline', 'class', 'elementor-headline');
if ('rotate' === $settings['headline_style']) {
$this->add_render_attribute('headline', 'class', 'motiox-elementor-headline-animation-type-' . $settings['animation_type']);
$is_letter_animation = in_array($settings['animation_type'], ['typing', 'swirl', 'blinds', 'wave']);
if ($is_letter_animation) {
$this->add_render_attribute('headline', 'class', 'motiox-elementor-headline-letters');
}
}
if (!empty($settings['link']['url'])) {
$this->add_link_attributes('url', $settings['link']);
?>
<a <?php $this->print_render_attribute_string('url'); ?>>
<?php
}
?>
<<?php Utils::print_validated_html_tag($tag); ?> <?php $this->print_render_attribute_string('headline'); ?>>
<?php if (!empty($settings['before_text'])) : ?>
<span class="motiox-elementor-headline-plain-text motiox-elementor-headline-text-wrapper"><?php $this->print_unescaped_setting('before_text'); ?></span>
<?php endif; ?>
<span class="motiox-elementor-headline-dynamic-wrapper motiox-elementor-headline-text-wrapper">
<?php if ('rotate' === $settings['headline_style'] && $settings['rotating_text']) :
$rotating_text = explode("\n", $settings['rotating_text']);
foreach ($rotating_text as $key => $text) : ?>
<span class="motiox-elementor-headline-dynamic-text<?php echo 1 > $key ? ' motiox-elementor-headline-text-active' : ''; ?>">
<?php Utils::print_unescaped_internal_string(str_replace(' ', ' ', $text)); ?>
</span>
<?php endforeach; ?>
<?php elseif ('highlight' === $settings['headline_style'] && !empty($settings['highlighted_text'])) : ?>
<span class="motiox-elementor-headline-dynamic-text motiox-elementor-headline-text-active"><?php $this->print_unescaped_setting('highlighted_text'); ?></span>
<?php elseif ('default' === $settings['headline_style'] && !empty($settings['main_text'])) : ?>
<span class="motiox-elementor-headline-dynamic-text"><?php $this->print_unescaped_setting('main_text'); ?></span>
<?php endif ?>
</span>
<?php if (!empty($settings['after_text'])) : ?>
<span class="motiox-elementor-headline-plain-text motiox-elementor-headline-text-wrapper"><?php $this->print_unescaped_setting('after_text'); ?></span>
<?php endif; ?>
</<?php Utils::print_validated_html_tag($tag); ?>>
<?php
if (!empty($settings['link']['url'])) {
echo '</a>';
}
}
/**
* Render Animated Headline widget output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 2.9.0
* @access protected
*/
protected function content_template() {
?>
<#
var headlineClasses = 'elementor-headline',
tag = elementor.helpers.validateHTMLTag( settings.tag );
if ( 'rotate' === settings.headline_style ) {
headlineClasses += ' motiox-elementor-headline-animation-type-' + settings.animation_type;
var isLetterAnimation = -1 !== [ 'typing', 'swirl', 'blinds', 'wave' ].indexOf( settings.animation_type );
if ( isLetterAnimation ) {
headlineClasses += ' motiox-elementor-headline-letters';
}
}
if ( settings.link.url ) { #>
<a href="#">
<# } #>
<{{{ tag }}} class="{{{ headlineClasses }}}">
<# if ( settings.before_text ) { #>
<span class="motiox-elementor-headline-plain-text motiox-elementor-headline-text-wrapper">{{{ settings.before_text }}}</span>
<# } #>
<# if ( settings.rotating_text ) { #>
<span class="motiox-elementor-headline-dynamic-wrapper motiox-elementor-headline-text-wrapper">
<# if ( 'rotate' === settings.headline_style && settings.rotating_text ) {
var rotatingText = ( settings.rotating_text || '' ).split( '\n' );
for ( var i = 0; i < rotatingText.length; i++ ) {
var statusClass = 0 === i ? 'motiox-elementor-headline-text-active' : ''; #>
<span class="motiox-elementor-headline-dynamic-text {{ statusClass }}">
{{{ rotatingText[ i ].replace( ' ', ' ' ) }}}
</span>
<# }
}
else if ( 'highlight' === settings.headline_style && settings.highlighted_text ) { #>
<span class="motiox-elementor-headline-dynamic-text motiox-elementor-headline-text-active">{{{ settings.highlighted_text }}}</span>
<# } #>
</span>
<# } #>
<# if ( settings.after_text ) { #>
<span class="motiox-elementor-headline-plain-text motiox-elementor-headline-text-wrapper">{{{ settings.after_text }}}</span>
<# } #>
</{{{ tag }}}>
<# if ( settings.link.url ) { #>
</a>
<# } #>
<?php
}
}
$widgets_manager->register(new Motiox_Animated_Headline());