45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
document.querySelectorAll('[data-auto-toast]').forEach((element) => {
|
|
const toast = new bootstrap.Toast(element, { delay: 3200 });
|
|
toast.show();
|
|
});
|
|
|
|
document.querySelectorAll('[data-copy-text]').forEach((button) => {
|
|
button.addEventListener('click', async () => {
|
|
const text = button.getAttribute('data-copy-text') || '';
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
const original = button.textContent;
|
|
button.textContent = 'Copied';
|
|
setTimeout(() => {
|
|
button.textContent = original;
|
|
}, 1200);
|
|
} catch (error) {
|
|
console.error('Copy failed', error);
|
|
}
|
|
});
|
|
});
|
|
|
|
const searchInput = document.querySelector('[data-subject-search]');
|
|
if (searchInput) {
|
|
const items = Array.from(document.querySelectorAll('.subject-grid-item'));
|
|
const emptyState = document.querySelector('[data-empty-state]');
|
|
|
|
const applyFilter = () => {
|
|
const query = searchInput.value.trim().toLowerCase();
|
|
let visible = 0;
|
|
items.forEach((item) => {
|
|
const text = item.getAttribute('data-filter-text') || '';
|
|
const match = text.includes(query);
|
|
item.classList.toggle('d-none', !match);
|
|
if (match) visible += 1;
|
|
});
|
|
if (emptyState) {
|
|
emptyState.classList.toggle('d-none', visible !== 0);
|
|
}
|
|
};
|
|
|
|
searchInput.addEventListener('input', applyFilter);
|
|
}
|
|
});
|