Skip to content

Commit

Permalink
Add function to detect multi facet selection configuration (#4051)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuomaJuha authored Nov 4, 2024
1 parent 2412f1d commit 5af280a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
26 changes: 19 additions & 7 deletions themes/bootstrap3/js/facets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
/*global multiFacetsSelectionEnabled, VuFind */
/*global VuFind, multiFacetsSelectionEnabled */

/**
* Returns if multiFacetsSelectionEnabled is set. Fallback if the value is missing for false
*
* @type {Function} Function to check for multiFacetsSelectionEnabled
*/
let isMultiFacetsSelectionEnabled = () => {
if (typeof multiFacetsSelectionEnabled === "undefined") {
return false;
}
return multiFacetsSelectionEnabled;
};

/* --- Facet List --- */
VuFind.register('facetList', function FacetList() {
Expand Down Expand Up @@ -393,7 +405,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
}

function init() {
if (multiFacetsSelectionEnabled !== true) {
if (!isMultiFacetsSelectionEnabled()) {
return;
}
if (defaultContext === undefined) {
Expand Down Expand Up @@ -492,18 +504,18 @@ VuFind.register('sideFacets', function SideFacets() {
}
} else if (typeof facetData.html !== 'undefined') {
$facetContainer.html(VuFind.updateCspNonce(facetData.html));
if (multiFacetsSelectionEnabled !== true) {
if (!isMultiFacetsSelectionEnabled()) {
activateFacetBlocking($facetContainer);
}
}
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.applyClickHandling($facetContainer.get()[0]);
}
$facetContainer.find('.facet-load-indicator').remove();
});
VuFind.lightbox.bind($('.sidebar'));
VuFind.emit('VuFind.sidefacets.loaded');
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.rangeSelectorInit();
}
})
Expand All @@ -525,7 +537,7 @@ VuFind.register('sideFacets', function SideFacets() {
}

function init() {
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.registerCallbackOnApply(showLoadingOverlay);
VuFind.multiFacetsSelection.registerCallbackWhenDeactivated(showLoadingOverlay);
} else {
Expand Down Expand Up @@ -600,7 +612,7 @@ VuFind.register('lightbox_facets', function LightboxFacets() {
}

function setup() {
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
let elem = document.getElementById('facet-info-result').children[0];
VuFind.multiFacetsSelection.applyClickHandling(elem);
VuFind.multiFacetsSelection.addSwitchAndButton(elem);
Expand Down
26 changes: 19 additions & 7 deletions themes/bootstrap5/js/facets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
/*global multiFacetsSelectionEnabled, VuFind */
/*global VuFind, multiFacetsSelectionEnabled */

/**
* Returns if multiFacetsSelectionEnabled is set. Fallback if the value is missing for false
*
* @type {Function} Function to check for multiFacetsSelectionEnabled
*/
let isMultiFacetsSelectionEnabled = () => {
if (typeof multiFacetsSelectionEnabled === "undefined") {
return false;
}
return multiFacetsSelectionEnabled;
};

/* --- Facet List --- */
VuFind.register('facetList', function FacetList() {
Expand Down Expand Up @@ -393,7 +405,7 @@ VuFind.register('multiFacetsSelection', function multiFacetsSelection() {
}

function init() {
if (multiFacetsSelectionEnabled !== true) {
if (!isMultiFacetsSelectionEnabled()) {
return;
}
if (defaultContext === undefined) {
Expand Down Expand Up @@ -492,18 +504,18 @@ VuFind.register('sideFacets', function SideFacets() {
}
} else if (typeof facetData.html !== 'undefined') {
$facetContainer.html(VuFind.updateCspNonce(facetData.html));
if (multiFacetsSelectionEnabled !== true) {
if (!isMultiFacetsSelectionEnabled()) {
activateFacetBlocking($facetContainer);
}
}
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.applyClickHandling($facetContainer.get()[0]);
}
$facetContainer.find('.facet-load-indicator').remove();
});
VuFind.lightbox.bind($('.sidebar'));
VuFind.emit('VuFind.sidefacets.loaded');
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.rangeSelectorInit();
}
})
Expand All @@ -525,7 +537,7 @@ VuFind.register('sideFacets', function SideFacets() {
}

function init() {
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
VuFind.multiFacetsSelection.registerCallbackOnApply(showLoadingOverlay);
VuFind.multiFacetsSelection.registerCallbackWhenDeactivated(showLoadingOverlay);
} else {
Expand Down Expand Up @@ -600,7 +612,7 @@ VuFind.register('lightbox_facets', function LightboxFacets() {
}

function setup() {
if (multiFacetsSelectionEnabled === true) {
if (isMultiFacetsSelectionEnabled()) {
let elem = document.getElementById('facet-info-result').children[0];
VuFind.multiFacetsSelection.applyClickHandling(elem);
VuFind.multiFacetsSelection.addSwitchAndButton(elem);
Expand Down

0 comments on commit 5af280a

Please sign in to comment.