From 7316238f16655bd127b04476bbf7864b27f940f9 Mon Sep 17 00:00:00 2001 From: Sivaldo Date: Sat, 13 Jun 2026 19:20:23 -0300 Subject: Commit inicial --- static/home-filter.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 static/home-filter.js (limited to 'static/home-filter.js') diff --git a/static/home-filter.js b/static/home-filter.js new file mode 100644 index 0000000..b2d1a47 --- /dev/null +++ b/static/home-filter.js @@ -0,0 +1,72 @@ +/** + * Home Filter — filtra disciplinas conforme você digita + * Só funciona quando há itens [data-filterable] na página + */ +document.addEventListener('DOMContentLoaded', () => { + const items = document.querySelectorAll('[data-filterable]'); + if (!items.length) return; + + // Cria campo de busca + const wrap = document.createElement('div'); + wrap.className = 'filter-container'; + wrap.innerHTML = ` + + + `; + + // Insere antes do disc-grid dentro do
+ const grid = document.querySelector('.disc-grid'); + if (grid) { + grid.parentNode.insertBefore(wrap, grid); + } else { + const main = document.querySelector('main'); + if (main) main.insertBefore(wrap, main.firstChild); + } + + const input = document.getElementById('home-filter'); + const count = document.getElementById('filter-count'); + + // Normaliza texto para comparação (remove acentos, maiúsculas) + function normalize(str) { + return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(); + } + + input.addEventListener('input', () => { + const q = normalize(input.value.trim()); + let visible = 0; + + items.forEach(item => { + const text = normalize(item.textContent); + const match = !q || text.includes(q); + item.style.display = match ? '' : 'none'; + if (match) visible++; + }); + + count.textContent = q ? `${visible} resultado${visible !== 1 ? 's' : ''}` : ''; + }); + + // Esc limpa e desfoca + input.addEventListener('keydown', e => { + if (e.key === 'Escape') { + input.value = ''; + input.dispatchEvent(new Event('input')); + input.blur(); + } + }); + + // Foco automático na home com / ou Ctrl+K + document.addEventListener('keydown', e => { + if ((e.key === '/' || (e.ctrlKey && e.key === 'k')) && document.activeElement !== input) { + e.preventDefault(); + input.focus(); + } + }); +}); -- cgit v1.2.3