-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
93 lines (79 loc) · 3.57 KB
/
Copy pathscript.js
File metadata and controls
93 lines (79 loc) · 3.57 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// script.js
document.addEventListener('DOMContentLoaded', function() {
// ===== Theme Toggle =====
const themeToggle = document.getElementById('theme-toggle');
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark');
if (themeToggle) themeToggle.textContent = '☀️';
}
if (themeToggle) {
themeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark');
const isDark = document.body.classList.contains('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
this.textContent = isDark ? '☀️' : '🌙';
});
}
// ===== Sidebar Toggle (Mobile) =====
const menuToggle = document.getElementById('menu-toggle');
const closeSidebar = document.getElementById('close-sidebar');
const sidebar = document.getElementById('sidebar');
function openSidebar() {
if (sidebar) sidebar.classList.add('open-mobile');
}
function closeSidebarFunc() {
if (sidebar) sidebar.classList.remove('open-mobile');
}
if (menuToggle) menuToggle.addEventListener('click', openSidebar);
if (closeSidebar) closeSidebar.addEventListener('click', closeSidebarFunc);
// Close sidebar when clicking outside on mobile (if open)
document.addEventListener('click', function(e) {
if (window.innerWidth <= 768 && sidebar && sidebar.classList.contains('open-mobile')) {
const isClickInside = sidebar.contains(e.target) || menuToggle?.contains(e.target);
if (!isClickInside) {
closeSidebarFunc();
}
}
});
// ===== Image Lightbox =====
window.openImage = function(src) {
const lightbox = document.getElementById('lightbox');
const lightboxImg = document.getElementById('lightbox-img');
if (lightbox && lightboxImg) {
lightboxImg.src = src;
lightbox.style.display = 'flex';
}
};
// Close lightbox on click (already set inline, but also allow escape)
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
const lightbox = document.getElementById('lightbox');
if (lightbox) lightbox.style.display = 'none';
}
});
// ===== File Input - Show File Name =====
const fileInput = document.querySelector('input[type="file"][name="file"]');
const fileNameDisplay = document.getElementById('file-name-display');
if (fileInput && fileNameDisplay) {
fileInput.addEventListener('change', function() {
if (this.files && this.files.length > 0) {
fileNameDisplay.textContent = this.files[0].name + ' (' + Math.round(this.files[0].size / 1024) + ' KB)';
} else {
fileNameDisplay.textContent = '';
}
});
}
// ===== Auto-scroll chat to bottom =====
const messagesContainer = document.getElementById('messages');
if (messagesContainer) {
// Scroll to bottom on load
messagesContainer.scrollTop = messagesContainer.scrollHeight;
// Optionally observe new messages (if needed, but not critical for standard load)
// For simplicity, we just scroll on load. If messages are added via AJAX later, adjust.
}
// ===== Handle logout form (prevent default) =====
// The logout link triggers a hidden form submission. We handle it via inline onclick.
// No extra JS needed.
// ===== (Optional) Auto-resize textarea? Not needed since we have input type="text" =====
});