1/** 2 * CoreCarouselNav â wiring partilhado do chrome de carrosséis Splide 3 * 4 * Usado por [destaques] (carousel.php) e [adsi_eventos] (EventosProximos::render_slider()) 5 * para ligar setas/paginação numérica/barra de progresso a uma instância Splide já montada, 6 * em vez de repetir a mesma lógica de getElementById + addEventListener + splide.on(...) 7 * em cada módulo. 8 */ 9(function (window) { 10 'use strict'; 11 12 // Textos de acessibilidade em português, aplicados a TODOS os carrosséis 13 // Splide do site (Splide.defaults é lido por cada "new Splide(...)" â 14 // nenhum módulo precisa de passar 'i18n' individualmente). 15 if (typeof Splide !== 'undefined') { 16 Splide.defaults = Object.assign({}, Splide.defaults, { 17 i18n: Object.assign({}, Splide.defaults && Splide.defaults.i18n, { 18 prev: 'Slide anterior', 19 next: 'Slide seguinte', 20 first: 'Ir para o primeiro slide', 21 last: 'Ir para o último slide', 22 slideX: 'Ir para o slide %s', 23 pageX: 'Ir para a página %s', 24 play: 'Iniciar reprodução automática', 25 pause: 'Parar reprodução automática', 26 carousel: 'carrossel', 27 slide: 'slide', 28 select: 'Selecionar um slide', 29 slideLabel: '%s de %s' 30 }) 31 }); 32 } 33 34 function wire(splide, opts) { 35 opts = opts || {}; 36 37 var prevBtn = opts.prevId ? document.getElementById(opts.prevId) : null; 38 var nextBtn = opts.nextId ? document.getElementById(opts.nextId) : null; 39 var numericEl = opts.numericId ? document.getElementById(opts.numericId) : null; 40 var progressFill = opts.progressFillId ? document.getElementById(opts.progressFillId) : null; 41 var paginationMount = opts.paginationMountId ? document.getElementById(opts.paginationMountId) : null; 42 var total = opts.total || 0; 43 var disableAtBounds = !!opts.disableAtBounds; 44 45 if (prevBtn) { prevBtn.addEventListener('click', function () { splide.go('<'); }); } 46 if (nextBtn) { nextBtn.addEventListener('click', function () { splide.go('>'); }); } 47 48 function currentEnd() { 49 if (splide.Components && splide.Components.Controller && splide.Components.Controller.getEnd) { 50 return splide.Components.Controller.getEnd(); 51 } 52 var perPage = (splide.options && splide.options.perPage) || 1; 53 return Math.max(total - perPage, 0); 54 } 55 56 function update(index) { 57 if (numericEl) { 58 numericEl.textContent = String(index + 1); 59 } 60 61 if (progressFill) { 62 var end = currentEnd(); 63 var pct = end > 0 ? (index / end) * 100 : 100; 64 progressFill.style.width = pct + '%'; 65 } 66 67 if (disableAtBounds) { 68 var end2 = currentEnd(); 69 if (prevBtn) { prevBtn.disabled = (index <= 0); } 70 if (nextBtn) { nextBtn.disabled = (index >= end2); } 71 } 72 } 73 74 function relocatePagination() { 75 if (!paginationMount) { return; } 76 var paginationEl = splide.root && splide.root.querySelector('.splide__pagination'); 77 if (paginationEl && paginationEl.parentNode !== paginationMount) { 78 var pagClass = paginationMount.getAttribute('data-pag-class'); 79 if (pagClass) { 80 pagClass.trim().split(/\s+/).forEach(function (c) { if (c) paginationEl.classList.add(c); }); 81 } 82 paginationMount.appendChild(paginationEl); 83 } 84 } 85 86 splide.on('mounted', function () { 87 update(splide.index); 88 relocatePagination(); 89 }); 90 splide.on('moved', function (newIndex) { update(newIndex); }); 91 splide.on('resized', function () { update(splide.index); }); 92 93 // Se wire() for chamado depois de mount() já ter ocorrido (is-initialized presente), 94 // o evento 'mounted' nunca disparará â executar imediatamente. 95 if (splide.root && splide.root.classList.contains('is-initialized')) { 96 update(splide.index); 97 relocatePagination(); 98 } 99 } 100 101 window.CoreCarouselNav = window.CoreCarouselNav || {}; 102 window.CoreCarouselNav.wire = wire; 103})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.