MediaWiki:CRT Search.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
* EveryCRT Advanced Search | * EveryCRT Advanced Search | ||
* Server-side faceted search using Semantic MediaWiki API | * Server-side faceted search using Semantic MediaWiki API | ||
*/ | */ | ||
(function() { | (function() { | ||
| Line 21: | Line 13: | ||
var totalResults = 0; | var totalResults = 0; | ||
var isLoading = false; | var isLoading = false; | ||
var searchDebounceTimer = null; | |||
var DEBOUNCE_DELAY = 400; | |||
// Filter configuration - defines all available filters | // Filter configuration - defines all available filters | ||
| Line 194: | Line 188: | ||
} | } | ||
}; | }; | ||
/** | |||
* Trigger search with debounce for text/number inputs | |||
*/ | |||
function triggerSearch(immediate) { | |||
if (searchDebounceTimer) { | |||
clearTimeout(searchDebounceTimer); | |||
} | |||
if (immediate) { | |||
currentOffset = 0; | |||
performSearch(); | |||
updateURL(); | |||
} else { | |||
searchDebounceTimer = setTimeout(function() { | |||
currentOffset = 0; | |||
performSearch(); | |||
updateURL(); | |||
}, DEBOUNCE_DELAY); | |||
} | |||
} | |||
/** | /** | ||
| Line 230: | Line 245: | ||
html += '<button type="button" class="crt-reset-btn" id="reset-filters">Reset All</button>'; | html += '<button type="button" class="crt-reset-btn" id="reset-filters">Reset All</button>'; | ||
html += '</div>'; | html += '</div>'; | ||
// Scrollable body for filter sections | |||
html += '<div class="crt-filters-body">'; | |||
// Build filter sections | // Build filter sections | ||
| Line 237: | Line 255: | ||
} | } | ||
html += '</div>'; // end crt-filters-body | |||
// Apply button (shown only on mobile) | |||
html += '<div class="crt-apply-filters">'; | html += '<div class="crt-apply-filters">'; | ||
html += '<button type="button" class="crt-apply-btn" id="apply-filters">Apply Filters</button>'; | html += '<button type="button" class="crt-apply-btn" id="apply-filters">Apply Filters</button>'; | ||
| Line 369: | Line 390: | ||
}); | }); | ||
// Apply filters button | // Apply filters button (mobile fallback) | ||
document.getElementById('apply-filters').addEventListener('click', function() { | document.getElementById('apply-filters').addEventListener('click', function() { | ||
currentOffset = 0; | currentOffset = 0; | ||
| Line 383: | Line 404: | ||
document.getElementById('reset-filters').addEventListener('click', resetFilters); | document.getElementById('reset-filters').addEventListener('click', resetFilters); | ||
// Sort change | // Sort change - immediate | ||
document.getElementById('sort-by').addEventListener('change', function() { | document.getElementById('sort-by').addEventListener('change', function() { | ||
triggerSearch(true); | |||
}); | }); | ||
| Line 404: | Line 423: | ||
}); | }); | ||
// | // Select change - immediate search | ||
document.querySelectorAll('.crt-filter- | document.querySelectorAll('.crt-filter-select').forEach(function(select) { | ||
select.addEventListener('change', function() { | |||
triggerSearch(true); | |||
}); | |||
}); | |||
// Number input change - debounced search | |||
document.querySelectorAll('.crt-filter-number').forEach(function(input) { | |||
input.addEventListener('input', function() { | |||
triggerSearch(false); | |||
}); | |||
input.addEventListener('keypress', function(e) { | input.addEventListener('keypress', function(e) { | ||
if (e.key === 'Enter') { | if (e.key === 'Enter') { | ||
triggerSearch(true); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
// | // Checkbox change - immediate search | ||
document.querySelectorAll('.crt-filter- | document.querySelectorAll('.crt-filter-checkbox').forEach(function(checkbox) { | ||
checkbox.addEventListener('change', function() { | |||
triggerSearch(true); | |||
}); | }); | ||
}); | }); | ||
| Line 519: | Line 543: | ||
tag.remove(); | tag.remove(); | ||
updateMultiselectDropdown(ms, ms.dataset.filter, ms.querySelector('.crt-multiselect-input').value); | updateMultiselectDropdown(ms, ms.dataset.filter, ms.querySelector('.crt-multiselect-input').value); | ||
triggerSearch(true); | |||
}); | }); | ||
selectedContainer.appendChild(tag); | selectedContainer.appendChild(tag); | ||
| Line 524: | Line 549: | ||
updateMultiselectDropdown(ms, ms.dataset.filter, ms.querySelector('.crt-multiselect-input').value); | updateMultiselectDropdown(ms, ms.dataset.filter, ms.querySelector('.crt-multiselect-input').value); | ||
triggerSearch(true); | |||
} | } | ||
| Line 765: | Line 791: | ||
} | } | ||
triggerSearch(true); | |||
} | } | ||
| Line 1,311: | Line 1,335: | ||
e.stopPropagation(); | e.stopPropagation(); | ||
tag.remove(); | tag.remove(); | ||
triggerSearch(true); | |||
}); | }); | ||
selectedContainer.appendChild(tag); | selectedContainer.appendChild(tag); | ||