1. Refactoring form objects and database objects to use inheritance and abstract base class for consistency and reduced redundancy.\n2. Contact us page button links updated to resolve error of missing link causing page refresh instead of expected functionality.
This commit is contained in:
65
static/js/lib/main.js
Normal file
65
static/js/lib/main.js
Normal file
@@ -0,0 +1,65 @@
|
||||
// main.js
|
||||
|
||||
import { initializeAPI } from './shared/api.js';
|
||||
import { setupEventListeners } from './shared/events.js';
|
||||
import { initializeComponents } from './components/componentInitializer.js';
|
||||
import { router } from './shared/router.js';
|
||||
import { CONFIG } from './config/config.js';
|
||||
|
||||
// DOM ready function
|
||||
function domReady(fn) {
|
||||
if (document.readyState !== 'loading') {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
}
|
||||
|
||||
// Main initialization function
|
||||
function initializeApp() {
|
||||
console.log('Initializing application...');
|
||||
|
||||
// Initialize API with base URL
|
||||
initializeAPI(CONFIG.API_BASE_URL);
|
||||
|
||||
// Setup global event listeners
|
||||
setupEventListeners();
|
||||
|
||||
// Initialize reusable components
|
||||
initializeComponents();
|
||||
|
||||
// Initialize router
|
||||
router.init();
|
||||
|
||||
// Page-specific initialization
|
||||
const currentPage = document.body.dataset.page;
|
||||
switch (currentPage) {
|
||||
case 'home':
|
||||
import('./pages/home.js').then(module => module.initHomePage());
|
||||
break;
|
||||
case 'about':
|
||||
import('./pages/about.js').then(module => module.initAboutPage());
|
||||
break;
|
||||
case 'contact':
|
||||
import('./pages/contact.js').then(module => module.initContactPage());
|
||||
break;
|
||||
default:
|
||||
console.log('No specific initialization for this page');
|
||||
}
|
||||
|
||||
console.log('Application initialized');
|
||||
}
|
||||
|
||||
// Run the initialization when the DOM is ready
|
||||
domReady(initializeApp);
|
||||
|
||||
// Expose a global app object if needed
|
||||
window.app = {
|
||||
// Add methods or properties that need to be globally accessible
|
||||
reloadPage: () => {
|
||||
window.location.reload();
|
||||
},
|
||||
navigateTo: (url) => {
|
||||
router.navigateTo(url);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user