Spaces:
Running
Running
File size: 7,148 Bytes
17fcaeb af14a86 53873ca af14a86 53873ca af14a86 53873ca af14a86 53873ca af14a86 53873ca af14a86 |
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
// Initialize Mermaid diagrams
document.addEventListener('DOMContentLoaded', () => {
if (window.mermaid) {
mermaid.initialize({
startOnLoad: true,
theme: 'neutral',
themeVariables: {
fontSize: '16px'
}
});
}
});
// Lazy loading for images
document.addEventListener('DOMContentLoaded', () => {
const images = document.querySelectorAll('img[loading="lazy"]');
if ('loading' in HTMLImageElement.prototype) {
images.forEach(img => {
img.src = img.dataset.src;
});
} else {
// Fallback for browsers that don't support lazy loading
const script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.3.2/lazysizes.min.js';
document.body.appendChild(script);
}
});
// Print optimization
const optimizePrint = () => {
const style = document.createElement('style');
style.textContent = `
@media print {
.no-print { display: none !important; }
a[href]:after { content: " (" attr(href) ")"; }
img { max-width: 500px !important; }
}
`;
document.head.appendChild(style);
};
// Initialize all components
const initComponents = () => {
// Initialize Lottie animations if present
if (window.lottie) {
document.querySelectorAll('.lottie-player').forEach(player => {
if (!player.hasAttribute('data-initialized')) {
player.setAttribute('data-initialized', 'true');
// Add any specific Lottie initialization here
}
});
}
};
// Export utilities
window.hospitalAI = {
optimizePrint,
initComponents
};
// Main JavaScript for Hospital AI Website
// Language handling
const languageHandler = {
// Available languages
languages: ['es', 'en'],
// Get current language
getCurrentLanguage() {
return document.body.getAttribute('data-language') || 'es';
},
// Set language
setLanguage(lang) {
if (this.languages.includes(lang)) {
document.body.setAttribute('data-language', lang);
document.body.classList.toggle('lang-en', lang === 'en');
localStorage.setItem('preferred-language', lang);
this.updateMetaTags(lang);
}
},
// Update meta tags for language
updateMetaTags(lang) {
document.documentElement.lang = lang;
const title = document.querySelector('title');
if (title) {
title.textContent = title.getAttribute(`data-${lang}`) || title.textContent;
}
},
// Initialize language
init() {
const savedLang = localStorage.getItem('preferred-language');
if (savedLang) {
this.setLanguage(savedLang);
}
}
};
// Navigation handling
const navigationHandler = {
// Update active state
updateActiveState() {
const currentPath = window.location.pathname;
document.querySelectorAll('nav a').forEach(link => {
const href = link.getAttribute('href');
if (href === currentPath) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
},
// Update breadcrumbs
updateBreadcrumbs() {
const breadcrumb = document.querySelector('.breadcrumb');
if (breadcrumb) {
const currentPath = window.location.pathname;
const pathParts = currentPath.split('/').filter(Boolean);
let currentLink = '';
const breadcrumbHTML = pathParts.map((part, index) => {
currentLink += `/${part}`;
return `
<a href="${currentLink}">${part}</a>
${index < pathParts.length - 1 ? '<span>/</span>' : ''}
`;
}).join('');
breadcrumb.innerHTML = `
<a href="/">Home</a>
${pathParts.length ? '<span>/</span>' : ''}
${breadcrumbHTML}
`;
}
},
// Initialize navigation
init() {
this.updateActiveState();
this.updateBreadcrumbs();
window.addEventListener('popstate', () => {
this.updateActiveState();
this.updateBreadcrumbs();
});
}
};
// Dark mode handling
const darkModeHandler = {
// Toggle dark mode
toggle() {
document.documentElement.classList.toggle('dark');
const isDark = document.documentElement.classList.contains('dark');
localStorage.setItem('dark-mode', isDark ? 'dark' : 'light');
},
// Initialize dark mode
init() {
const savedMode = localStorage.getItem('dark-mode');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedMode === 'dark' || (!savedMode && prefersDark)) {
document.documentElement.classList.add('dark');
}
}
};
// Smooth scrolling
const scrollHandler = {
init() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
e.preventDefault();
const target = document.querySelector(anchor.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
};
// Initialize everything
document.addEventListener('DOMContentLoaded', () => {
languageHandler.init();
navigationHandler.init();
darkModeHandler.init();
scrollHandler.init();
// Close doc viewer on escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') DocViewer.close();
});
});
// Global language toggle function
function toggleLanguage() {
const currentLang = languageHandler.getCurrentLanguage();
const newLang = currentLang === 'es' ? 'en' : 'es';
languageHandler.setLanguage(newLang);
}
// Global dark mode toggle function
function toggleDarkMode() {
darkModeHandler.toggle();
}
// Export for use in Node.js environments
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
languageHandler,
navigationHandler,
darkModeHandler,
scrollHandler
};
}
// Document viewer
const DocViewer = {
open(url) {
const viewer = document.getElementById('docViewer');
const frame = document.getElementById('docFrame');
frame.src = url;
viewer.classList.add('active');
document.body.style.overflow = 'hidden';
},
close() {
const viewer = document.getElementById('docViewer');
const frame = document.getElementById('docFrame');
frame.src = '';
viewer.classList.remove('active');
document.body.style.overflow = 'auto';
}
};
// Export for global use
window.openDoc = DocViewer.open;
window.closeDoc = DocViewer.close; |