Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace TrinityWidgets\Widgets;
- use Elementor\Widget_Base;
- use Elementor\Controls_Manager;
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
- /**
- * Elementor Hello World
- *
- * Elementor widget for hello world.
- *
- * @since 1.0.0
- */
- class Trinity_Slider extends Widget_Base {
- /**
- * Retrieve the widget name.
- *
- * @since 1.0.0
- *
- * @access public
- *
- * @return string Widget name.
- */
- public function get_name() {
- return 'trinity-slider';
- }
- /**
- * Retrieve the widget title.
- *
- * @since 1.0.0
- *
- * @access public
- *
- * @return string Widget title.
- */
- public function get_title() {
- return __( 'Trinity Slider', 'trinity-widgets' );
- }
- /**
- * Retrieve the widget icon.
- *
- * @since 1.0.0
- *
- * @access public
- *
- * @return string Widget icon.
- */
- public function get_icon() {
- return 'eicon-slider-push';
- }
- /**
- * Retrieve the list of categories the widget belongs to.
- *
- * Used to determine where to display the widget in the editor.
- *
- * Note that currently Elementor supports only one category.
- * When multiple categories passed, Elementor uses the first one.
- *
- * @since 1.0.0
- *
- * @access public
- *
- * @return array Widget categories.
- */
- public function get_categories() {
- return [ 'basic' ];
- }
- /**
- * Retrieve the list of scripts the widget depended on.
- *
- * Used to set scripts dependencies required to run the widget.
- *
- * @since 1.0.0
- *
- * @access public
- *
- * @return array Widget scripts dependencies.
- */
- public function get_script_depends() {
- return [ 'trinity-slider' ];
- }
- /**
- * Register the 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(
- 'content_section',
- [
- 'label' => __( 'Sliders', 'trinity-widgets' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
- $repeater = new \Elementor\Repeater();
- $repeater->add_control(
- 'image_control',
- [
- 'label' => __( 'Choose Image', 'trinity-widgets' ),
- 'type' => \Elementor\Controls_Manager::MEDIA,
- 'default' => [
- 'url' => \Elementor\Utils::get_placeholder_image_src(),
- ],
- ]
- );
- $repeater->add_control(
- 'heading_control', [
- 'label' => __( 'Banner Header / Caption for Mobile devices', 'trinity-widgets' ),
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'placeholder' => __( 'Banner Header / Caption for Mobile devices', 'trinity-widgets' ),
- ]
- );
- $this->add_control(
- 'trinity_sliders',
- [
- 'label' => __( 'Trinity Sliders', 'trinity-widgets' ),
- 'type' => \Elementor\Controls_Manager::REPEATER,
- 'fields' => $repeater->get_controls(),
- 'default' => [
- [
- 'image_control' => __( 'Image', 'trinity-widgets' ),
- 'heading_control' => __( 'Banner Heading / Mobile Caption', 'trinity-widgets' ),
- ],
- [
- 'image_control' => __( 'Image', 'trinity-widgets' ),
- 'heading_control' => __( 'Banner Heading / Mobile Caption', 'trinity-widgets' ),
- ],
- ],
- 'title_field' => '{{{ heading_control }}}',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'banner_caption',
- [
- 'label' => esc_html__( 'Banner Content', 'trinity-widgets' ), //section name for controler view
- ]
- );
- $this->add_control(
- 'banner_caption_control',
- [
- 'label' => esc_html__( 'Edit Banner Caption', 'trinity-widgets' ),
- 'description' => esc_html__('Edit contents for the banner caption text.','trinity-widgets'),
- 'type' => \Elementor\Controls_Manager::WYSIWYG,
- 'placeholder' => __( 'Type your content here', 'trinity-widgets' ),
- ]
- );
- $this->end_controls_section();
- }
- protected function render() {
- $settings = $this->get_settings_for_display();
- if ( $settings['trinity_sliders'] ) {
- $i = 1;
- echo '
- <div id="home_banner_slider" class="container-fluid">
- <div class="row">
- <div id="carousel-home-banner" class="carousel slide" data-ride="carousel">
- <ol class="carousel-indicators">
- <li data-target="#carousel-home-banner" data-slide-to="0" class="active"></li>
- <li data-target="#carousel-home-banner" data-slide-to="1"></li>
- <li data-target="#carousel-home-banner" data-slide-to="2"></li>
- </ol>
- <div class="carousel-inner">
- ';
- foreach ( $settings['trinity_sliders'] as $item ) { ?>
- <div class="item<?php if ($i == 1) echo ' active'; ?>">
- <div class="img-wrapper">
- <img src="<?php echo $item['image_control']['url']; ?>" alt="First slide">
- </div>
- <div class="carousel-caption">
- <p class="visible-xs"><?php echo $item['heading_control']; ?></p>
- </div>
- </div>
- <?php $i++; }
- echo '
- <a class="left carousel-control" href="#carousel-home-banner" data-slide="prev">
- <span class="glyphicon glyphicon-chevron-left"></span></a>
- <a class="right carousel-control" href="#carousel-home-banner" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
- </div>
- <div class="main-text col-md-5 col-md-offset-0 col-sm-7 col-xs-10 col-xs-offset-1">' . $settings['banner_caption_control'] .' </div>
- </div>
- </div>
- ';
- }
- }
- protected function _content_template() {
- ?>
- <# if ( settings.trinity_sliders ) { #>
- <div id="home_banner_slider" class="container-fluid">
- <div class="row">
- <div id="carousel-home-banner" class="carousel slide" data-ride="carousel">
- <ol class="carousel-indicators">
- <li data-target="#carousel-home-banner" data-slide-to="0" class="active"></li>
- <li data-target="#carousel-home-banner" data-slide-to="1"></li>
- <li data-target="#carousel-home-banner" data-slide-to="2"></li>
- </ol>
- <div class="carousel-inner">
- ';
- <# _.each( settings.trinity_sliders, function( item ) { #>
- <div class="item active" style="background: url({{ item.image_control.url }});">
- <div class="img-wrapper">
- <img src="{{ item.image_control.url }}" alt="First slide">
- </div>
- <div class="carousel-caption">
- <p class="visible-xs"><span>VARIETY</span> Travel Options</p>
- </div>
- </div>
- <# }); #>
- <a class="left carousel-control" href="#carousel-home-banner" data-slide="prev">
- <span class="glyphicon glyphicon-chevron-left"></span></a>
- <a class="right carousel-control" href="#carousel-home-banner" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
- </div>
- <div class="main-text col-md-5 col-md-offset-0 col-sm-7 col-xs-10 col-xs-offset-1">
- <div class="col-md-12 text-center">
- <h3 class="heading">YOUR EASY AND<br>AFFORDABLE <span class="highlight">CHOICE</span>
- <div class="divider"></div>
- </h3>
- <ul class="hidden-xs">
- <li><span>VARIETY</span> Travel Options</li>
- <li><span>BOOK</span> Online or by Phone</li>
- <li><span>BUDGET</span> Friendly</li>
- <li><span>COMPETITIVE</span> Pricing</li>
- </ul>
- <div class="btns-wrapper">
- <a href="services.php" class="btn btn-dark" href="">Learn More</a>
- </div>
- </div>
- </div>
- </div>
- </div>
- <# } #>
- <?php
- }
- }
Add Comment
Please, Sign In to add comment