From: Stephen Cameron Date: Mon, 7 Feb 2022 18:33:58 +0000 (+0100) Subject: Done #4988 @5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=231ab449e265e131309221dc0011f4b7fe4f4f6e;p=pmi.git Done #4988 @5 --- diff --git a/resources/js/components/ProductsFilters.vue b/resources/js/components/ProductsFilters.vue index caba3bf..7853294 100644 --- a/resources/js/components/ProductsFilters.vue +++ b/resources/js/components/ProductsFilters.vue @@ -3,48 +3,59 @@
-
-
+

-

{{ filter.label }}

+

+ {{ filter.label }} + + + +

-
    -
  • + +
    - +
      +
    • -
      ({{ option.nb_products }})
      + -
    • -
    +
    ({{ option.nb_products }})
    -
    - - - -
    - {{ filter.prefix }} {{ filter.min }} {{ filter.unit }} - {{ filter.prefix }} {{ filter.max }} {{ filter.unit }} +
  • +
+ +
+ + + +
+ {{ filter.prefix }} {{ filter.min }} {{ filter.unit }} + {{ filter.prefix }} {{ filter.max }} {{ filter.unit }} +
@@ -176,6 +187,10 @@ productType: { required: true, }, + baseFilters: { + type: String, + default: '', + }, filterData: { required: true, }, @@ -190,6 +205,8 @@ data: () => ({ viewStyle: 'grid', filters: {}, + filterWrappers: [], // All the sets of filters in the accordion + currentFilterIndex: 0, // Index of the filter group that is open matches: {}, products: [], log: function (v) { @@ -302,13 +319,38 @@ this.viewStyle = localStorage.viewStyle; } + // Gather all the filter sets for the accordion + this.filterWrappers = this.$refs.filters.querySelectorAll('.filters-wrapper'); + + // Calculate the max-height of each filter set (required so accordion height animation can work) + this.filterWrappers.forEach(function(el) { + + let totalHeight = 0; + for (let i = 0; i < el.children.length; i++) { + totalHeight += el.children[i].clientHeight; + } + + el.style.maxHeight = totalHeight + 'px'; + }); + + // Find the first filter set that has pre-selected filters and open it + let initialFilterIndex = 0; + for (let fi = 0; fi < this.filterData.length; fi++) { + let id = this.filterData[fi].id; + if (this.filters[id].length > 0 && this.filterData[fi].type !== 'range') { + initialFilterIndex = fi; + break; + } + } + this.expandFilters(initialFilterIndex); + }, methods: { parseQuerystring() { const $this = this; - const querystring = window.baseFilters + '&' + location.search.substring(1); // Get querystring minus first character (?) + const querystring = this.baseFilters + '&' + location.search.substring(1); // Get querystring minus first character (?) if (querystring.length > 0) { querystring.split('&').forEach(function (pair) { @@ -377,7 +419,36 @@ } this.viewStyle = this.viewStyle === 'list' ? 'grid' : 'list'; }, + + expandFilters(index) { + // For the accordion animation to work, overflow:hidden must be set on the wrapping element. + // However, some filter elements like sliders don't display properly if the overflow is hidden + // (due to tooltips etc), so we need to set the overflow to visible on the open set of filters + // immediately *after* the CSS transition (300ms) ends. When a new filter set is opened, the + // overflow:visible override needs to be removed immediately, before the transition accordion + // animation begins... + let $this = this; + let previousIndex = this.currentFilterIndex; + this.filterWrappers[previousIndex].style.removeProperty('overflow'); + this.currentFilterIndex = index; + setTimeout(function() { + $this.filterWrappers[index].style.overflow = 'visible'; + }, 300); // Keep this value in sync with the CSS transition duration defined below! + }, }, } + + diff --git a/resources/views/pages/category.blade.php b/resources/views/pages/category.blade.php index acd3dc9..aee4462 100644 --- a/resources/views/pages/category.blade.php +++ b/resources/views/pages/category.blade.php @@ -1,9 +1,7 @@ @extends('layouts/app') @section('content') - + @intro(['padding' => 'pb-1v']) @@ -12,7 +10,8 @@ @if ($filters && $filter_results) - window.baseFilters = "{{$page->get('filter')}}"; - @intro(['padding' => 'pb-1v'])