124 lines
3.6 KiB
JavaScript
124 lines
3.6 KiB
JavaScript
|
|
/**
|
||
|
|
* Navegación entre secciones SCORM
|
||
|
|
*/
|
||
|
|
|
||
|
|
(function() {
|
||
|
|
'use strict';
|
||
|
|
|
||
|
|
const sections = [
|
||
|
|
'section-01.html',
|
||
|
|
'section-02.html',
|
||
|
|
'section-03.html',
|
||
|
|
'section-04.html',
|
||
|
|
'section-05.html',
|
||
|
|
'section-06.html',
|
||
|
|
'section-07.html',
|
||
|
|
'section-08.html'
|
||
|
|
];
|
||
|
|
|
||
|
|
let currentSection = 1;
|
||
|
|
const totalSections = sections.length;
|
||
|
|
|
||
|
|
// Obtener sección actual desde SCORM o URL
|
||
|
|
function getCurrentSection() {
|
||
|
|
if (window.SCORM && window.SCORM.isInitialized) {
|
||
|
|
const location = window.SCORM.getValue("cmi.core.lesson_location");
|
||
|
|
if (location) {
|
||
|
|
return parseInt(location, 10) || 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Intentar desde URL
|
||
|
|
const urlParams = new URLSearchParams(window.location.search);
|
||
|
|
const section = urlParams.get('section');
|
||
|
|
if (section) {
|
||
|
|
return parseInt(section, 10) || 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Cargar sección
|
||
|
|
function loadSection(sectionNumber) {
|
||
|
|
if (sectionNumber < 1 || sectionNumber > totalSections) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
currentSection = sectionNumber;
|
||
|
|
const sectionFile = sections[sectionNumber - 1];
|
||
|
|
|
||
|
|
// Cargar contenido
|
||
|
|
fetch(`sections/${sectionFile}`)
|
||
|
|
.then(response => response.text())
|
||
|
|
.then(html => {
|
||
|
|
document.getElementById('content').innerHTML = html;
|
||
|
|
updateUI();
|
||
|
|
updateSCORM();
|
||
|
|
})
|
||
|
|
.catch(error => {
|
||
|
|
console.error('Error cargando sección:', error);
|
||
|
|
document.getElementById('content').innerHTML =
|
||
|
|
'<p>Error al cargar la sección. Por favor, recarga la página.</p>';
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Actualizar UI
|
||
|
|
function updateUI() {
|
||
|
|
// Actualizar indicador de sección
|
||
|
|
document.getElementById('current-section').textContent = currentSection;
|
||
|
|
document.getElementById('total-sections').textContent = totalSections;
|
||
|
|
|
||
|
|
// Actualizar barra de progreso
|
||
|
|
const progress = (currentSection / totalSections) * 100;
|
||
|
|
document.getElementById('progress-fill').style.width = progress + '%';
|
||
|
|
|
||
|
|
// Actualizar botones
|
||
|
|
document.getElementById('btn-prev').disabled = currentSection === 1;
|
||
|
|
document.getElementById('btn-next').disabled = currentSection === totalSections;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Actualizar SCORM
|
||
|
|
function updateSCORM() {
|
||
|
|
if (window.SCORM) {
|
||
|
|
window.SCORM.updateProgress(currentSection, totalSections);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Event listeners
|
||
|
|
document.getElementById('btn-prev').addEventListener('click', () => {
|
||
|
|
if (currentSection > 1) {
|
||
|
|
loadSection(currentSection - 1);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('btn-next').addEventListener('click', () => {
|
||
|
|
if (currentSection < totalSections) {
|
||
|
|
loadSection(currentSection + 1);
|
||
|
|
} else {
|
||
|
|
// Completar curso
|
||
|
|
if (window.SCORM) {
|
||
|
|
window.SCORM.setCompleted();
|
||
|
|
}
|
||
|
|
alert('¡Has completado la guía!');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('btn-exit').addEventListener('click', () => {
|
||
|
|
if (window.SCORM) {
|
||
|
|
window.SCORM.terminate();
|
||
|
|
}
|
||
|
|
// Cerrar ventana o redirigir
|
||
|
|
if (window.opener) {
|
||
|
|
window.close();
|
||
|
|
} else {
|
||
|
|
window.location.href = '/';
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Inicializar
|
||
|
|
currentSection = getCurrentSection();
|
||
|
|
loadSection(currentSection);
|
||
|
|
|
||
|
|
})();
|
||
|
|
|