diff --git a/skenografia.info.yml b/skenografia.info.yml index 35eac739..e0349adb 100644 --- a/skenografia.info.yml +++ b/skenografia.info.yml @@ -18,10 +18,6 @@ libraries: # - bootstrap_italia/load-fonts - skenografia/version -# Check these settings, they must match the "libraries" choices. -# ckeditor_stylesheets: -# - dist/css/bootstrap-italia.min.css - ckeditor5-stylesheets: - /libraries/ouitoulia-skenografia/css/ckeditor5.min.css diff --git a/skenografia.libraries.yml b/skenografia.libraries.yml index ce6fe66d..82ec2c50 100755 --- a/skenografia.libraries.yml +++ b/skenografia.libraries.yml @@ -29,7 +29,17 @@ toc: - core/drupal - toc_js/tocjs -# Bootstrap-italia library if you use a CDN +# Skenografia search-filters +search-filters: + version: 2.3.1 + js: + /libraries/ouitoulia-skenografia/js/search-api--submit-filters.min.js: { minified: true } + #dist/js/search-api--submit-filters.min.js: { } + dependencies: + - core/drupal + - core/once + +# theme version for compliance C.SC.1.3 version: version: 2.3.1 css: diff --git a/src/js/custom/search-api--submit-filters.js b/src/js/custom/search-api--submit-filters.js new file mode 100644 index 00000000..2508e47d --- /dev/null +++ b/src/js/custom/search-api--submit-filters.js @@ -0,0 +1,44 @@ +(function (Drupal, once) { + 'use strict'; + + Drupal.behaviors.searchAPISubmitFilters = { + attach: function (context, settings) { + // Tutti i submit nella form di ricerca o nelle form di ricerca. + let submitButtons = once('searchAPISubmitFilters', context.querySelectorAll('[data-search-api-submit-filters]')); + + // Intercetto l'evento click sui submit. + submitButtons.forEach(function(button) { + button.addEventListener('click', function(event) { + // Evito il submit per poter fare cose. + event.preventDefault(); + + // La form su cui operare + let form = button.closest('form'); + + if (form) { + // Prendo i valori dei filtri dagli attributi del submit. + let values = JSON.parse(button.getAttribute('data-search-api-submit-filters')); + + // Il nodo, o i nodi, a cui devo aggiungere le informazioni sui filtri da applicare. + let filters = form.querySelectorAll('[data-search-filter-id]'); + + // Aggiunta dei filtri. + filters.forEach(function(filter) { + values.forEach(function(value) { + let input = document.createElement('input'); + input.type = 'hidden'; + input.name = 'f[]'; + input.value = value; + filter.parentNode.insertBefore(input, filter); + }); + }); + + form.submit(); + } + + }); + }); + } + }; + +})(Drupal,once); diff --git a/templates/views/search/input--submit--id--edit-submit-risultati-ricerca.html.twig b/templates/views/search/input--submit--id--edit-submit-risultati-ricerca.html.twig index 69f08d0b..fc67cae2 100644 --- a/templates/views/search/input--submit--id--edit-submit-risultati-ricerca.html.twig +++ b/templates/views/search/input--submit--id--edit-submit-risultati-ricerca.html.twig @@ -13,6 +13,7 @@ */ #} {% apply spaceless %} + {{ attach_library('skenografia/search-filters') }}
{% set _attributes = attributes .removeClass('btn-primary') @@ -21,30 +22,42 @@ %} Cerca in tutto il sito Cerca nella sezione Scuola + Cerca nei + Servizi + + + Cerca tra le {{ 'Novità' }} @@ -52,37 +65,14 @@ - Cerca nei - Servizi - - - Cerca nella Didattica - +
{% endapply %} - - diff --git a/webpack.common.js b/webpack.common.js index 699aeeff..b9edd7a9 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -12,7 +12,8 @@ module.exports = { entry: { "bootstrap-italia": [paths.src + '/js/index.js', paths.src + '/scss/theme.scss'], "ckeditor5": paths.src + '/scss/ckeditor5.scss', - "toc_js_loader": [paths.src + '/js/custom/toc_js.js'] + "toc_js_loader": [paths.src + '/js/custom/toc_js.js'], + "search-api--submit-filters": [paths.src + '/js/custom/search-api--submit-filters.js'] }, // Output