фикс логики запуска
This commit is contained in:
1 parent
18744b7807
commit
a608eb60af
5 files changed
+59
-45
No files matched your search
-27
@@ -1,32 +1,5 @@
|
||||
const input = document.querySelector('#search');
|
||||
const sections = [...document.querySelectorAll('article section')];
|
||||
const status = document.querySelector('#search-status');
|
||||
const links = [...document.querySelectorAll('nav a')];
|
||||
|
||||
input.addEventListener('input', () => {
|
||||
const query = input.value.trim().toLocaleLowerCase('ru');
|
||||
let count = 0;
|
||||
sections.forEach((section, index) => {
|
||||
const matches = section.textContent.toLocaleLowerCase('ru').includes(query);
|
||||
section.hidden = !matches;
|
||||
links[index].hidden = !matches;
|
||||
if (matches) count++;
|
||||
});
|
||||
status.hidden = !query;
|
||||
status.textContent = count ? `Найдено разделов: ${count}` : 'Ничего не найдено. Попробуйте другой запрос.';
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === '/' && !event.ctrlKey && !event.metaKey && !['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName) && !document.activeElement.isContentEditable) {
|
||||
event.preventDefault();
|
||||
input.focus();
|
||||
}
|
||||
if (event.key === 'Escape' && document.activeElement === input) {
|
||||
input.value = '';
|
||||
input.dispatchEvent(new Event('input'));
|
||||
}
|
||||
});
|
||||
|
||||
function updateNavigation() {
|
||||
links.forEach(link => {
|
||||
if (link.hash === location.hash) link.setAttribute('aria-current', 'location');
|
||||
|
||||
Reference in new issue
Block a user