Skip to content

Commit

Permalink
Discussion changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rominail committed Dec 2, 2024
1 parent aaf958e commit ec04495
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions themes/bootstrap3/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
const activation_event = 'facet-selection-begin';
const deactivation_event = 'facet-selection-cancel';
const apply_event = 'facet-selection-done';
const localStorageVariableName = 'multiFacetsSelection';
const local_storage_variable_name = 'multiFacetsSelection';

/**
* Normalize a filter value
Expand Down Expand Up @@ -299,12 +299,17 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
}

function saveUserSelectionLastState(state) {
localStorage.setItem(localStorageVariableName, state);
localStorage.setItem(local_storage_variable_name, state);
}

function getUserSelectionLastState() {
return localStorage.getItem(local_storage_variable_name) === 'true';
}

function toggleMultiFacetsSelection(enable) {
if (typeof enable !== 'undefined') {
isMultiFacetsSelectionActivated = enable;
saveUserSelectionLastState(isMultiFacetsSelectionActivated);
}
document.querySelectorAll('.multi-facet-selection').forEach( el => el.classList.toggle('multi-facet-selection-active', isMultiFacetsSelectionActivated) );
const checkboxes = document.getElementsByClassName('js-user-selection-multi-filters');
Expand All @@ -318,7 +323,6 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
toggleSelectedFacetStyle(elem);
}
}
saveUserSelectionLastState(isMultiFacetsSelectionActivated);
const event = isMultiFacetsSelectionActivated ? activation_event : deactivation_event;
VuFind.emit(event);
}
Expand All @@ -344,7 +348,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
const activationElem = context.querySelector('.js-user-selection-multi-filters');
if (activationElem) {
activationElem.addEventListener('change', function multiFacetSelectionChange() { toggleMultiFacetsSelection(this.checked); } );
toggleMultiFacetsSelection(localStorage.getItem(localStorageVariableName) === 'true');
toggleMultiFacetsSelection(getUserSelectionLastState());
}
// Listener on apply filters button
const applyElem = context.querySelector('.js-apply-multi-facets-selection');
Expand Down

0 comments on commit ec04495

Please sign in to comment.