* @return array Widget scripts dependencies.
*/
public function get_script_depends() {
- return [];
+
+ wp_register_script(
+ 'cube-resource-carousel',
+ \App\asset_path('scripts/resource-carousel.js'),
+ ['jquery'], // Dependencies
+ null, // Version
+ true // In footer?
+ );
+
+ // Use script already registered by Elementor so we don't have to include another copy of Slick
+ return [ 'jquery-slick', 'cube-resource-carousel' ];
+
}
/**
* Register the widget controls.
]
);
+ $this->add_control(
+ 'type',
+ [
+ 'label' => __('Display Type', 'cube'),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ 'grid' => __( 'Grid', 'cube' ),
+ 'carousel' => __( 'Carousel', 'cube' ),
+ ],
+ 'default' => 'grid',
+ 'render_type' => 'template', // Make editor re-render when this changes
+ 'prefix_class' => 'resource-grid-type-',
+ ]
+ );
+
$this->add_control(
'items',
[
// Todo: revisit this to see if we can have a more user-friendly file control
// See: https://github.com/pojome/elementor/issues/4468
+ // See also: https://github.com/elementor/elementor/issues/1573#issuecomment-561405541
+ // A searchable URL field might be enough but the text control isn't compatible with the
+ // data structure of the URL control so that would need to be handled or transitioned
[
'name' => 'interactive_version',
'label' => __( 'Interactive version link', 'cube' ),
*/
protected function render() {
+ $display_type = $this->get_settings('type');
$items = $this->get_settings('items');
- $html = \App\template('widgets/resource-grid', compact('items'));
-
- echo '<div class="resource-grid">'. $html .'</div>';
+ if ($display_type == 'carousel') {
+ echo \App\template('widgets/resource-carousel', compact('items'));
+ } else {
+ echo \App\template('widgets/resource-grid', compact('items'));
+ }
}
/**
* @since 1.0.0
* @access protected
*/
+
+ /* ### Disabled because now there are two different templates (grid + carousel)
+ and it would be too messy to have live JS templates too
+
protected function _content_template() {
?>
<div class="resource-grid">
</div>
<?php
}
+ */
}
"video-carousel": [
"./scripts/video-carousel.js"
],
+ "resource-carousel": [
+ "./scripts/resource-carousel.js"
+ ],
"customizer": [
"./scripts/customizer.js"
]
},
"publicPath": "/wp-content/themes/physioassist",
"devUrl": "http://physioassist.test",
- "proxyUrl": "http://localhost:3000",
+ "proxyUrl": "http://paris.cubedesigners.com:63000",
"cacheBusting": "[name]_[hash:8]",
"watch": [
"app/**/*.php",
--- /dev/null
+// ELEMENTOR Trigger
+(function($) {
+ // Trigger handler when element ready
+ $(window).on( 'elementor/frontend/init', function() {
+ // eslint-disable-next-line
+ elementorFrontend.hooks.addAction('frontend/element_ready/cube-resource-grid.default', function ($scope) {
+
+ // Only trigger if it is a carousel type gallery
+ if ($scope.hasClass('resource-grid-type-carousel')) {
+ $scope.find('.resource-carousel').slick(); // Note: settings come from data-attribute in HTML
+ }
+ });
+ });
+})(jQuery);
--- /dev/null
+.resource-carousel
+
+ &-item-content
+ display: flex
+
+ &-image
+ flex: 0 1 auto
+ display: block
+ align-self: flex-end
+ max-width: 35% !important
+ box-shadow: -4px 6px 10px -2px rgba(0,0,0,0.4) !important
+ margin-left: 30px !important
+
+ +below(680px)
+ margin-left: 0
+
+ &-text
+ flex: 1 1 auto
+ constrain(padding-left, 2.5vw) // Gutter between image and text
+ align-self: center
+
+ &-title
+ color: $colors.sub-headings
+ font-size: 18px
+ font-weight: 600
+ text-transform: uppercase
+ margin-bottom: 0.8em
+ line-height: 1.2
+
+ &-link
+ display: block
+ position: relative
+ margin-top: 1.4em
+ padding-left: 1em
+
+ svg
+ position: absolute
+ top: 0.425em
+ left: 0
--- /dev/null
+{{--RESOURCE CAROUSEL--}}
+@php
+ $settings = [
+ 'slidesToShow' => 3,
+ 'slidesToScroll' => 1,
+ 'dots' => count($items) > 3, // Only show dots when there are enough items
+ 'infinite' => true,
+ 'responsive' => [
+ [
+ 'breakpoint' => 1300,
+ 'settings' => [
+ 'slidesToShow' => 2
+ ]
+ ],
+ [
+ 'breakpoint' => 850,
+ 'settings' => [
+ 'slidesToShow' => 1
+ ]
+ ],
+ ]
+ ];
+
+ $slick = json_encode($settings);
+
+@endphp
+
+<div class="resource-carousel elementor-slick-slider" data-slick="{{ $slick }}">
+
+ @foreach ($items as $item)
+
+ <div class="resource-carousel-item slick-slide">
+ <div class="resource-carousel-item-content">
+
+ @image($item['image']['id'], 'full', ['class' => 'resource-carousel-image'])
+
+ <div class="resource-carousel-text">
+
+ <h3 class="resource-carousel-title">{{ $item['title'] }}</h3>
+
+ @if ($item['interactive_version'])
+ <a href="{{ $item['interactive_version'] }}" class="resource-carousel-link arrow-link" target="_blank" rel="noopener">
+ @svg('arrow')
+ <?php _ex('Read interactive version', 'Resource grid widget interactive version link text', 'cube') ?>
+ </a>
+ @endif
+
+ @if ($item['pdf'])
+ <a href="{{ $item['pdf'] }}" class="resource-carousel-link arrow-link" target="_blank" rel="noopener">
+ @svg('arrow')
+ <?php _ex('Download PDF', 'Resource grid widget PDF link text', 'cube') ?>
+ </a>
+ @endif
+
+ </div> {{-- .resource-carousel-text --}}
+
+ </div> {{-- .resource-carousel-item-content --}}
+ </div> {{-- .resource-carousel-item --}}
+
+ @endforeach
+
+</div>
-@foreach ($items as $item)
+<div class="resource-grid">
- <div class="resource-grid-item">
- @image($item['image']['id'], 'full', ['class' => 'resource-grid-image'])
+ @foreach ($items as $item)
- <div class="resource-grid-text">
+ <div class="resource-grid-item">
+ @image($item['image']['id'], 'full', ['class' => 'resource-grid-image'])
- <h3 class="resource-grid-title">{{ $item['title'] }}</h3>
+ <div class="resource-grid-text">
- @if ($item['interactive_version'])
- <a href="{{ $item['interactive_version'] }}" class="resource-grid-link arrow-link" target="_blank" rel="noopener">
- @svg('arrow')
- <?php _ex('Read interactive version', 'Resource grid widget interactive version link text', 'cube') ?>
- </a>
- @endif
+ <h3 class="resource-grid-title">{{ $item['title'] }}</h3>
- @if ($item['pdf'])
- <a href="{{ $item['pdf'] }}" class="resource-grid-link arrow-link" target="_blank" rel="noopener">
- @svg('arrow')
- <?php _ex('Download PDF', 'Resource grid widget PDF link text', 'cube') ?>
- </a>
- @endif
+ @if ($item['interactive_version'])
+ <a href="{{ $item['interactive_version'] }}" class="resource-grid-link arrow-link" target="_blank" rel="noopener">
+ @svg('arrow')
+ <?php _ex('Read interactive version', 'Resource grid widget interactive version link text', 'cube') ?>
+ </a>
+ @endif
+ @if ($item['pdf'])
+ <a href="{{ $item['pdf'] }}" class="resource-grid-link arrow-link" target="_blank" rel="noopener">
+ @svg('arrow')
+ <?php _ex('Download PDF', 'Resource grid widget PDF link text', 'cube') ?>
+ </a>
+ @endif
+
+ </div>
</div>
- </div>
-@endforeach
+ @endforeach
+
+</div>