Files
KiraTV-APP-NodeCast-Modific…/public/js/app.js
T
2025-12-29 23:41:40 -08:00

88 lines
2.5 KiB
JavaScript

/**
* NodeCast TV Application Entry Point
*/
class App {
constructor() {
this.currentPage = 'home';
this.pages = {};
// Initialize components
this.player = new VideoPlayer();
this.channelList = new ChannelList();
this.sourceManager = new SourceManager();
this.epgGuide = new EpgGuide();
// Initialize page controllers
this.pages.home = new HomePage(this);
this.pages.guide = new GuidePage(this);
this.pages.movies = new MoviesPage(this);
this.pages.series = new SeriesPage(this);
this.pages.settings = new SettingsPage(this);
this.init();
}
async init() {
// Navigation handling
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
this.navigateTo(link.dataset.page);
});
});
// Toggle groups button
document.getElementById('toggle-groups').addEventListener('click', () => {
this.channelList.toggleAllGroups();
});
// Search clear buttons (global handler for all)
document.querySelectorAll('.search-clear').forEach(btn => {
btn.addEventListener('click', () => {
const wrapper = btn.closest('.search-wrapper');
const input = wrapper?.querySelector('.search-input');
if (input) {
input.value = '';
input.dispatchEvent(new Event('input', { bubbles: true }));
input.focus();
}
});
});
// Initialize home page
await this.pages.home.init();
this.navigateTo('home');
console.log('NodeCast TV initialized');
}
navigateTo(pageName) {
// Update nav
document.querySelectorAll('.nav-link').forEach(link => {
link.classList.toggle('active', link.dataset.page === pageName);
});
// Update pages
document.querySelectorAll('.page').forEach(page => {
page.classList.toggle('active', page.id === `page-${pageName}`);
});
// Notify page controllers
if (this.pages[this.currentPage]?.hide) {
this.pages[this.currentPage].hide();
}
this.currentPage = pageName;
if (this.pages[pageName]?.show) {
this.pages[pageName].show();
}
}
}
// Start app when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
window.app = new App();
});