EXTREMUM_web/base/static/js/features_to_vary.js
2024-11-15 20:50:36 +02:00

38 lines
1.5 KiB
JavaScript

// Select All / Deselect All Function
function selectAll(selectAll) {
const checkboxes = document.querySelectorAll('#featureList input[type="checkbox"]');
checkboxes.forEach(checkbox => {
checkbox.checked = selectAll;
});
}
// Search Function
if (document.getElementById('searchInput')) {
document.getElementById('searchInput').addEventListener('input', function () {
const searchTerm = this.value.toLowerCase();
const features = document.querySelectorAll('.feature-item');
features.forEach(feature => {
const label = feature.querySelector('label').textContent.toLowerCase();
if (label.includes(searchTerm)) {
feature.style.display = 'flex'; // Show matching feature
} else {
feature.style.display = 'none'; // Hide non-matching feature
}
});
});
}
// Sort by Importance Function
function sortByImportance() {
const featureList = document.getElementById('featureList');
const features = Array.from(document.querySelectorAll('.feature-item'));
features.sort((a, b) => {
const importanceA = parseFloat(a.querySelector('label span').textContent.replace(/[^\d.]/g, ''));
const importanceB = parseFloat(b.querySelector('label span').textContent.replace(/[^\d.]/g, ''));
return importanceB - importanceA;
});
// Append sorted elements back to the list
features.forEach(feature => featureList.appendChild(feature));
}