Skip to content

Commit 87da4fd

Browse files
committed
📝 added jsdoc documentation
1 parent 5713693 commit 87da4fd

File tree

5 files changed

+131
-2
lines changed

5 files changed

+131
-2
lines changed

js/dataLoader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Fetches all necessary data files: films, series, and collections.
3+
* @returns {Object} An object containing films, series, and collections data.
4+
*/
15
export async function fetchAllData() {
26
try {
37
await new Promise(r => setTimeout(r, 800));
@@ -27,6 +31,10 @@ export async function fetchAllData() {
2731
}
2832
}
2933

34+
/**
35+
* Fetches notifications data.
36+
* @returns {Array} An array of notifications.
37+
*/
3038
export async function fetchNotifs() {
3139
try {
3240
const res = await fetch('data/notifs.json');

js/display.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { playVideo } from './utils.js';
33
let activeDetailItem = null;
44
let activeVideoSrc = "";
55

6+
/**
7+
* Sets up the hero section with the given media item.
8+
* @param {Object} item - The media item to display in the hero section.
9+
*/
610
export function setupHero(item) {
711
if (!item) return;
812

@@ -44,6 +48,10 @@ export function setupHero(item) {
4448
}
4549
}
4650

51+
/**
52+
* Opens the details overlay for a given media item.
53+
* @param {Object} item - The media item to display details for.
54+
*/
4755
export function openDetails(item) {
4856
activeDetailItem = item;
4957
const overlay = document.getElementById('detailsOverlay');
@@ -114,11 +122,17 @@ export function openDetails(item) {
114122
document.body.style.overflow = 'hidden';
115123
}
116124

125+
/**
126+
* Closes the details overlay.
127+
*/
117128
export function closeDetails() {
118129
document.getElementById('detailsOverlay').classList.add('hidden');
119130
document.body.style.overflow = '';
120131
}
121132

133+
/**
134+
* Plays the currently selected media in the details overlay.
135+
*/
122136
export function playCurrentMedia() {
123137
if (activeVideoSrc) {
124138
playVideo(activeVideoSrc);
@@ -127,6 +141,11 @@ export function playCurrentMedia() {
127141
}
128142
}
129143

144+
/**
145+
* Renders the list of episodes for a given season.
146+
* @param {Array} episodes - The list of episodes to render.
147+
* @param {number|string} seasonNum - The season number.
148+
*/
130149
function renderEpisodes(episodes, seasonNum) {
131150
const list = document.getElementById('episodesList');
132151
list.innerHTML = '';
@@ -215,6 +234,12 @@ function renderEpisodes(episodes, seasonNum) {
215234
});
216235
}
217236

237+
/**
238+
* Creates a media card element for a given media item.
239+
* @param {Object} item - The media item to create a card for.
240+
* @param {string} [extraClasses=""] - Additional CSS classes to apply to the card.
241+
* @returns {HTMLElement} The created media card element.
242+
*/
218243
export function createMediaCard(item, extraClasses = "") {
219244
const card = document.createElement('div');
220245
card.className = `media-card group relative rounded-xl overflow-hidden cursor-pointer bg-[#1a1a1a] shadow-lg transition-all duration-300 ${extraClasses}`;
@@ -235,12 +260,21 @@ export function createMediaCard(item, extraClasses = "") {
235260
return card;
236261
}
237262

263+
/**
264+
* Renders a grid of media items.
265+
* @param {Array} items - The list of media items to render.
266+
*/
238267
export function renderGrid(items) {
239268
const grid = document.getElementById('contentGrid');
240269
grid.innerHTML = '';
241270
items.forEach(item => grid.appendChild(createMediaCard(item, "aspect-[2/3]")));
242271
}
243272

273+
/**
274+
* Renders a horizontal row of media items.
275+
* @param {string} containerId - The ID of the container element.
276+
* @param {Array} items - The list of media items to render.
277+
*/
244278
export function renderHorizontalRow(containerId, items) {
245279
const container = document.getElementById(containerId);
246280
container.innerHTML = '';
@@ -251,6 +285,11 @@ export function renderHorizontalRow(containerId, items) {
251285
});
252286
}
253287

288+
/**
289+
* Renders collections of media items.
290+
* @param {Object} collectionsData - The collections data.
291+
* @param {Object} appData - The application data containing films and series.
292+
*/
254293
export function renderCollections(collectionsData, appData) {
255294
const container = document.getElementById('collectionsContent');
256295
container.innerHTML = '';
@@ -309,6 +348,10 @@ export function renderCollections(collectionsData, appData) {
309348
}
310349
}
311350

351+
/**
352+
* Renders the list of notifications.
353+
* @param {Array} list - The list of notifications to render.
354+
*/
312355
export function renderNotifs(list) {
313356
const container = document.getElementById('notifList');
314357
const badge = document.getElementById('notifBadge');

js/errorHandler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ if (errorCodeEl) {
1818
errorCodeEl.textContent = (paramCode || "404").toString();
1919
}
2020

21+
/**
22+
* Handles an error by storing the message and redirecting to the error page.
23+
* @param {string} message - The error message to display.
24+
* @param {number|string} [code=404] - The error code to display.
25+
*/
2126
function handleErrorAndRedirect(message, code = 404) {
2227
localStorage.setItem("streamit_error", message);
2328
const safeCode = (typeof code === "number" || typeof code === "string") ? code : 404;
@@ -39,6 +44,9 @@ document.addEventListener("keydown", (e) => {
3944
}
4045
});
4146

47+
/**
48+
* Detects if developer tools are open and redirects if so.
49+
*/
4250
(function detectDevTools() {
4351
const start = Date.now();
4452
debugger;

js/main.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ document.addEventListener('DOMContentLoaded', async () => {
3333
hideLoader();
3434
});
3535

36+
/**
37+
* Sets navigation link colors to default (removes highlight).
38+
* @param {HTMLElement} navHome - Navigation link elements
39+
* @param {HTMLElement} navSeries - Navigation link elements
40+
* @param {HTMLElement} navFilms - Navigation link elements
41+
* @param {HTMLElement} navCollections - Navigation link elements
42+
*/
3643
function textWhite(navHome, navSeries, navFilms, navCollections) {
3744
[navHome, navSeries, navFilms, navCollections].forEach(el => {
3845
if (el) el.classList.remove('text-white', 'text-red-500');
3946
});
4047
}
4148

49+
/**
50+
* Routes to the specified view and updates the UI accordingly.
51+
* @param {string} view - The view to route to ('home', 'series', 'films', 'collections').
52+
*/
4253
function router(view) {
4354
currentView = view;
4455

@@ -106,7 +117,9 @@ function router(view) {
106117
}
107118
}
108119

109-
120+
/**
121+
* Initializes the hero section with a featured item or the latest item.
122+
*/
110123
function initHero() {
111124
const all = [...Object.values(appData.films), ...Object.values(appData.series)];
112125
if (all.length === 0) return;
@@ -121,6 +134,9 @@ function initHero() {
121134
}
122135
}
123136

137+
/**
138+
* Populates filter dropdowns based on available data.
139+
*/
124140
function populateFilters() {
125141
const source = currentView === 'films' ? Object.values(appData.films) : Object.values(appData.series);
126142
const genres = new Set();
@@ -147,6 +163,9 @@ function populateFilters() {
147163
Array.from(directors).sort().forEach(d => directorSel.add(new Option(d, d)));
148164
}
149165

166+
/**
167+
* Applies selected filters and sorting to the displayed items.
168+
*/
150169
function applyFilters() {
151170
const genre = document.getElementById('filterGenre').value;
152171
const year = document.getElementById('filterYear').value;
@@ -179,6 +198,9 @@ function applyFilters() {
179198
renderGrid(filtered);
180199
}
181200

201+
/**
202+
* Resets all filters to default values and reapplies them.
203+
*/
182204
function resetFilters() {
183205
document.getElementById('filterGenre').value = "";
184206
document.getElementById('filterYear').value = "";
@@ -188,6 +210,10 @@ function resetFilters() {
188210
applyFilters();
189211
}
190212

213+
/**
214+
* Handles search input and updates the displayed content accordingly.
215+
* @param {Event} e - The input event.
216+
*/
191217
function handleSearch(e) {
192218
const q = e.target.value.toLowerCase();
193219

@@ -224,7 +250,6 @@ function handleSearch(e) {
224250
const navSeries = document.getElementById('nav-series');
225251
const navFilms = document.getElementById('nav-films');
226252
const navCollections = document.getElementById('nav-collections');
227-
228253
textWhite(navHome, navSeries, navFilms, navCollections);
229254

230255
const titleEl = document.getElementById('titleText');
@@ -240,6 +265,9 @@ function handleSearch(e) {
240265
renderGrid(res);
241266
}
242267

268+
/**
269+
* Clears search input fields.
270+
*/
243271
function clearSearch() {
244272
document.getElementById('searchInput').value = '';
245273
document.getElementById('mobileSearchInput').value = '';

js/utils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
const PROGRESS_PREFIX = 'streamit:progress:';
22
let currentVideoSrc = '';
33

4+
/**
5+
* Generates a unique key for storing video progress in localStorage.
6+
* @param {string} src - The video source URL.
7+
* @returns {string} The generated storage key.
8+
*/
49
function progressKey(src) {
510
return `${PROGRESS_PREFIX}${src}`;
611
}
712

13+
/**
14+
* Restores video playback progress from localStorage.
15+
* @param {HTMLVideoElement} player - The video player element.
16+
* @param {string} src - The video source URL.
17+
*/
818
function restoreProgress(player, src) {
919
const saved = parseFloat(localStorage.getItem(progressKey(src)) || '');
1020
if (Number.isNaN(saved)) return;
@@ -19,6 +29,10 @@ function restoreProgress(player, src) {
1929
else player.addEventListener('loadedmetadata', applyTime);
2030
}
2131

32+
/**
33+
* Persists video playback progress to localStorage.
34+
* @param {HTMLVideoElement} player - The video player element.
35+
*/
2236
function persistProgress(player) {
2337
if (!currentVideoSrc) return;
2438
const key = progressKey(currentVideoSrc);
@@ -29,6 +43,10 @@ function persistProgress(player) {
2943
else localStorage.setItem(key, String(t));
3044
}
3145

46+
/**
47+
* Plays a video in the overlay player.
48+
* @param {string} src - The video source URL.
49+
*/
3250
export function playVideo(src) {
3351
const overlay = document.getElementById('videoOverlay');
3452
const player = document.getElementById('mainPlayer');
@@ -48,6 +66,9 @@ export function playVideo(src) {
4866
}, 50);
4967
}
5068

69+
/**
70+
* Closes the video overlay and stops playback.
71+
*/
5172
export function closeVideo() {
5273
const overlay = document.getElementById('videoOverlay');
5374
const player = document.getElementById('mainPlayer');
@@ -57,11 +78,17 @@ export function closeVideo() {
5778
overlay.classList.add('hidden');
5879
}
5980

81+
/**
82+
* Toggles the notifications dropdown visibility.
83+
*/
6084
export function toggleNotifs() {
6185
const dropdown = document.getElementById('notifDropdown');
6286
dropdown.classList.toggle('active');
6387
}
6488

89+
/**
90+
* Toggles the mobile menu visibility.
91+
*/
6592
export function toggleMobileMenu() {
6693
const menu = document.getElementById('mobileMenuPanel');
6794
const search = document.getElementById('mobileSearchPanel');
@@ -73,6 +100,9 @@ export function toggleMobileMenu() {
73100
menu.classList.toggle('active');
74101
}
75102

103+
/**
104+
* Toggles the mobile search panel visibility.
105+
*/
76106
export function toggleMobileSearch() {
77107
const search = document.getElementById('mobileSearchPanel');
78108
const menu = document.getElementById('mobileMenuPanel');
@@ -88,17 +118,26 @@ export function toggleMobileSearch() {
88118
}
89119
}
90120

121+
/**
122+
* Shows the loading spinner.
123+
*/
91124
export function showLoader() {
92125
document.getElementById('loader').classList.remove('hidden');
93126
document.getElementById('loader').style.opacity = '1';
94127
}
95128

129+
/**
130+
* Hides the loading spinner with a fade-out effect.
131+
*/
96132
export function hideLoader() {
97133
const loader = document.getElementById('loader');
98134
loader.style.opacity = '0';
99135
setTimeout(() => loader.classList.add('hidden'), 700);
100136
}
101137

138+
/**
139+
* Enhances video player controls to prevent downloading and remote playback.
140+
*/
102141
export function hardenPlayerControls() {
103142
const player = document.getElementById('mainPlayer');
104143
if (!player) return;
@@ -109,6 +148,9 @@ export function hardenPlayerControls() {
109148
player.addEventListener('contextmenu', (e) => e.preventDefault());
110149
}
111150

151+
/**
152+
* Initializes video player progress persistence.
153+
*/
112154
export function initPlayerPersistence() {
113155
const player = document.getElementById('mainPlayer');
114156
if (!player) return;

0 commit comments

Comments
 (0)