Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi facet selection - Record last user state #4109

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions themes/bootstrap3/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +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 local_storage_variable_name = 'multiFacetsSelection';

/**
* Normalize a filter value
Expand Down Expand Up @@ -297,9 +298,21 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
toggleSelectedFacetStyle(elem);
}

function saveUserSelectionLastState(state) {
localStorage.setItem(local_storage_variable_name, state ? 'true' : 'false');
}

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

function toggleMultiFacetsSelection(enable) {
if (typeof enable !== 'undefined') {
if (isMultiFacetsSelectionActivated === enable) {
return;
}
isMultiFacetsSelectionActivated = enable;
rominail marked this conversation as resolved.
Show resolved Hide resolved
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 Down Expand Up @@ -338,6 +351,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(getUserSelectionLastState());
}
// Listener on apply filters button
const applyElem = context.querySelector('.js-apply-multi-facets-selection');
Expand Down
14 changes: 14 additions & 0 deletions themes/bootstrap5/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +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 local_storage_variable_name = 'multiFacetsSelection';

/**
* Normalize a filter value
Expand Down Expand Up @@ -297,9 +298,21 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
toggleSelectedFacetStyle(elem);
}

function saveUserSelectionLastState(state) {
localStorage.setItem(local_storage_variable_name, state ? 'true' : 'false');
}

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

function toggleMultiFacetsSelection(enable) {
if (typeof enable !== 'undefined') {
if (isMultiFacetsSelectionActivated === enable) {
return;
}
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 Down Expand Up @@ -338,6 +351,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(getUserSelectionLastState());
}
// Listener on apply filters button
const applyElem = context.querySelector('.js-apply-multi-facets-selection');
Expand Down
Loading