-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (61 loc) · 3.14 KB
/
script.js
File metadata and controls
62 lines (61 loc) · 3.14 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
document.addEventListener('DOMContentLoaded', () => {
const filterBtns = document.querySelectorAll('.filter-btn');
const cards = document.querySelectorAll('.card');
const modal = document.getElementById('previewModal');
const modalContentPreview = modal.querySelector('.modal-preview');
const modalTitle = document.getElementById('modalTitle');
const modalDescription = document.getElementById('modalDescription');
const modalCopyBtn = document.getElementById('modalCopyBtn');
const closeModalBtn = modal.querySelector('.close-btn');
const toggleThemeBtn = document.getElementById('toggleTheme');
let currentModalCSS = '';
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const filter = btn.getAttribute('data-filter');
cards.forEach(card => {
card.style.display = (filter === 'all' || card.getAttribute('data-category') === filter) ? 'block' : 'none';
});
});
});
cards.forEach(card => {
card.addEventListener('click', e => {
if (e.target.classList.contains('copy-btn')) return;
const preview = card.querySelector('.preview').innerHTML;
const title = card.querySelector('.card-info h3').innerText;
const description = card.querySelector('.card-info p').innerText;
currentModalCSS = card.querySelector('.copy-btn').getAttribute('data-code');
modalContentPreview.innerHTML = preview;
modalTitle.innerText = title;
modalDescription.innerText = description;
modal.style.display = 'flex';
});
});
closeModalBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
window.addEventListener('click', e => {
if (e.target === modal) modal.style.display = 'none';
});
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', e => {
e.stopPropagation();
const cssCode = btn.getAttribute('data-code');
copyToClipboard(cssCode);
});
});
modalCopyBtn.addEventListener('click', () => {
copyToClipboard(currentModalCSS);
});
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('CSS code copied to clipboard!');
}).catch(err => {
alert('Failed
to copy text: ' + err); });
}
toggleThemeBtn.addEventListener('click', () => {
document.body.classList.toggle('dark');
});
});