From 46ab87a1a584b63b839a262bcbaf7a672bd7a50a Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 31 Mar 2020 13:18:54 -0600 Subject: [PATCH] feat: announce filters once applied (resolves #130) (#241) --- app/Controllers/App.php | 19 +++++++++++++++++++ app/filters.php | 5 ++--- resources/assets/scripts/routes/archive.js | 11 ++++++++++- resources/views/layouts/app.blade.php | 6 +++++- resources/views/partials/filters.blade.php | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/Controllers/App.php b/app/Controllers/App.php index 078f455..ee5ec3c 100644 --- a/app/Controllers/App.php +++ b/app/Controllers/App.php @@ -68,6 +68,25 @@ public function queriedResourceTerms() return $terms; } + public function filterCount() + { + $count = 0; + global $wp_query; + if ($wp_query->tax_query) { + foreach ($wp_query->tax_query->queries as $value) { + foreach ($value['terms'] as $t) { + $count++; + } + } + } + if (isset($_GET['language'])) { + foreach ($_GET['language'] as $lang) { + $count++; + } + } + return $count; + } + public function availableLanguages() { if (function_exists('pll_the_languages') && function_exists('pll_current_language')) { diff --git a/app/filters.php b/app/filters.php index ae0a564..d380503 100644 --- a/app/filters.php +++ b/app/filters.php @@ -13,9 +13,8 @@ } } - /** Add class if sidebar is active */ - if (display_sidebar()) { - $classes[] = 'sidebar-primary'; + if (isset($_GET['filtered']) && $_GET['filtered'] === '1') { + $classes[] = 'filtered'; } /** Clean up class names for custom templates */ diff --git a/resources/assets/scripts/routes/archive.js b/resources/assets/scripts/routes/archive.js index 6d44937..621fb4d 100644 --- a/resources/assets/scripts/routes/archive.js +++ b/resources/assets/scripts/routes/archive.js @@ -3,7 +3,7 @@ import addNotification from '../util/addNotification'; import Cookies from 'cookies.js'; import Pinecone from '@platform-coop-toolkit/pinecone'; -import { __, sprintf } from '@wordpress/i18n'; +import { __, _n, sprintf } from '@wordpress/i18n'; import { speak } from '@wordpress/a11y'; export default { @@ -13,6 +13,15 @@ export default { const showFilters = document.querySelector( '#show-filters' ); const hideFilters = document.querySelector( '#hide-filters' ); + if (document.body.classList.contains('filtered')) { + const currentFilterCount = document.body.dataset.filters; + if ( currentFilterCount ) { + setTimeout(function() { + speak(sprintf(_n('%s filter applied. Resource list updated.', '%s filters applied. Resource list updated.', parseInt(currentFilterCount), 'coop-library'), currentFilterCount), 'assertive'); + }, 1000); + } + } + if ( showFilters && hideFilters && filterContainer ) { new Pinecone.FilterList( filterContainer, showFilters, hideFilters ); } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 6f17631..dcb44b3 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -1,7 +1,11 @@ @include('partials.head') - + @php do_action('get_header') @endphp @include('partials.header')
diff --git a/resources/views/partials/filters.blade.php b/resources/views/partials/filters.blade.php index 3eb87d6..fdb8d5a 100644 --- a/resources/views/partials/filters.blade.php +++ b/resources/views/partials/filters.blade.php @@ -1,6 +1,7 @@
+ @if(isset($_GET['s']))