-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (32 loc) · 1.2 KB
/
Copy pathindex.js
File metadata and controls
39 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(() => {
const search = document.querySelector('#search');
const cards = [...document.querySelectorAll('.project')];
const count = document.querySelector('#count');
const empty = document.querySelector('#empty');
const year = document.querySelector('#year');
year.textContent = new Date().getFullYear();
const normalize = (value) => value
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.trim();
const update = () => {
const query = normalize(search.value);
let visible = 0;
cards.forEach((card) => {
const content = normalize(`${card.textContent} ${card.dataset.search || ''}`);
const match = !query || content.includes(query);
card.hidden = !match;
if (match) visible += 1;
});
count.textContent = visible;
empty.classList.toggle('show', visible === 0);
};
search.addEventListener('input', update);
document.addEventListener('keydown', (event) => {
if (event.key === '/' && document.activeElement !== search) {
event.preventDefault();
search.focus();
}
});
})();