-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
119 lines (102 loc) · 3.45 KB
/
Copy pathscript.js
File metadata and controls
119 lines (102 loc) · 3.45 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
// === Spotlight Section ===
const spotlightSlides = document.querySelectorAll('.spotlight-slide');
const nextSpot = document.querySelector('.next');
const prevSpot = document.querySelector('.prev');
let spotlightIndex = 0;
function showSpotlightSlide(index) {
spotlightSlides.forEach((slide, i) => {
slide.classList.toggle('active', i === index);
});
}
if (nextSpot) {
nextSpot.addEventListener('click', () => {
spotlightIndex = (spotlightIndex + 1) % spotlightSlides.length;
showSpotlightSlide(spotlightIndex);
});
}
if (prevSpot) {
prevSpot.addEventListener('click', () => {
spotlightIndex = (spotlightIndex - 1 + spotlightSlides.length) % spotlightSlides.length;
showSpotlightSlide(spotlightIndex);
});
}
// Auto-slide every 6 seconds
setInterval(() => {
spotlightIndex = (spotlightIndex + 1) % spotlightSlides.length;
showSpotlightSlide(spotlightIndex);
}, 6000);
// === Trailer Modal ===
document.addEventListener('DOMContentLoaded', () => {
const trailerModal = document.getElementById('videoModal');
const trailerFrame = document.getElementById('trailerFrame');
if (!trailerModal || !trailerFrame) {
console.error('Modal elements not found');
return;
}
function openTrailer(url) {
if (!url) return;
trailerFrame.src = url;
trailerModal.style.display = 'flex';
}
function closeTrailer() {
trailerModal.style.display = 'none';
trailerFrame.src = '';
}
// Close button
const closeBtn = trailerModal.querySelector('.close');
if (closeBtn) {
closeBtn.addEventListener('click', closeTrailer);
}
// Click outside to close
trailerModal.addEventListener('click', (e) => {
if (e.target === trailerModal) closeTrailer();
});
// Event delegation for buttons
document.body.addEventListener('click', (e) => {
const clicked = e.target;
// Watch button in spotlight
const watchBtn = clicked.closest('.watch-btn[data-trailer]');
if (watchBtn) {
const url = watchBtn.getAttribute('data-trailer');
openTrailer(url);
return;
}
// Trailer button in poster cards
const trailerBtn = clicked.closest('.poster-btn.trailer-btn');
if (trailerBtn) {
const posterCard = trailerBtn.closest('.poster-card');
const url = posterCard ? posterCard.dataset.trailer : null;
if (url) openTrailer(url);
return;
}
// Get Tickets button
const getTicketsBtn = clicked.closest('.poster-btn.get-tickets-btn');
if (getTicketsBtn) {
e.preventDefault();
const posterCard = getTicketsBtn.closest('.poster-card');
const movieTitle = posterCard.dataset.movie;
const moviePoster = posterCard.dataset.poster;
// Redirect to booking page with movie data
window.location.href = `booking.php?movie=${encodeURIComponent(movieTitle)}&poster=${encodeURIComponent(moviePoster)}`;
return;
}
});
// ESC key to close
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && trailerModal.style.display === 'flex') {
closeTrailer();
}
});
});
// === PWA install / offline (Service Worker) ===
// Register the service worker so the phone can run the site as a PWA.
(function registerServiceWorker() {
if (!('serviceWorker' in navigator)) return;
window.addEventListener('load', function () {
navigator.serviceWorker
.register('service-worker.js')
.catch(function () {
// If registration fails, we still keep the app usable normally.
});
});
})();