1document.addEventListener('DOMContentLoaded', () => { 2 const sliderContainers = document.querySelectorAll('.ed-container'); 3 4 sliderContainers.forEach((container) => { 5 const listItems = container.querySelectorAll('.ed-list-item'); 6 const btnPrev = container.querySelector('.ed-prev'); 7 const btnNext = container.querySelector('.ed-next'); 8 const mainImg = container.querySelector('.ed-main-img'); 9 const mainCat = container.querySelector('.ed-cat'); 10 const mainDate = container.querySelector('.ed-date'); 11 const mainTitle = container.querySelector('.ed-title-main a'); 12 const mainExcerpt = container.querySelector('.ed-excerpt'); 13 const mainLink = container.querySelector('.ed-read-more'); 14 15 let currentIndex = 0; 16 const totalItems = listItems.length; 17 let autoplayInterval = null; 18 19 if (totalItems === 0) return; 20 21 const updateMainPanel = (index) => { 22 listItems.forEach((item) => { 23 item.classList.remove('is-active'); 24 item.setAttribute('aria-current', 'false'); 25 }); 26 27 const activeItem = container.querySelector(`.ed-list-item[data-index="${index}"]`); 28 if (!activeItem) return; 29 30 activeItem.classList.add('is-active'); 31 activeItem.setAttribute('aria-current', 'true'); 32 33 const data = activeItem.dataset; 34 35 if (mainImg) { 36 mainImg.style.opacity = '0.45'; 37 setTimeout(() => { 38 if (data.img) { 39 mainImg.src = data.img; 40 mainImg.style.display = 'block'; 41 } 42 mainImg.alt = data.title || ''; 43 mainImg.style.opacity = '1'; 44 }, 220); 45 } 46 47 if (mainCat) mainCat.textContent = data.cat || ''; 48 if (mainDate) mainDate.textContent = data.date || ''; 49 if (mainTitle) { 50 mainTitle.textContent = data.title || ''; 51 mainTitle.href = data.url || '#'; 52 } 53 if (mainExcerpt) mainExcerpt.textContent = data.excerpt || ''; 54 if (mainLink) mainLink.href = data.url || '#'; 55 56 currentIndex = parseInt(index, 10) || 0; 57 }; 58 59 const goNext = () => updateMainPanel((currentIndex + 1) % totalItems); 60 const goPrev = () => updateMainPanel(currentIndex - 1 < 0 ? totalItems - 1 : currentIndex - 1); 61 62 const startAutoplay = () => { 63 if (window.matchMedia('(prefers-reduced-motion: reduce)').matches || totalItems < 2) return; 64 stopAutoplay(); 65 autoplayInterval = setInterval(goNext, 5000); 66 }; 67 68 const stopAutoplay = () => { 69 if (autoplayInterval) clearInterval(autoplayInterval); 70 }; 71 72 container.addEventListener('mouseenter', stopAutoplay); 73 container.addEventListener('mouseleave', startAutoplay); 74 container.addEventListener('focusin', stopAutoplay); 75 container.addEventListener('focusout', startAutoplay); 76 77 listItems.forEach((item) => { 78 item.setAttribute('aria-current', item.classList.contains('is-active') ? 'true' : 'false'); 79 item.addEventListener('click', function (event) { 80 event.preventDefault(); 81 updateMainPanel(this.dataset.index); 82 }); 83 item.addEventListener('keydown', function (event) { 84 if (event.key === 'Enter' || event.key === ' ') { 85 event.preventDefault(); 86 updateMainPanel(this.dataset.index); 87 } 88 }); 89 }); 90 91 if (btnPrev) btnPrev.addEventListener('click', goPrev); 92 if (btnNext) btnNext.addEventListener('click', goNext); 93 94 startAutoplay(); 95 }); 96
97 const loadMoreButtons = document.querySelectorAll('.ed-btn-load-more'); 98 99 loadMoreButtons.forEach((button) => { 100 const wrapper = button.closest('.ed-grid-wrapper'); 101 const gridContainer = wrapper ? wrapper.querySelector('.ed-grid-container') : document.getElementById('ed-news-grid-container'); 102 103 if (!gridContainer) return; 104 105 button.addEventListener('click', async function () { 106 const btn = this; 107 const currentPage = parseInt(btn.dataset.page, 10) || 1; 108 const maxPage = parseInt(btn.dataset.max, 10) || 1; 109 const nextPage = currentPage + 1; 110 111 if (btn.classList.contains('is-loading') || nextPage > maxPage) return; 112 113 btn.classList.add('is-loading'); 114 btn.setAttribute('aria-busy', 'true'); 115 const originalText = btn.textContent; 116 btn.textContent = 'A carregar...'; 117 118 const formData = new FormData(); 119 formData.append('action', 'load_more_ed_news'); 120 formData.append('nonce', window.ed_ajax?.nonce || ''); 121 formData.append('page', nextPage); 122 formData.append('posts', btn.dataset.posts || '6'); 123 formData.append('cat', btn.dataset.cat || ''); 124 formData.append('tags', btn.dataset.tags || ''); 125 126 try { 127 const response = await fetch(window.ed_ajax?.ajaxurl || '', { 128 method: 'POST', 129 credentials: 'same-origin', 130 body: formData, 131 }); 132 133 const data = await response.json(); 134 135 if (data.success && data.data) { 136 gridContainer.insertAdjacentHTML('beforeend', data.data); 137 btn.dataset.page = String(nextPage); 138 139 if (nextPage >= maxPage && btn.parentElement) { 140 btn.parentElement.style.display = 'none'; 141 } 142 } 143 } catch (error) { 144 console.error('Erro ao carregar mais notÃcias:', error); 145 } finally { 146 btn.classList.remove('is-loading'); 147 btn.removeAttribute('aria-busy'); 148 btn.textContent = originalText; 149 } 150 }); 151 }); 152});
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.