1 changed files with 41 additions and 45 deletions
@ -1,46 +1,42 @@ |
|||||||
(function (Drupal) { |
(function (Drupal) { // Select the parent container
|
||||||
'use strict'; // Good practice for stricter JS parsing
|
const sidebar = document.querySelector('.region--sidebar'); // Check if the element exists
|
||||||
|
if (sidebar) { |
||||||
document.addEventListener('DOMContentLoaded', function () { |
// Get all direct children
|
||||||
// Select the parent container
|
const children = Array.from(sidebar.children);// Create the wrapper div
|
||||||
const sidebar = document.querySelector('.region--sidebar'); |
const wrapper = document.createElement('div'); |
||||||
|
wrapper.classList.add('facet-wrapper'); |
||||||
// Check if the element exists
|
|
||||||
if (sidebar) { |
// Move each child into the wrapper
|
||||||
// Get all direct children
|
children.forEach(child => { |
||||||
const children = Array.from(sidebar.children); |
wrapper.appendChild(child); |
||||||
|
}); |
||||||
if (children.length > 0) { // Optional: Skip if no children
|
|
||||||
// Create the wrapper div
|
// Append the wrapper back to the sidebar (replacing the original children)
|
||||||
const wrapper = document.createElement('div'); |
sidebar.appendChild(wrapper); } |
||||||
wrapper.classList.add('facet-wrapper'); |
// Select the parent container
|
||||||
|
//const sidebar = document.querySelector('.region--sidebar'); // Check if the element exists
|
||||||
// Move each child into the wrapper
|
if (sidebar) { |
||||||
children.forEach(child => { |
// Select the existing wrapper
|
||||||
wrapper.appendChild(child); |
const wrapper = sidebar.querySelector('.facet-wrapper');// Check if the wrapper exists
|
||||||
}); |
if (wrapper) { |
||||||
|
// Create the button element
|
||||||
// Append the wrapper back to the sidebar
|
const button = document.createElement('button'); |
||||||
sidebar.appendChild(wrapper); |
button.id = 'toggle-facets'; |
||||||
|
button.textContent = 'Search the Collection'; |
||||||
// Create the button element
|
|
||||||
const button = document.createElement('button'); |
// Insert the button before the wrapper
|
||||||
button.id = 'toggle-facets'; |
sidebar.insertBefore(button, wrapper); |
||||||
button.textContent = 'Search the Collection'; |
} } |
||||||
|
document.addEventListener("DOMContentLoaded", function () { |
||||||
// Insert the button before the wrapper
|
const toggleButton = document.getElementById("toggle-facets"); |
||||||
sidebar.insertBefore(button, wrapper); |
const facetWrapper = document.querySelector( |
||||||
|
".region--sidebar .facet-wrapper" |
||||||
// Wire up the toggle (now after elements exist)
|
);if (toggleButton && facetWrapper) { |
||||||
const toggleButton = document.getElementById('toggle-facets'); |
toggleButton.addEventListener("click", function () { |
||||||
if (toggleButton) { // Extra safety, though it should exist
|
const isHidden = |
||||||
toggleButton.addEventListener('click', function () { |
facetWrapper.style.display === "none" || !facetWrapper.style.display; // Accounts for CSS default
|
||||||
const computedStyle = window.getComputedStyle(facetWrapper); |
facetWrapper.style.display = isHidden ? "block" : "none"; |
||||||
const isHidden = computedStyle.display === 'none'; |
}); |
||||||
facetWrapper.style.display = isHidden ? 'block' : 'none'; |
} }); |
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
}); |
|
||||||
})(Drupal); |
})(Drupal); |
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue