From f51ba26b15697f6c9430f62c3a65141ab87ec092 Mon Sep 17 00:00:00 2001 From: "stephen@cubedesigners.com" Date: Thu, 12 Mar 2020 19:11:38 +0000 Subject: [PATCH] WIP #3470 @7 --- .../src/Elementor/Widgets/ResourceGrid.php | 45 ++++++++++++-- .../physioassist/resources/assets/config.json | 5 +- .../assets/scripts/resource-carousel.js | 14 +++++ .../styles/widgets/resource-carousel.styl | 39 ++++++++++++ .../views/widgets/resource-carousel.blade.php | 62 +++++++++++++++++++ .../views/widgets/resource-grid.blade.php | 42 +++++++------ 6 files changed, 183 insertions(+), 24 deletions(-) create mode 100644 wp-content/themes/physioassist/resources/assets/scripts/resource-carousel.js create mode 100644 wp-content/themes/physioassist/resources/assets/styles/widgets/resource-carousel.styl create mode 100644 wp-content/themes/physioassist/resources/views/widgets/resource-carousel.blade.php diff --git a/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/ResourceGrid.php b/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/ResourceGrid.php index 9c6c3817..8432bda1 100644 --- a/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/ResourceGrid.php +++ b/wp-content/mu-plugins/physioassist/src/Elementor/Widgets/ResourceGrid.php @@ -40,7 +40,18 @@ class ResourceGrid extends Widget_Base { * @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. @@ -58,6 +69,21 @@ class ResourceGrid extends Widget_Base { ] ); + $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', [ @@ -83,6 +109,9 @@ class ResourceGrid extends Widget_Base { // 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' ), @@ -110,11 +139,14 @@ class ResourceGrid extends Widget_Base { */ protected function render() { + $display_type = $this->get_settings('type'); $items = $this->get_settings('items'); - $html = \App\template('widgets/resource-grid', compact('items')); - - echo '
'. $html .'
'; + if ($display_type == 'carousel') { + echo \App\template('widgets/resource-carousel', compact('items')); + } else { + echo \App\template('widgets/resource-grid', compact('items')); + } } /** @@ -125,6 +157,10 @@ class ResourceGrid extends Widget_Base { * @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() { ?>
@@ -164,5 +200,6 @@ class ResourceGrid extends Widget_Base {
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 + + diff --git a/wp-content/themes/physioassist/resources/views/widgets/resource-grid.blade.php b/wp-content/themes/physioassist/resources/views/widgets/resource-grid.blade.php index 7bd0eb12..40a41c15 100644 --- a/wp-content/themes/physioassist/resources/views/widgets/resource-grid.blade.php +++ b/wp-content/themes/physioassist/resources/views/widgets/resource-grid.blade.php @@ -1,27 +1,31 @@ -@foreach ($items as $item) +
-
- @image($item['image']['id'], 'full', ['class' => 'resource-grid-image']) + @foreach ($items as $item) -
+
+ @image($item['image']['id'], 'full', ['class' => 'resource-grid-image']) -

{{ $item['title'] }}

+
- @if ($item['interactive_version']) - - @svg('arrow') - - - @endif +

{{ $item['title'] }}

- @if ($item['pdf']) - - @svg('arrow') - - - @endif + @if ($item['interactive_version']) + + @svg('arrow') + + + @endif + @if ($item['pdf']) + + @svg('arrow') + + + @endif + +
-
-@endforeach + @endforeach + +
-- 2.39.5