| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  | (function() { | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |   // --- LÓGICA DE DETECCIÓN AUTOMÁTICA DE LA RUTA BASE ---
 | 
					
						
							|  |  |  |   // document.currentScript.src nos da la URL completa del propio script bootstrap.js
 | 
					
						
							|  |  |  |   const scriptUrl = new URL(document.currentScript.src); | 
					
						
							|  |  |  |   // La ruta base es el origen (ej. 'https://elecciones2025.eldia.com')
 | 
					
						
							|  |  |  |   const WIDGETS_HOST = scriptUrl.origin; | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |    | 
					
						
							|  |  |  |   // --- FUNCIONES AUXILIARES (sin cambios) ---
 | 
					
						
							|  |  |  |   function loadScript(src) { | 
					
						
							|  |  |  |     return new Promise((resolve, reject) => { | 
					
						
							|  |  |  |       const script = document.createElement('script'); | 
					
						
							|  |  |  |       script.type = 'module'; | 
					
						
							|  |  |  |       script.src = src; | 
					
						
							|  |  |  |       script.onload = resolve; | 
					
						
							|  |  |  |       script.onerror = reject; | 
					
						
							|  |  |  |       document.head.appendChild(script); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function loadCSS(href) { | 
					
						
							|  |  |  |     const link = document.createElement('link'); | 
					
						
							|  |  |  |     link.rel = 'stylesheet'; | 
					
						
							|  |  |  |     link.href = href; | 
					
						
							|  |  |  |     document.head.appendChild(link); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // --- LÓGICA PRINCIPAL ---
 | 
					
						
							|  |  |  |   async function initWidgets() { | 
					
						
							|  |  |  |     try { | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       // 1. Obtener el manifest.json desde la ruta base detectada
 | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |       const response = await fetch(`${WIDGETS_HOST}/manifest.json`); | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       if (!response.ok) { | 
					
						
							| 
									
										
										
										
											2025-09-03 14:16:18 -03:00
										 |  |  |         throw new Error('No se pudo cargar el manifest. (404 Not Found)'); | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |       const manifest = await response.json(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       // 2. Encontrar el punto de entrada principal
 | 
					
						
							|  |  |  |       const entryKey = Object.keys(manifest).find(key => manifest[key].isEntry); | 
					
						
							|  |  |  |       if (!entryKey) { | 
					
						
							|  |  |  |         throw new Error('No se encontró el punto de entrada en el manifest.'); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |        | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       const entry = manifest[entryKey]; | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |       const jsUrl = `${WIDGETS_HOST}/${entry.file}`; | 
					
						
							|  |  |  |        | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       // 3. Cargar el CSS
 | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |       if (entry.css && entry.css.length > 0) { | 
					
						
							|  |  |  |         entry.css.forEach(cssFile => { | 
					
						
							|  |  |  |           const cssUrl = `${WIDGETS_HOST}/${cssFile}`; | 
					
						
							|  |  |  |           loadCSS(cssUrl); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 14:05:06 -03:00
										 |  |  |       // 4. Cargar el JS principal
 | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  |       await loadScript(jsUrl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							|  |  |  |       console.error('Error al inicializar los widgets de Elecciones:', error); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   initWidgets(); | 
					
						
							|  |  |  | })(); |