forked from ejbills/DockDoor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
336 lines (282 loc) · 11.7 KB
/
Copy pathscripts.js
File metadata and controls
336 lines (282 loc) · 11.7 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// DockDoor Website JavaScript
// Wait for DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
// Theme toggle functionality
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Check for saved theme preference or use preferred color scheme
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
body.classList.add('dark');
themeToggle.innerText = '☀️';
} else {
themeToggle.innerText = '🌙';
}
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark');
if (body.classList.contains('dark')) {
localStorage.setItem('theme', 'dark');
themeToggle.innerText = '☀️';
} else {
localStorage.setItem('theme', 'light');
themeToggle.innerText = '🌙';
}
});
// Mobile menu toggle
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
});
});
// FAQ accordion
const faqQuestions = document.querySelectorAll('.faq-question');
faqQuestions.forEach(question => {
question.addEventListener('click', () => {
const answer = question.nextElementSibling;
// Toggle active class on question and answer
question.classList.toggle('active');
answer.classList.toggle('active');
// Update icon
const icon = question.querySelector('i');
icon.textContent = question.classList.contains('active') ? '↑' : '↓';
});
});
// Slideshow functionality for customization sections
function setupSlideshow(slideshowId) {
const slideshow = document.getElementById(slideshowId);
if (!slideshow) return;
const track = slideshow.querySelector('.slideshow-track');
const slides = slideshow.querySelectorAll('.slideshow-slide');
const indicators = slideshow.querySelectorAll('.slideshow-indicator');
const prevBtn = slideshow.querySelector('[data-direction="prev"]');
const nextBtn = slideshow.querySelector('[data-direction="next"]');
let currentIndex = 0;
const slideCount = slides.length;
// Initialize
updateSlidePosition();
updateIndicators();
// Previous slide button
prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + slideCount) % slideCount;
updateSlidePosition();
updateIndicators();
});
// Next slide button
nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % slideCount;
updateSlidePosition();
updateIndicators();
});
// Indicator buttons
indicators.forEach((indicator, index) => {
indicator.addEventListener('click', () => {
currentIndex = index;
updateSlidePosition();
updateIndicators();
});
});
// Auto advance
let interval = setInterval(() => {
currentIndex = (currentIndex + 1) % slideCount;
updateSlidePosition();
updateIndicators();
}, 4000);
// Pause on hover
slideshow.addEventListener('mouseenter', () => {
clearInterval(interval);
});
// Resume on mouse leave
slideshow.addEventListener('mouseleave', () => {
interval = setInterval(() => {
currentIndex = (currentIndex + 1) % slideCount;
updateSlidePosition();
updateIndicators();
}, 4000);
});
// Update slide position
function updateSlidePosition() {
track.style.transform = `translateX(-${currentIndex * 100}%)`;
}
// Update indicators
function updateIndicators() {
indicators.forEach((indicator, index) => {
if (index === currentIndex) {
indicator.classList.add('active');
} else {
indicator.classList.remove('active');
}
});
}
}
// Set up all slideshows
setupSlideshow('window-switcher-slideshow');
setupSlideshow('dock-preview-slideshow');
// Video playback controls
function handleVideoPlayback() {
const videos = document.querySelectorAll('video');
if ('IntersectionObserver' in window) {
const videoObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.play();
} else {
entry.target.pause();
}
});
}, { threshold: 0.5 });
videos.forEach(video => {
videoObserver.observe(video);
});
} else {
// Fallback for browsers that don't support IntersectionObserver
videos.forEach(video => {
video.play();
});
}
}
// Initialize video playback
handleVideoPlayback();
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80, // Adjust for header height
behavior: 'smooth'
});
}
});
});
// Animation for elements when scrolling into view
function animateOnScroll() {
const elements = document.querySelectorAll('.feature-media-container, .special-feature-card, .customization-card, .settings-card, .large-preview-container, .comments-container, .download-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
elements.forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(20px)';
element.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(element);
});
}
// Initialize animations on scroll
if ('IntersectionObserver' in window) {
animateOnScroll();
}
// Donation Modal Logic
const donationModal = document.getElementById('donation-modal');
const donationLinks = document.querySelectorAll('.donation-prompt');
const closeModalBtn = donationModal.querySelector('.modal-close');
const proceedToDownloadBtn = document.getElementById('proceed-to-download');
let downloadUrl = '';
const openModal = () => {
donationModal.classList.add('active');
document.body.style.overflow = 'hidden';
};
const closeModal = () => {
donationModal.classList.remove('active');
document.body.style.overflow = '';
};
donationLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
downloadUrl = this.href;
openModal();
});
});
closeModalBtn.addEventListener('click', closeModal);
proceedToDownloadBtn.addEventListener('click', function(e) {
e.preventDefault();
closeModal();
window.location.href = downloadUrl;
});
donationModal.addEventListener('click', function(e) {
if (e.target === this) {
closeModal();
}
});
// Close modal with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && donationModal.classList.contains('active')) {
closeModal();
}
});
// Toast notification for donations when clicking download buttons
function createToast() {
const toastContainer = document.querySelector('.toast-container');
// Create toast HTML
const toast = document.createElement('div');
toast.className = 'toast';
toast.innerHTML = `
<div class="toast-content">
<div class="toast-title">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2zM8 1.918l-.797.161A4.002 4.002 0 0 0 4 6c0 .628-.134 2.197-.459 3.742-.16.767-.376 1.566-.663 2.258h10.244c-.287-.692-.502-1.49-.663-2.258C12.134 8.197 12 6.628 12 6a4.002 4.002 0 0 0-3.203-3.92L8 1.917zM14.22 12c.223.447.481.801.78 1H1c.299-.199.557-.553.78-1C2.68 10.2 3 6.88 3 6c0-2.42 1.72-4.44 4.005-4.901a1 1 0 1 1 1.99 0A5.002 5.002 0 0 1 13 6c0 .88.32 4.2 1.22 6z"/>
</svg>
Support DockDoor Development
</div>
<div class="toast-message">
DockDoor is free, but your support helps us continue development. Consider making a small donation to keep this project going.
</div>
<div class="toast-actions">
<a href="https://www.buymeacoffee.com/keplercafe" class="btn btn-primary toast-btn" target="_blank">Donate</a>
<button class="btn btn-outline toast-btn not-now">Not Now</button>
</div>
</div>
<button class="toast-close">×</button>
`;
// Add to container
toastContainer.appendChild(toast);
// Show the toast after a small delay
setTimeout(() => {
toast.classList.add('show');
}, 300);
// Handle close button click
const closeBtn = toast.querySelector('.toast-close');
closeBtn.addEventListener('click', () => {
hideToast(toast);
});
// Handle "Not Now" button click
const notNowBtn = toast.querySelector('.not-now');
notNowBtn.addEventListener('click', () => {
hideToast(toast);
});
// Auto hide after 10 seconds
setTimeout(() => {
hideToast(toast);
}, 10000);
}
function hideToast(toast) {
toast.classList.remove('show');
setTimeout(() => {
toast.remove();
}, 500);
}
// Add click event listeners to download buttons
const downloadButtons = document.querySelectorAll('.download-btn');
downloadButtons.forEach(button => {
button.addEventListener('click', (e) => {
// Don't prevent default - we want the download to happen
// Show the donation toast
createToast();
});
});
});