forked from Ctoic/Lisbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshare.js
More file actions
66 lines (59 loc) · 1.97 KB
/
share.js
File metadata and controls
66 lines (59 loc) · 1.97 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
63
64
65
66
document.addEventListener('DOMContentLoaded', function() {
const shareBtn = document.getElementById('shareBtn');
const shareModal = document.getElementById('shareModal');
const closeShareModal = document.getElementById('closeShareModal');
const copyLinkBtn = document.getElementById('copyLinkBtn');
const shareLink = document.getElementById('shareLink');
const toast = document.getElementById('toast');
// Open share modal
if (shareBtn) {
shareBtn.addEventListener('click', function() {
shareModal.classList.remove('hidden');
// In a real app, you would set the current audiobook's details here
document.getElementById('shareBookTitle').textContent = 'The Great Audiobook';
document.getElementById('shareBookAuthor').textContent = 'Author Name';
});
}
// Close share modal
if (closeShareModal) {
closeShareModal.addEventListener('click', function() {
shareModal.classList.add('hidden');
});
}
// Close modal when clicking outside
if (shareModal) {
shareModal.addEventListener('click', function(e) {
if (e.target === shareModal) {
shareModal.classList.add('hidden');
}
});
}
// Copy link to clipboard
if (copyLinkBtn) {
copyLinkBtn.addEventListener('click', async function() {
try {
await navigator.clipboard.writeText(shareLink.value);
showToast();
} catch (err) {
// Fallback for browsers that don't support clipboard API
shareLink.select();
document.execCommand('copy');
showToast();
}
});
}
// Show toast notification
function showToast() {
if (!toast) return;
toast.classList.remove('hidden');
setTimeout(() => {
toast.classList.add('hidden');
}, 3000);
}
// Close modal with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && shareModal && !shareModal.classList.contains('hidden')) {
shareModal.classList.add('hidden');
}
});
});