Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Filtering Query Strings Support
  • Loading branch information
AlexDawsonUK committed Nov 13, 2025
commit 844bd534d8b100882968b6568bafa2ff433ce2ed
35 changes: 34 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,39 @@ <h2 class="introductory">Content Filters</h2>
document.querySelectorAll(attr).forEach(function (elem) {
elem.classList.remove(name); }); }
return(name + attr); }
function queryFilter() {
// Query String Filtering onLoad
const queryParams = window.location.search.substring(1).toLowerCase().split('&');
const labels = document.querySelectorAll('.filter label');
document.querySelectorAll('.filter label').forEach(label => {
const id = label.childNodes[0].id || ''; let result;
const text = label.textContent.trim().toLowerCase().replace(/\s+/g, '-').replace(/\(.*?\)/g, '').replace(/-$/, '');
if (["high", "medium", "low"].includes(text)) {
result = `${id}-${text}`; } else { result = `${text}`; }
result = "filter=" + result;
if (queryParams.includes(result)) {
const input = label.querySelector('input');
if (input) { input.checked = true; } else { input.checked = false; } } });
const clickEvent = new MouseEvent('click', { view: window, bubbles: true, cancelable: true });
document.dispatchEvent(clickEvent); }
function queryString() {
document.querySelectorAll('.filter input').forEach(input => {
input.addEventListener('change', updateQueryString); });
document.addEventListener('reset', function(event) { setTimeout(updateQueryString, 0); }); }
function getQueryValue(input) {
let labelText = input.parentElement.textContent.trim().toLowerCase().toLowerCase().replace(/\s+/g, '-').replace(/\(.*?\)/g, '').replace(/-$/, '');
if (["high", "medium", "low"].includes(labelText)) {
return `${input.id}-${labelText}`;
} else { return `${labelText}`; }
}
function updateQueryString() {
const url = new URL(window.location);
const params = new URLSearchParams(url.search);
params.delete('filter');
document.querySelectorAll('.filter input').forEach(input => {
if (input.checked) { const value = getQueryValue(input); params.append('filter', value); } });
window.history.replaceState({}, '', `${url.pathname}?${params.toString()}`); }
window.addEventListener('DOMContentLoaded', () => { queryFilter(); queryString(); });
</script>
<script class="remove">
var respecConfig = {
Expand Down Expand Up @@ -345,7 +378,7 @@ <h2 class="introductory">Content Filters</h2>
noRecTrack: true,
shortName: "web-sustainability-guidelines",
latestVersion: "https://www.w3.org/TR/web-sustainability-guidelines/",
postProcess: [authorRef, htmlInsert, addFilter]
postProcess: [authorRef, htmlInsert, addFilter, queryFilter, queryString]
}
</script>
</head>
Expand Down