humanware

trinity_slider

Jan 2nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.73 KB | None | 0 0
  1. <?php
  2. namespace TrinityWidgets\Widgets;
  3.  
  4. use Elementor\Widget_Base;
  5. use Elementor\Controls_Manager;
  6.  
  7. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  8.  
  9. /**
  10.  * Elementor Hello World
  11.  *
  12.  * Elementor widget for hello world.
  13.  *
  14.  * @since 1.0.0
  15.  */
  16. class Trinity_Slider extends Widget_Base {
  17.  
  18.     /**
  19.      * Retrieve the widget name.
  20.      *
  21.      * @since 1.0.0
  22.      *
  23.      * @access public
  24.      *
  25.      * @return string Widget name.
  26.      */
  27.     public function get_name() {
  28.         return 'trinity-slider';
  29.     }
  30.  
  31.     /**
  32.      * Retrieve the widget title.
  33.      *
  34.      * @since 1.0.0
  35.      *
  36.      * @access public
  37.      *
  38.      * @return string Widget title.
  39.      */
  40.     public function get_title() {
  41.         return __( 'Trinity Slider', 'trinity-widgets' );
  42.     }
  43.  
  44.     /**
  45.      * Retrieve the widget icon.
  46.      *
  47.      * @since 1.0.0
  48.      *
  49.      * @access public
  50.      *
  51.      * @return string Widget icon.
  52.      */
  53.     public function get_icon() {
  54.         return 'eicon-slider-push';
  55.     }
  56.  
  57.     /**
  58.      * Retrieve the list of categories the widget belongs to.
  59.      *
  60.      * Used to determine where to display the widget in the editor.
  61.      *
  62.      * Note that currently Elementor supports only one category.
  63.      * When multiple categories passed, Elementor uses the first one.
  64.      *
  65.      * @since 1.0.0
  66.      *
  67.      * @access public
  68.      *
  69.      * @return array Widget categories.
  70.      */
  71.     public function get_categories() {
  72.         return [ 'basic' ];
  73.     }
  74.  
  75.     /**
  76.      * Retrieve the list of scripts the widget depended on.
  77.      *
  78.      * Used to set scripts dependencies required to run the widget.
  79.      *
  80.      * @since 1.0.0
  81.      *
  82.      * @access public
  83.      *
  84.      * @return array Widget scripts dependencies.
  85.      */
  86.     public function get_script_depends() {
  87.         return [ 'trinity-slider' ];
  88.     }
  89.  
  90.     /**
  91.      * Register the widget controls.
  92.      *
  93.      * Adds different input fields to allow the user to change and customize the widget settings.
  94.      *
  95.      * @since 1.0.0
  96.      *
  97.      * @access protected
  98.      */
  99.     protected function _register_controls() {
  100.  
  101.         $this->start_controls_section(
  102.             'content_section',
  103.             [
  104.                 'label' => __( 'Sliders', 'trinity-widgets' ),
  105.                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  106.             ]
  107.         );
  108.  
  109.         $repeater = new \Elementor\Repeater();
  110.  
  111.         $repeater->add_control(
  112.             'image_control',
  113.             [
  114.                 'label' => __( 'Choose Image', 'trinity-widgets' ),
  115.                 'type' => \Elementor\Controls_Manager::MEDIA,
  116.                 'default' => [
  117.                     'url' => \Elementor\Utils::get_placeholder_image_src(),
  118.                 ],
  119.             ]
  120.         );
  121.  
  122.         $repeater->add_control(
  123.             'heading_control', [
  124.                 'label' => __( 'Banner Header / Caption for Mobile devices', 'trinity-widgets' ),
  125.                 'type' => \Elementor\Controls_Manager::TEXT,
  126.                 'placeholder' => __( 'Banner Header / Caption for Mobile devices', 'trinity-widgets' ),
  127.             ]
  128.         );
  129.  
  130.         $this->add_control(
  131.             'trinity_sliders',
  132.             [
  133.                 'label' => __( 'Trinity Sliders', 'trinity-widgets' ),
  134.                 'type' => \Elementor\Controls_Manager::REPEATER,
  135.                 'fields' => $repeater->get_controls(),
  136.                 'default' => [
  137.                     [
  138.                         'image_control' => __( 'Image', 'trinity-widgets' ),
  139.                         'heading_control' => __( 'Banner Heading / Mobile Caption', 'trinity-widgets' ),
  140.                     ],
  141.                     [
  142.                         'image_control' => __( 'Image', 'trinity-widgets' ),
  143.                         'heading_control' => __( 'Banner Heading / Mobile Caption', 'trinity-widgets' ),
  144.                     ],
  145.                 ],
  146.                 'title_field' => '{{{ heading_control }}}',
  147.             ]
  148.         );
  149.  
  150.         $this->end_controls_section();
  151.         $this->start_controls_section(
  152.             'banner_caption',
  153.             [
  154.                 'label' => esc_html__( 'Banner Content', 'trinity-widgets' ),   //section name for controler view
  155.             ]
  156.         );
  157.  
  158.         $this->add_control(
  159.             'banner_caption_control',
  160.             [
  161.                 'label' => esc_html__( 'Edit Banner Caption', 'trinity-widgets' ),
  162.                 'description' => esc_html__('Edit contents for the banner caption text.','trinity-widgets'),
  163.                 'type' => \Elementor\Controls_Manager::WYSIWYG,
  164.                 'placeholder' => __( 'Type your content here', 'trinity-widgets' ),
  165.             ]
  166.         );
  167.  
  168.         $this->end_controls_section();
  169.  
  170.     }
  171.  
  172.     protected function render() {
  173.         $settings = $this->get_settings_for_display();
  174.  
  175.         if ( $settings['trinity_sliders'] ) {
  176.             $i = 1;
  177.             echo '
  178. <div id="home_banner_slider" class="container-fluid">
  179.     <div class="row">
  180.         <div id="carousel-home-banner" class="carousel slide" data-ride="carousel">
  181.            <ol class="carousel-indicators">
  182.                <li data-target="#carousel-home-banner" data-slide-to="0" class="active"></li>
  183.                <li data-target="#carousel-home-banner" data-slide-to="1"></li>
  184.                <li data-target="#carousel-home-banner" data-slide-to="2"></li>
  185.            </ol>
  186.            <div class="carousel-inner">
  187.             ';
  188.         foreach (  $settings['trinity_sliders'] as $item ) { ?>
  189.                 <div class="item<?php if ($i == 1) echo ' active'; ?>">
  190.                     <div class="img-wrapper">
  191.                         <img src="<?php echo $item['image_control']['url']; ?>" alt="First slide">
  192.                     </div>
  193.                     <div class="carousel-caption">
  194.                         <p class="visible-xs"><?php echo $item['heading_control']; ?></p>
  195.                     </div>
  196.                 </div>
  197.             <?php $i++; }
  198.             echo '
  199.                 <a class="left carousel-control" href="#carousel-home-banner" data-slide="prev">
  200.                    <span class="glyphicon glyphicon-chevron-left"></span></a>
  201.                 <a class="right carousel-control" href="#carousel-home-banner" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
  202.             </div>
  203.             <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>
  204.         </div>
  205.     </div>
  206.             ';
  207.         }
  208.     }
  209.  
  210.     protected function _content_template() {
  211.         ?>
  212.         <# if ( settings.trinity_sliders ) { #>
  213. <div id="home_banner_slider" class="container-fluid">
  214.     <div class="row">
  215.         <div id="carousel-home-banner" class="carousel slide" data-ride="carousel">
  216.             <ol class="carousel-indicators">
  217.                 <li data-target="#carousel-home-banner" data-slide-to="0" class="active"></li>
  218.                 <li data-target="#carousel-home-banner" data-slide-to="1"></li>
  219.                 <li data-target="#carousel-home-banner" data-slide-to="2"></li>
  220.             </ol>
  221.             <div class="carousel-inner">
  222.             ';
  223.         <# _.each( settings.trinity_sliders, function( item ) { #>
  224.                 <div class="item active" style="background: url({{ item.image_control.url }});">
  225.                     <div class="img-wrapper">
  226.                         <img src="{{ item.image_control.url }}" alt="First slide">
  227.                     </div>
  228.                     <div class="carousel-caption">
  229.                         <p class="visible-xs"><span>VARIETY</span> Travel Options</p>
  230.                     </div>
  231.                 </div>
  232.         <# }); #>
  233.                 <a class="left carousel-control" href="#carousel-home-banner" data-slide="prev">
  234.                     <span class="glyphicon glyphicon-chevron-left"></span></a>
  235.                 <a class="right carousel-control" href="#carousel-home-banner" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
  236.             </div>
  237.             <div class="main-text col-md-5 col-md-offset-0 col-sm-7 col-xs-10 col-xs-offset-1">
  238.                 <div class="col-md-12 text-center">
  239.                     <h3 class="heading">YOUR EASY AND<br>AFFORDABLE <span class="highlight">CHOICE</span>
  240.                         <div class="divider"></div>
  241.                     </h3>
  242.                     <ul class="hidden-xs">
  243.                         <li><span>VARIETY</span> Travel Options</li>
  244.                         <li><span>BOOK</span> Online or by Phone</li>
  245.                         <li><span>BUDGET</span> Friendly</li>
  246.                         <li><span>COMPETITIVE</span> Pricing</li>
  247.                     </ul>
  248.                     <div class="btns-wrapper">
  249.                         <a href="services.php" class="btn btn-dark" href="">Learn More</a>
  250.                     </div>
  251.                 </div>
  252.             </div>
  253.         </div>
  254.     </div>
  255.         <# } #>
  256.         <?php
  257.     }
  258. }
Add Comment
Please, Sign In to add comment