1 line
5.1 KiB
JavaScript
1 line
5.1 KiB
JavaScript
async function handleGlossaryButton(e){const t=document.getElementById("offcanvasGlossary");if(!t)return;const n=new bootstrap.Offcanvas(t);try{const e=await fetch("manual_pld_ft.html");if(!e.ok)throw new Error("Error al cargar el glosario");const o=await e.text(),a=new DOMParser,s=a.parseFromString(o,"text/html").querySelector("main");t.querySelector(".offcanvas-body").innerHTML=s?s.innerHTML:'<p class="text-danger">No se encontró el contenido.</p>';const l=CourseNav.getCurrentSlide().title;t.querySelectorAll("section[data-title]").forEach((e=>{e.classList.toggle("d-none",e.dataset.title!==l)})),n.show()}catch(e){t.querySelector(".offcanvas-body").innerHTML='<p class="text-danger">Error al cargar el glosario. Recargue la página e intente nuevamente.</p>',n.show()}}function setupGlossaryListeners(){document.body.addEventListener("click",(function(e){const t=e.target.closest(".btn-glossary");t&&(e.preventDefault(),handleGlossaryButton(t))}))}function gotoSection(e,t={}){const n=Object.assign({behavior:"smooth",block:"start"},t);let o=e;"number"==typeof e?o=`sec${e}`:"string"!=typeof e||e.startsWith("#")?e.startsWith("#")&&(o=e.substring(1)):o=e.startsWith("sec")?e:`sec${e}`;const a=document.getElementById(o);return!!a&&("none"===a.style.display&&(a.style.display=""),a.scrollIntoView(n),!0)}function scrollToElementTop(e,t={}){const n=Object.assign({behavior:"smooth",block:"start",inline:"nearest"},t),o=document.querySelector(e);o&&o.scrollIntoView(n)}function animateOnScroll(e,t,n={}){const{threshold:o=.1,animateOnce:a=!0,prefix:s="animate__animated"}=n,l=new IntersectionObserver(((e,n)=>{e.forEach((e=>{e.isIntersecting?(e.target.classList.add(s,t),a&&n.unobserve(e.target)):a||e.target.classList.remove(s,t)}))}),{threshold:o});return document.querySelectorAll(e).forEach((e=>l.observe(e))),l}function initializeSwiper(e,t,n={},o=[],a=!0){const s=new Set,l="string"==typeof e?document.querySelector(e):e,r=l.parentElement;n.navigation&&n.navigation.nextEl&&n.navigation.prevEl&&(n.navigation.nextEl=l.querySelector(n.navigation.nextEl)?l.querySelector(n.navigation.nextEl):r.querySelector(n.navigation.nextEl),n.navigation.prevEl=l.querySelector(n.navigation.prevEl)?l.querySelector(n.navigation.prevEl):r.querySelector(n.navigation.prevEl));const i={effect:"slide",loop:!1,autoHeight:!0,...n,on:{init:function(){s.add(this.activeIndex),o.length>0&&o[this.activeIndex]&&a&&CourseNav.audioController.stopAllSoundsAndPlay(o[this.activeIndex])},slideChange:function(){const e=this.activeIndex;s.add(e),o.length>0&&CourseNav.audioController.stopAudio(),o.length>0&&o[e]&&CourseNav.audioController.stopAllSoundsAndPlay(o[e]),s.size===this.slides.length&&"function"==typeof t&&t()}}};return new Swiper(l,i)}window.COURSE_CONFIG={COURSE_CONFIG_URL:"config.json",DEBUG:!1,SHOW_PAGINATION:!1,SHOW_TITLE:!1,SHOW_GLOSSARY:!1},document.addEventListener("DOMContentLoaded",(()=>{setupGlossaryListeners(),"undefined"!=typeof sal&&document.querySelectorAll("[data-sal]").length>0&&setTimeout((()=>{document.querySelectorAll("[data-sal]").forEach((e=>e.style.visibility="visible")),sal({once:!1,threshold:.3,duration:600,easing:"ease-out",distance:"50px",opacity:0,scale:.95})}),200),document.body.addEventListener("beforeSlideChange",(e=>{})),document.body.addEventListener("slideChange",(e=>{if(e.detail&&"number"==typeof e.detail.slideIndex&&Array.isArray(e.detail.contentArray)){"undefined"!=typeof sal&&document.querySelectorAll("[data-sal]").length>0&&setTimeout((()=>{document.querySelectorAll("[data-sal]").forEach((e=>e.style.visibility="visible")),sal({once:!1,threshold:.3,duration:600,easing:"ease-out",distance:"50px",opacity:0,scale:.95})}),200);const t=document.getElementById("pagination"),n=document.querySelector(".paginacion_sco");window.COURSE_CONFIG.SHOW_PAGINATION?(t&&(t.innerHTML=e.detail.slideIndex+1+" / "+e.detail.contentArray.length),n&&n.classList.remove("isFalse")):n&&n.classList.add("isFalse");const o=document.getElementById("titleSco");o&&(window.COURSE_CONFIG.SHOW_TITLE?(o.classList.remove("d-none"),e.detail.contentArray[e.detail.slideIndex]&&(o.innerHTML=e.detail.contentArray[e.detail.slideIndex].title||"")):o.classList.add("d-none"));const a=document.getElementById("btn-glossary");if(a)if(window.COURSE_CONFIG.SHOW_GLOSSARY){const t=[0,1,e.detail.contentArray.length-1];a.style.display=t.includes(e.detail.slideIndex)?"none":"block"}else a.style.display="none"}})),document.body.addEventListener("slideCompleted",(e=>{}));const e=document.getElementById("btn-glossary");e&&e.addEventListener("click",(async()=>{const e=document.getElementById("offcanvasGlossary"),t=new bootstrap.Offcanvas(e);try{const n=await fetch("manual_pld_ft.html"),o=await n.text(),a=new DOMParser,s=a.parseFromString(o,"text/html").querySelector("main");e.querySelector(".offcanvas-body").innerHTML=s?s.innerHTML:'<p class="text-danger">No se encontró el contenido.</p>';const l=CourseNav.getCurrentSlide().title;e.querySelectorAll("section[data-title]").forEach((e=>{e.dataset.title===l?e.classList.remove("d-none"):e.classList.add("d-none")})),t.show()}catch(n){e.querySelector(".offcanvas-body").innerHTML='<p class="text-danger">Error al cargar el glosario.</p>',t.show()}}))})); |