]
);
+ $repeater->add_control(
+ 'image',
+ [
+ 'label' => esc_html__( 'Image', 'cube' ),
+ 'type' => Controls_Manager::MEDIA
+ ]
+ );
+
$repeater->add_control(
'background_color',
[
'label' => esc_html__( 'Background color', 'cube' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
- '{{WRAPPER}} .rightside .overlay' => 'background-color: {{VALUE}}',
+ '{{WRAPPER}} {{CURRENT_ITEM}} .rightside .overlay' => 'background-color: {{VALUE}}',
+ ],
+ ]
+ );
+
+ $repeater->add_control(
+ 'left',
+ [
+ 'label' => esc_html__('Image left position (px)', 'cube'),
+ 'type' => Controls_Manager::SLIDER,
+ 'range' => [
+ 'px' => [
+ 'min' => 1,
+ 'max' => 200,
+ 'step' => 1,
+ ],
+ ],
+ 'default' => [
+ 'size' => 0,
+ ],
+ 'separator' => 'after',
+ 'selectors' => [
+ '{{WRAPPER}} {{CURRENT_ITEM}} .thumbnail img' => 'left: {{SIZE}}px'
+ ],
+ ]
+ );
+
+ $repeater->add_control(
+ 'top',
+ [
+ 'label' => esc_html__('Image top position (px)', 'cube'),
+ 'type' => Controls_Manager::SLIDER,
+ 'range' => [
+ 'px' => [ // Not really a px measure but the slider doesn't work properly if we set a custom type here
+ 'min' => 1,
+ 'max' => 200,
+ 'step' => 1,
+ ],
+ ],
+ 'default' => [
+ 'size' => 0,
+ ],
+ 'separator' => 'after',
+ 'selectors' => [
+ '{{WRAPPER}} {{CURRENT_ITEM}} .thumbnail img' => 'bottom: -{{SIZE}}px'
],
]
);
[
'label' => esc_html__( 'Slides', 'cube' ),
'type' => Controls_Manager::REPEATER,
- 'fields' => $repeater->get_controls(), /* Use our repeater */
- 'default' => [
- [
- 'title' => 'Slide #1',
- 'text' => esc_html__( 'Lorem ipsum dolor', 'cube' ),
- 'link' => '',
- ],
- [
- 'text' => esc_html__( 'List Item #2', 'cube' ),
- 'link' => '',
- ]
- ],
+ 'fields' => $repeater->get_controls(),
+ 'default' => [],
'title_field' => '{{{ text }}}',
]
);
$settings = $this->get_settings_for_display();
if ( $settings['slides'] ) {
- echo '<div class="home-carousel">';
- foreach ( $settings['slides'] as $key => $item ) {
- $background_image = $item['background_image']['url'];
- $active = "";
- if($key === 0){
- $active = "active";
- }
-
- echo '<div class="carousel-slide container '.$active.'">
- <div class="leftside">
- <div class="overlay overlayside" style="background-image: url('.$background_image.')"></div>
- </div>
- <div class="rightside">
- <div class="overlay overlayside"></div>
- <div class="text">
- <h1 class="text-3xl">'.$item['title'].'</h1>
- <p>
- '.$item['text'].'
- </p>
- <a class="btn white" href="'.$item['link']['url'].'">'.$item['link_text'].'</a>
- </div>
- </div>
- </div>
- ';
- }
- echo '</div>';
+ $slides = $settings['slides'];
+ echo view('widgets/carousel-home', compact('slides'));
}
}
- protected function content_template() {
- ?>
- <# if ( settings.slides.length ) { #>
- <div class="home-carousel">
- <# _.each( settings.slides, function( item ) { #>
- <dt class="elementor-repeater-item-{{ item._id }}">{{{ item.list_title }}}</dt>
- <dd>{{{ item.list_content }}}</dd>
- <div class="carousel-slide container $active">
- <div class="leftside">
- <div class="overlay overlayside" style='background-image: url("{{{ item.background_image.url }}}")'></div>
- </div>
- <div class="rightside">
- <div class="overlay overlayside"></div>
- <div class="text">
- <h1 class="text-3xl">{{{ item.title }}}</h1>
- <p>{{{ item.text }}}</p>
- <a href="{{{ item.link }}}">{{{ item.link_text }}}</a>
- </div>
- </div>
- </div>
- <# }); #>
- </div>
- <# } #>
- <?php
- }
}
\ No newline at end of file
--- /dev/null
+<div class="home-carousel">
+ @foreach($slides as $key => $slide)
+ @php
+ $key += 1;
+ @endphp
+ <div class="elementor-repeater-item-{{$slide['_id']}} carousel-slide container {{ $key === 1 ? 'active' : '' }}">
+ <div class="leftside">
+ <div class="overlay overlayside" style="background-image: url({{$slide['background_image']['url']}})"></div>
+ @if(array_key_exists('image',$slide))
+ <div class="thumbnail">
+ <img src="{{ $slide['image']['url'] }}" />
+ </div>
+ @endif
+ </div>
+ <div class="rightside">
+ <div class="overlay overlayside"></div>
+ <div class="text">
+ <h1 class="text-3xl">{{ $slide['title'] }}</h1>
+ <p>{{ $slide['text'] }}</p>
+ @if(array_key_exists('link',$slide))
+ <a class="btn white" href="{{ $slide['link']['url'] }}">{{ $slide['link_text'] }}</a>
+ @endif
+ </div>
+ </div>
+ </div>
+ @endforeach
+</div>