This commit is contained in:
2025-09-03 15:03:15 -03:00
parent 0c1cca64a8
commit 7bc96fec2b
2 changed files with 13 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
// frontend/public/bootstrap.js
(function() {
(function () {
// El dominio donde se alojan los widgets
const WIDGETS_HOST = 'https://elecciones2025.eldia.com';
@@ -39,10 +39,10 @@
if (!entryKey) {
throw new Error('No se encontró el punto de entrada en el manifest.');
}
const entry = manifest[entryKey];
const jsUrl = `${WIDGETS_HOST}/${entry.file}`;
// 3. Cargar el CSS si existe
if (entry.css && entry.css.length > 0) {
entry.css.forEach(cssFile => {
@@ -54,6 +54,14 @@
// 4. Cargar el JS principal y esperar a que esté listo
await loadScript(jsUrl);
console.log('Bootstrap: Intentando llamar a render...');
if (window.EleccionesWidgets && typeof window.EleccionesWidgets.render === 'function') {
console.log('Bootstrap: La función render existe. Llamando ahora.');
window.EleccionesWidgets.render();
} else {
console.error('Bootstrap: La función render no se encontró en window.EleccionesWidgets.');
}
// 5. Una vez cargado, llamar a la función de renderizado
if (window.EleccionesWidgets && typeof window.EleccionesWidgets.render === 'function') {
window.EleccionesWidgets.render();

View File

@@ -60,7 +60,9 @@ if (import.meta.env.DEV) {
// --- MODO PRODUCCIÓN ---
// Exponemos la función de renderizado para el bootstrap.js
const renderWidgets = () => {
console.log('React: Se ha ejecutado renderWidgets.');
const widgetContainers = document.querySelectorAll('[data-elecciones-widget]');
console.log(`React: Se encontraron ${widgetContainers.length} contenedores de widget.`);
widgetContainers.forEach(container => {
const widgetName = (container as HTMLElement).dataset.eleccionesWidget;
if (widgetName && WIDGET_MAP[widgetName]) {