Skip to content

Commit

Permalink
Merge branch 'main' into cookbook-gallery-216
Browse files Browse the repository at this point in the history
  • Loading branch information
erogluorhan authored Jan 9, 2025
2 parents 7184154 + a22b1e3 commit c46a722
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
26 changes: 19 additions & 7 deletions site/_static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ function getClassOfCheckedCheckboxes(checkboxes) {
function change() {
console.log("Change event fired.");
var domainsCbs = document.querySelectorAll(".domains input[type='checkbox']");
var eventsCbs = document.querySelectorAll(".events input[type='checkbox']");
var packagesCbs = document.querySelectorAll(".packages input[type='checkbox']");

var domainTags = getClassOfCheckedCheckboxes(domainsCbs);
var eventTags = getClassOfCheckedCheckboxes(eventsCbs);
var packageTags = getClassOfCheckedCheckboxes(packagesCbs);

var filters = {
domains: domainTags,
events: eventTags,
packages: packageTags
};

Expand All @@ -31,13 +34,22 @@ function filterResults(filters) {
rElems.forEach(function (el) {
var isVisible = true; // Assume visible by default

// Check if the element has any domain or package filter
if (filters.domains.length > 0 || filters.packages.length > 0) {
var hasMatchingDomain = filters.domains.length === 0 || filters.domains.some(domain => el.classList.contains(domain));
var hasMatchingPackage = filters.packages.length === 0 || filters.packages.some(package => el.classList.contains(package));
// Check for matching domains
if (filters.domains.length > 0) {
var hasMatchingDomain = filters.domains.some(domain => el.classList.contains(domain));
isVisible = isVisible && hasMatchingDomain;
}

// Check for matching events
if (filters.events.length > 0) {
var hasMatchingEvent = filters.events.some(event => el.classList.contains(event));
isVisible = isVisible && hasMatchingEvent;
}

// The element should be visible if it matches any filter within each category
isVisible = hasMatchingDomain && hasMatchingPackage;
// Check for matching packages
if (filters.packages.length > 0) {
var hasMatchingPackage = filters.packages.some(package => el.classList.contains(package));
isVisible = isVisible && hasMatchingPackage;
}

// Toggle visibility based on the result
Expand Down Expand Up @@ -88,4 +100,4 @@ function clearCbs() {
// Initial call to set up correct margins when the page loads
document.addEventListener('DOMContentLoaded', updateMargins);

console.log("Script loaded.");
console.log("Script loaded.");
3 changes: 2 additions & 1 deletion site/cookbook_gallery.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ na-cordex-viz-cookbook
eofs-cookbook
ocean-bgc-cookbook
paleoPCA-cookbook
wavelet-cookbook
esgf-cookbook
wavelet-cookbook

0 comments on commit c46a722

Please sign in to comment.