Files
ComfyUI-Lora-Manager/static/js/core.js
Will Miao 04545c5706 Implement lazy loading and infinite scroll features in core application
- Added lazy loading for images and initialized infinite scroll in the AppCore class to enhance performance across various pages.
- Updated LoraPageManager and RecipeManager to utilize the new initializePageFeatures method for common UI features.
- Enhanced infinite scroll functionality to dynamically load more content based on the page type, improving user experience.
- Refactored recipes.html to trigger the import modal through the ModalManager for better modal handling.
2025-03-19 17:04:58 +08:00

83 lines
2.6 KiB
JavaScript

// Core application functionality
import { state, initSettings } from './state/index.js';
import { LoadingManager } from './managers/LoadingManager.js';
import { modalManager } from './managers/ModalManager.js';
import { updateService } from './managers/UpdateService.js';
import { HeaderManager } from './components/Header.js';
import { SettingsManager } from './managers/SettingsManager.js';
import { showToast, initTheme, initBackToTop, updatePanelPositions, lazyLoadImages } from './utils/uiHelpers.js';
import { initializeInfiniteScroll } from './utils/infiniteScroll.js';
// Core application class
export class AppCore {
constructor() {
this.initialized = false;
}
// Initialize core functionality
async initialize() {
if (this.initialized) return;
// Initialize settings
initSettings();
// Initialize managers
state.loadingManager = new LoadingManager();
modalManager.initialize();
updateService.initialize();
window.modalManager = modalManager;
window.settingsManager = new SettingsManager();
// Initialize UI components
window.headerManager = new HeaderManager();
initTheme();
initBackToTop();
// Set up event listeners
window.addEventListener('resize', updatePanelPositions);
// Initial positioning
updatePanelPositions();
// Mark as initialized
this.initialized = true;
// Return the core instance for chaining
return this;
}
// Get the current page type
getPageType() {
const body = document.body;
return body.dataset.page || 'unknown';
}
// Show toast messages
showToast(message, type = 'info') {
showToast(message, type);
}
// Initialize common UI features based on page type
initializePageFeatures() {
const pageType = this.getPageType();
// Initialize lazy loading for images on all pages
lazyLoadImages();
// Initialize infinite scroll for pages that need it
if (['loras', 'recipes', 'checkpoints'].includes(pageType)) {
initializeInfiniteScroll(pageType);
}
// Update panel positions
updatePanelPositions();
return this;
}
}
// Create and export a singleton instance
export const appCore = new AppCore();
// Export common utilities for global use
export { showToast, modalManager, state, lazyLoadImages, initializeInfiniteScroll };