1 line
5.0 KiB
JavaScript
1 line
5.0 KiB
JavaScript
function renderPagination(e,t){const n=document.getElementById("coursenav-page-number"),o=document.getElementById("coursenav-total-pages");if(!Array.isArray(t))return;manageMenuVisibility(e,t);const r=t[e];if(!r)return;const s=t.filter((e=>e.moduleTitle===r.moduleTitle)),l=s.findIndex((e=>e.content===r.content));n&&(n.textContent=l+1),o&&(o.textContent=" / "+s.length),updateNavButtons(l,s)}function updateNavButtons(e,t){const n=document.getElementById("coursenav-next-btn"),o=document.getElementById("coursenav-prev-btn");if(!n||!o)return;const r=e+1===t.length,s=0===e,l=CourseNav.isDebug();n.classList.toggle("disabled",r&&!l),o.classList.toggle("disabled",s&&!l)}function manageMenuVisibility(e,t){const n=document.querySelectorAll("#coursenav-main-menu > ul.course-menu");if(!n.length)return;if(n[0].style.display="block",!Array.isArray(t)||!t.length){for(let e=1;e<n.length;e++)n[e].style.display="none";return}const o=t[e];if(!o?.moduleTitle){for(let e=1;e<n.length;e++)n[e].style.display="none";return}const r=o.moduleTitle;for(let e=1;e<n.length;e++){const o=Array.from(n[e].querySelectorAll(".coursenav-link")).some((e=>{const n=parseInt(e.dataset.coursenavindex);return n>=0&&t[n]?.moduleTitle===r}));n[e].style.display=o?"block":"none"}}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:r=!0,prefix:s="animate__animated"}=n,l=new IntersectionObserver(((e,n)=>{e.forEach((e=>{e.isIntersecting?(e.target.classList.add(s,t),r&&n.unobserve(e.target)):r||e.target.classList.remove(s,t)}))}),{threshold:o});return document.querySelectorAll(e).forEach((e=>l.observe(e))),l}function scaleWrapCourseContent(){const e=document.querySelector(".wrap-course-content");if(!e)return;const t=window.innerWidth,n=window.innerHeight;let o,r;t<1500?(o=1366,r=768):(o=1920,r=1080);const s=Math.min(t/o,n/r);e.style.transform=`scale(${s})`,e.style.transformOrigin="top left",e.style.width=o+"px",e.style.height=r+"px",e.style.position="absolute",e.style.left=(t-o*s)/2+"px",e.style.top=(n-r*s)/2+"px",e.style.overflow="hidden",e.style.zIndex="1"}function renderStepper(e,t,n,o=5){if("string"==typeof e&&(e=document.querySelector(e)),"string"==typeof n&&(n=document.querySelector(n)),!(e instanceof HTMLElement&&n instanceof HTMLElement))throw new Error("renderStepper: elementos inválidos.");e.querySelectorAll(".step").forEach((e=>e.remove()));const r=Array.from({length:o},((e,t)=>t/(o-1)*100)),s=r.map(((e,t)=>({p:e,i:t}))).filter((({p:e})=>e<=t)).pop().i;r.forEach(((t,n)=>{const o=document.createElement("div");o.classList.add("step"),n<s&&o.classList.add("completed"),n===s&&(o.classList.add("completed"),o.setAttribute("data-label",Math.round(t)+"%")),e.appendChild(o)})),e.style.setProperty("--pct",t+"%");const l=n.offsetWidth;n.style.left=`calc(${t}% - ${l}px)`,n.setAttribute("data-label",t+"%")}function gotoFirstMenuToolSlide(){const e=CourseNav.getCourseContentArray(),t=CourseNav.getCurrentSlide(),n=e.findIndex((e=>"Menús de la herramienta"===e.title&&e.moduleTitle===t.moduleTitle));-1!==n&&CourseNav.gotoSlide(n)}window.COURSE_CONFIG={COURSE_CONFIG_URL:"config.json",DEBUG:!0},document.addEventListener("DOMContentLoaded",(()=>{let e;scaleWrapCourseContent(),setTimeout(scaleWrapCourseContent,100),window.addEventListener("resize",(()=>{clearTimeout(e),e=setTimeout(scaleWrapCourseContent,50)})),window.addEventListener("orientationchange",(()=>{setTimeout(scaleWrapCourseContent,200)})),document.addEventListener("visibilitychange",(()=>{document.hidden||setTimeout(scaleWrapCourseContent,100)})),document.body.addEventListener("beforeSlideChange",(e=>{})),document.body.addEventListener("slideChange",(e=>{if(e.detail&&"number"==typeof e.detail.slideIndex&&Array.isArray(e.detail.contentArray)){renderPagination(e.detail.slideIndex,e.detail.contentArray);const t=e.detail.contentArray,n="Menús de la herramienta",o=CourseNav.getCurrentSlide(),r=t.findIndex((e=>e.title===n&&e.moduleTitle===o.moduleTitle)),s=document.getElementById("coursenav-other-btn");if(!s)return;-1!==r?s.classList.remove("disabled"):s.classList.add("disabled")}const t=document.getElementById("coursenav-course-title");if(t){const n=e.detail.contentArray[e.detail.slideIndex],o=n.moduleTitle?n.moduleTitle+" | ":"",r=n.title||"Sin título";t.textContent=o+r}const n=document.getElementById("stepper"),o=document.getElementById("step-movil");renderStepper(n,CourseNav.getProgressPercent(!0),o)})),document.body.addEventListener("slideCompleted",(e=>{const t=document.getElementById("stepper"),n=document.getElementById("step-movil");renderStepper(t,CourseNav.getProgressPercent(!0),n),renderPagination(e.detail.slideIndex,CourseNav.getCourseContentArray())}));const t=document.getElementById("coursenav-other-btn");t&&t.addEventListener("click",(()=>{gotoFirstMenuToolSlide()}))})),window.addEventListener("DOMContentLoaded",(()=>scaleWrapCourseContent())),window.addEventListener("resize",(()=>scaleWrapCourseContent())); |