1define(function (){ 2 let timerIDCardCarrossel = 0; 3 let timerIDBannerPrincipal = 0; 4 let timerIDNoticias = 0; 5 let timerIDDestaque = 0; 6 return { 7 ajustarQtdIconesAcessoRapido: () => { 8 ajustaIconesNaTela(); 9 window.addEventListener('resize', () => { 10 ajustaIconesNaTela(); 11 }); 12 }, 13 verificaEdicaoPortletCards: () => { 14 let observer = new MutationObserver(elementoAdicionadoCallback); 15 observer.observe(document.body, { childList: true}); 16 }, 17 18 verificaPortletDestaques: () => { 19 const portletDestaque = document.querySelector('[data-tipo-destaques="destaques"]'); 20 if (!portletDestaque){ 21 return 22 } 23 controlaDestaques(); 24 }, 25 26 verificaCardCarrossel: () => { 27 // Tratamento para o card de Carrossel 28 const cardCarrossel = document.querySelector('[data-tipo-card="cardCarrossel"]'); 29 if (cardCarrossel){ 30 const tempoImagemEmSegundos = parseInt(document.querySelectorAll('[data-card-tempo-imagem="qtdTempoImagem"]')[0].value) * 1000; 31 const listaImagens = document.querySelectorAll('[data-imagem-card="imagemCard"]'); 32 const anterior = document.querySelector('[data-cards-imagem-anterior="ImagemAnterior"]'); 33 const proximo = document.querySelector('[data-cards-proxima-imagem="ProximaImagem"]'); 34 anterior.addEventListener('click', () => { 35 apresentaImagemAnterior(listaImagens, tempoImagemEmSegundos); 36 }); 37 proximo.addEventListener('click', () => { 38 apresentaProximaImagem(listaImagens, tempoImagemEmSegundos); 39 }); 40 rotacionaImagens(listaImagens, tempoImagemEmSegundos); 41 } 42 }, 43 44 verificaPortletNoticias: () => { 45 // Tratamento para o portlet de notÃcias 46 const portletNoticias = document.querySelector('[data-portlet-noticias="portletNoticias"]'); 47 if (portletNoticias){ 48 const tempoNoticiasEmSegundos = parseInt(document.querySelectorAll('[data-tempo-noticia="qtdTempoNoticia"')[0].value) * 1000; 49 const listaNoticias = document.querySelectorAll('[data-bloco-noticia="BlocoNoticia"]'); 50 const noticiaAnterior = document.querySelector('[data-noticia-anterior="NoticiaAnterior"]'); 51 const proximaNoticia = document.querySelector('[data-proxima-noticia="ProximaNoticia"]'); 52 noticiaAnterior.addEventListener('click', () => { 53 apresentaNoticiaAnterior(listaNoticias, tempoNoticiasEmSegundos); 54 }); 55 proximaNoticia.addEventListener('click', () => { 56 apresentaProximaNoticia(listaNoticias, tempoNoticiasEmSegundos); 57 }); 58 rotacionaNoticias(listaNoticias, tempoNoticiasEmSegundos); 59 } 60 }, 61 62 verificaBanner: () => { 63 // Tratamento do Banner Interno 64 const bannerInterno = document.querySelectorAll('.bannerInterno [data-banner-home]'); 65 if (bannerInterno.length){ 66 for (let i = 0; i < bannerInterno.length; i++){ 67 bannerInterno[i].classList.remove('oculta-elemento'); 68 } 69 } 70 71 // Gerenciamento da rotação das imagens e da barra de navegação no banner principal 72 const mainBannerCntnr = document.querySelector( '.bannerPrincipal' ) 73 const banners = mainBannerCntnr.querySelectorAll( '[data-banner-home]' ) 74 if ( banners ){ 75 let startPosition = 0 76 const tempoBannerEmSegundos = parseInt( document.querySelectorAll( '.bannerPrincipal [data-tempo-banner="qtd_tempo_banner"]' )[0].value ) * 1000 77 rotacionaBanner( banners, tempoBannerEmSegundos ) 78 // Scroll horizontal dos banners por meio do movimento de mouse 79 mainBannerCntnr.addEventListener( 'dragstart', ( event ) => startPosition = event.clientX ) 80 mainBannerCntnr.addEventListener( 'dragend', ( event ) => { 81 clearTimeout( timerIDBannerPrincipal ) 82 const visibleBannerIdx = parseInt( mainBannerCntnr.querySelector( '.bannerPrincipal .banner-home:not( .oculta-elemento )' ).getAttribute( 'data-id
82x' )) 83 const incr = startPosition > event.clientX ? 1 : -1 84 let nextVisibleBannerIdx = ( visibleBannerIdx + incr ) in [ ... Array( banners.length ).keys()] ? visibleBannerIdx + incr : [ banners.length - 1, 0 ][[ -1, banners.length ].indexOf( visibleBannerIdx + incr )] 85 giraBanner( nextVisibleBannerIdx, banners, tempoBannerEmSegundos ) 86 manageBullets( visibleBannerIdx, nextVisibleBannerIdx ) 87 }) 88 // Scroll horizontal dos banners por meio de touch 89 mainBannerCntnr.addEventListener( 'touchstart', ( event ) => startPosition = event.changedTouches[0].clientX ) 90 mainBannerCntnr.addEventListener( 'touchend', ( event ) => { 91 if ( Math.abs( startPosition - event.changedTouches[0].clientX) < 2 ) return 92 clearTimeout( timerIDBannerPrincipal ) 93 const visibleBannerIdx = parseInt( mainBannerCntnr.querySelector( '.bannerPrincipal .banner-home:not( .oculta-elemento )' ).getAttribute( 'data-idx' )) 94 const incr = startPosition > event.changedTouches[0].clientX ? 1 : -1 95 let nextVisibleBannerIdx = ( visibleBannerIdx + incr ) in [ ... Array( banners.length ).keys()] ? visibleBannerIdx + incr : [ banners.length - 1, 0 ][[ -1, banners.length ].indexOf( visibleBannerIdx + incr )] 96 giraBanner( nextVisibleBannerIdx, banners, tempoBannerEmSegundos ) 97 manageBullets( visibleBannerIdx, nextVisibleBannerIdx ) 98 }) 99 } 100 } 101 102 } 103 104 // InÃcio do tratamento dos Ãcones do acesso rápido 105 function ajustaIconesNaTela(){ 106 const listaAcessoRapido = document.querySelectorAll('[data-portlet-acesso-rapido]') 107 if (listaAcessoRapido.length) { 108 verificaQTDIcones(listaAcessoRapido); 109 } 110 } 111 112 function verificaQTDIcones(listaAcessoRapido){ 113 for (let i = 0; i < listaAcessoRapido.length; i++){ 114 let formRastreamento = listaAcessoRapido[i].querySelector('[data-form-acesso-rapido]'); 115 if (formRastreamento){ 116 let acessoRapido = listaAcessoRapido[i].querySelector('[data-portlet-acesso-rapido-links]'); 117 ajustaIconesATela(acessoRapido); 118 }procuraNoticiaVisivel 119 } 120 } 121 122 function ajustaIconesATela(acessoRapido){ 123 const listaItemAcessoRapido = acessoRapido.querySelectorAll('[data-item-acesso-rapido]'); 124 if (tamanhoTela() < 992 ){ 125 ocultarIcones(listaItemAcessoRapido); 126 } else { 127 apresentaIcones(listaItemAcessoRapido); 128 } 129 } 130 131 function tamanhoTela(){ 132 return window.innerWidth 133 } 134 135 function ocultarIcones(listaItemAcessoRapido){ 136 for (let i = (listaItemAcessoRapido.length - 1); i > 3; i--){ 137 listaItemAcessoRapido[i].classList.add("oculta-elemento"); 138 } 139 } 140 141 function apresentaIcones(listaItemAcessoRapido){ 142 for (let i = (listaItemAcessoRapido.length - 1); i > 3; i--){ 143 listaItemAcessoRapido[i].classList.remove("oculta-elemento"); 144 } 145 } 146 // Fim do tratamento dos Ãcones do acesso rápido 147 148 // InÃcio do tratamento para habilitar/desabilitar campos do cadastro dos portlets do tipo Card 149 function elementoAdicionadoCallback(mutationsList, observer) { 150 for (var mutation of mutationsList) { 151 if (mutation.type === 'childList') { 152 setTimeout(() => { 153 // Tratamento para edição dos Cards 154 const edicaoPortletCard = document.querySelectorAll('.section-homepage.template-manage-portlets .plone-modal-dialog .plone-modal-body form #formfield-form-widgets-tipo_portlet'); 155 if (edicaoPortletCard.length){ 156 adequaTelaPortletCards(edicaoPortletCard[0]); 157 edicaoPortletCard[0].addEventListener("mouseleave", () => { 158 adequaTelaPortletCards(document.querySelectorAll('.section-homepage.template-manage-portlets .plone-modal-dialog .plone-modal-body form #formfield-form-widgets-tipo_portlet')[0]); 159 })} 160 // Tratamento para a edição dos Banners 161 const edicaoPortletBanner = document.querySelectorAll('.section-homepage.template-manage-portlets .plone-modal-dialog .plone-modal-body form #formfield-form-widgets-tipo_banner'); 162 if (edicaoPortletBanner.length){ 163 adequaTelaPortletBanner(edicaoPortletBanner[0]); 164 edicaoPortletBanner[0].addEventListener("mouseleave", () => { 165 adequaTelaPortletBanner(document.querySelectorAll('.section-homepage.template-manage-portlets .plone-modal-dialog .plone-modal-body form #formfield-form-widgets-tipo_banner')[0]); 166 })} 167 },1000); 168 } 169 } 170 } 171 172 function adequaTelaPortletCards(portletCorreto){ 173 const listaObjsTipoPortlet = montaObjetosTipoCard(); 174 const listaTipoPortlet = ['cards', 'cardCarrossel', 'cardsMenu', 'produtoDia']; 175 const formulario = portletCorreto.parentNode; 176 const tipoPortlet = formulario.querySelector('#form-widgets-tipo_portlet').value 177 const indice = listaTipoPortlet.indexOf(tipoPortlet); 178 ajustaCamposFormulario(listaObjsTipoPortlet[indice], formulario); 179 } 180 181 function montaObjetosTipoCard(){ 182 const mensagemImagem = ' Selecione a imagem do Card ' 183 const textoTituloLink1 = ' TÃtulo do link ' 184 const cards = { camposLink: true, 185 imagens: true, 186 textoImagens: mensagemImagem, 187 textoTituloLink1: textoTituloLink1 188 }; 189 const cardCarrossel = { camposLink: true, 190 imagens: false, 191 textoImagens: ' Selecione a pasta com as imagens que serão rotacionadas no Card ', 192 textoTituloLink1: textoTituloLink1 193 }; 194 const cardsMenu = { camposLink: false, 195 imagens: true, 196 textoImagens: mensagemImagem, 197 textoTituloLink1: textoTituloLink1 198 }; 199 const produtoDia = {camposLink: true, 200 imagens: true, 201 textoImagens: mensagemImagem, 202 textoTituloLink1: "Texto para o botão do produto do dia"}; 203 return [cards, cardCarrossel, cardsMenu, produtoDia] 204 } 205 206 function ajustaCamposFormulario(objeto, formulario){ 207 formulario.querySelector('#form-widgets-titulo_link2').disabled = objeto.camposLink; 208 formulario.querySelector('#form-widgets-link2').disabled = objeto.camposLink; 209 formulario.querySelector('#form-widgets-titulo_link3').disabled = objeto.camposLink; 210 formulario.querySelector('#form-widgets-link3').disabled = objeto.camposLink; 211 formulario.querySelector('#form-widgets-qtd_imagem').disabled = objeto.imagens; 212 formulario.querySelector('#form-widgets-qtd_tempo_imagem').disabled = objeto.imagens; 213 formulario.querySelector('#formfield-form-widgets-imagem label').innerHTML = objeto.textoImagens; 214 formulario.querySelector('#formfield-form-widgets-titulo_link1 label').innerHTML = objeto.textoTituloLink1; 215 } 216 // Fim do tratamento para habilitar/desabilitar campos do cadastro dos portlets do tipo Card 217 218 // InÃcio do tratamento da rotação das imagens do Card Carrossel 219 function rotacionaImagens(listaImagens, tempoImagemEmSegundos){ 220 if (!listaImagens || listaImagens.length == 0){ 221 return "" 222 } 223 listaImagens = giraElementos(0, listaImagens, tempoImagemEmSegundos); 224 } 225 226 function giraElementos(indice, listaImagens, tempoImagemEmSegundos){ 227 indice = movimentaElementos(indice, listaImagens); 228 timerIDCardCarrossel = setTimeout(() => { 229 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 230 }, tempoImagemEmSegundos); 231 } 232 233 function movimentaElementos(indice, listaImagens){ 234 for (let x = 0; x < listaImagens.length; x++){ 235 if (x == indice){ 236 listaImagens[x].classList.remove("oculta-elemento"); 237 indice = x; 238 continue; 239 } 240 listaImagens[x].classList.add("oculta-elemento"); 241 } 242 indice++; 243 if (indice == listaImagens.length){ 244 indice = 0; 245 } 246 return indice 247 } 248 249 function apresentaImagemAnterior(listaImagens, tempoImagemEmSegundos){ 250 let indice = procuraElementoVisivel(listaImagens) 251 indice--; 252 if (indice < 0){ 253 indice = listaImagens.length - 1; 254 } 255 clearTimeout(timerIDCardCarrossel); 256 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 257 } 258 259 function apresentaProximaImagem(listaImagens, tempoImagemEmSegundos){ 260 let indice = procuraElementoVisivel(listaImagens) 261 indice++ 262 if (indice == listaImagens.length){ 263 indice = 0; 264 } 265 clearTimeout(timerIDCardCarrossel); 266 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 267 } 268 269 function procuraElementoVisivel(listaImagens){ 270 for (let x = 0; x < listaImagens.length; x++){ 271 if (!listaImagens[x].classList.contains("oculta-elemento")){ 272 return x; 273 } 274 } 275 } 276 // Fim do tratamento da rotação das imagens do Card Carrossel 277 278 // InÃcio do tratamento para habilitar/desabilitar campos do cadastro dos portlets do tipo Banner 279 function adequaTelaPortletBanner(portletBanner){ 280 const listaObjsTipoPortlet = montaObjetosTipoBanner(); 281 const listaTipoPortlet = ['bannerInterno', 'bannerPrincipal']; 282 const formularioBanner = portletBanner.parentNode; 283 const tipoPortlet = formularioBanner.querySelector('#form-widgets-tipo_banner').value 284 const indice = listaTipoPortlet.indexOf(tipoPortlet); 285 ajustaCamposBanner(listaObjsTipoPortlet[indice], formularioBanner); 286 } 287 288 function montaObjetosTipoBanner(){ 289 const bannerInterno = { mensagem: ' Selecione o banner que será apresentado como banner interno ', 290 qtd_banner: true, 291 qtd_tempo_banner: true 292 }; 293 const bannerPrincipal = { mensagem: ' Selecione a pasta com os banners que serão apresentados ', 294 qtd_banner: false, 295 qtd_tempo_banner: false 296 }; 297 return [bannerInterno, bannerPrincipal] 298 } 299 300 function ajustaCamposBanner(objeto, formularioBanner){ 301 formularioBanner.querySelector('#form-widgets-qtd_banner').disabled = objeto.qtd_banner; 302 formularioBanner.querySelector('#formfield-form-widgets-banner label').innerHTML = objeto.mensagem; 303 formularioBanner.querySelector('#form-widgets-qtd_tempo_banner').disabled = objeto.qtd_tempo_banner; 304 } 305 // Fim do tratamento para habilitar/desabilitar campos do cadastro dos portlets do tipo Banner 306 307 // InÃcio do tratamento da rotação das imagens do Card Carrossel 308 function rotacionaImagens(listaImagens, tempoImagemEmSegundos){ 309 if (!listaImagens || listaImagens.length == 0){ 310 return "" 311 } 312 listaImagens = giraElementos(0, listaImagens, tempoImagemEmSegundos); 313 } 314 315 function giraElementos(indice, listaImagens, tempoImagemEmSegundos){ 316 indice = movimentaElementos(indice, listaImagens); 317 timerIDCardCarrossel = setTimeout(() => { 318 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 319 }, tempoImagemEmSegundos); 320 } 321 322 function movimentaElementos(indice, listaImagens){ 323 for (let x = 0; x < listaImagens.length; x++){ 324 if (x == indice){ 325 listaImagens[x].classList.remove("oculta-elemento"); 326 indice = x; 327 continue; 328 } 329 listaImagens[x].classList.add("oculta-elemento"); 330 } 331 indice++; 332 if (indice == listaImagens.length){ 333 indice = 0; 334 } 335 return indice 336 } 337 338 function apresentaImagemAnterior(listaImagens, tempoImagemEmSegundos){ 339 let indice = procuraElementoVisivel(listaImagens) 340 indice--; 341 if (indice < 0){ 342 indice = listaImagens.length - 1; 343 } 344 clearTimeout(timerIDCardCarrossel); 345 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 346 } 347 348 function apresentaProximaImagem(listaImagens, tempoImagemEmSegundos){ 349 let indice = procuraElementoVisivel(listaImagens) 350 indice++ 351 if (indice == listaImagens.length){ 352 indice = 0; 353 } 354 clearTimeout(timerIDCardCarrossel); 355 giraElementos(indice, listaImagens, tempoImagemEmSegundos); 356 } 357 358 function procuraElementoVisivel(listaImagens){ 359 for (let x = 0; x < listaImagens.length; x++){ 360 if (!listaImagens[x].classList.contains("oculta-elemento")){ 361 return x; 362 } 363 } 364 } 365 // Fim do tratamento da rotação das imagens do Card Carrossel 366 367 // InÃcio do tratamento da rotação do banner principal 368 function rotacionaBanner(listaBanners, tempoBannerEmSegundos){ 369 adicionaBullets(listaBanners.length); 370 listaBanners = giraBanner(0, listaBanners, tempoBannerEmSegundos); 371 } 372 373 function giraBanner(indice, listaBanners, tempoBannerEmSegundos){ 374 indice = movimentaBanner(indice, listaBanners); 375 timerIDBannerPrincipal = setTimeout(() => { 376 giraBanner(indice, listaBanners, tempoBannerEmSegundos); 377 }, tempoBannerEmSegundos); 378 } 379 380 function recuperaBullets(){ 381 return document.querySelectorAll('[data-bullet-banner-principal]'); 382 } 383 384 function movimentaBanner(indice, listaBanners){ 385 for (let x = 0; x < listaBanners.length; x++){ 386 if (x == indice){ 387 listaBanners[x].classList.remove("oculta-elemento"); 388 movimentaBullet(x); 389 indice = x; 390 continue; 391 } 392 listaBanners[x].classList.add("oculta-elemento"); 393 } 394 indice++; 395 if (indice == listaBanners.length){ 396 indice = 0; 397 } 398 return indice 399 } 400 401 // Gerencia a exibição dos bullets no banner principal, independentemente do sentido do scroll horizontal 402 function manageBullets( oldIdx, newIdx ) { 403 const divBullet = recuperaBullets() 404 divBullet[ oldIdx ].classList.remove( 'circulo-preenchido' ) 405 divBullet[ newIdx ].classList.add( 'circulo-preenchido' ) 406 setTimeout( () => { ajustaPosicaoVerticalBullets() }, 10 ) 407 } 408 409 function movimentaBullet(x){ 410 const divBullet = recuperaBullets() 411 if (x > (divBullet.length - 1)){ 412 adicionaFundoPreenchido(divBullet[0]) 413 removeFundoPrenchido(divBullet[x - 1]); 414 } else { 415 adicionaFundoPreenchido(divBullet[x]) 416 if (x == 0){ 417 removeFundoPrenchido(divBullet[divBullet.length - 1]); 418 } else { 419 removeFundoPrenchido(divBullet[x - 1]); 420 } 421 } 422 setTimeout(() => {ajustaPosicaoVerticalBullets()},10); 423 } 424 425 function removeFundoPrenchido(bullet){ 426 bullet.classList.remove("circulo-preenchido"); 427 } 428 429 function adicionaFundoPreenchido(bullet){ 430 bullet.classList.add("circulo-preenchido"); 431 } 432 433 function adicionaBullets(qtdBullets){ 434 const listaBullet = document.querySelectorAll('[data-controle-imagem]'); 435 for (let x = 0; x < qtdBullets; x++){ 436 listaBullet[0].appendChild(montaContainer('circulo')); 437 } 438 ajustaPosicaoHorizontalBullets(); 439 criaEventoDeRedimensionamentoDeTela(); 440 criaEventoClick(); 441 } 442 443 function criaEventoDeRedimensionamentoDeTela(){ 444 window.addEventListener( 'resize', (e) => { 445 ajustaPosicaoHorizontalBullets(); 446 // ajustaPosicaoVerticalBullets(); 447 s
447etTimeout(() => {ajustaPosicaoVerticalBullets()},10); 448 }) 449 } 450 451 function ajustaPosicaoHorizontalBullets(){ 452 const larguraTela = window.innerWidth; 453 const Bullets = document.querySelector('[data-controle-imagem]'); 454 const larguraBullets = Bullets.offsetWidth; 455 const metadeLaguraBullets = Math.floor(larguraBullets/2); 456 const percentualARetirar = ((100 * metadeLaguraBullets)/larguraTela); 457 const posicaoBullet = 50 - percentualARetirar; 458 Bullets.style.left = posicaoBullet.toString() + '%'; 459 } 460 461 function ajustaPosicaoVerticalBullets(){ 462 const listaBanner = document.querySelectorAll('[data-banner-home]'); 463 const bullet = document.querySelector('[data-controle-imagem]'); 464 for (banner of listaBanner){ 465 if (banner.classList.contains("oculta-elemento")){ 466 continue; 467 } 468 const listaImagens = banner.querySelectorAll('img'); 469 let posicaoBullets = 0; 470 let percentualASerRetirado = 95; 471 let alturaImagem = listaImagens[1].offsetHeight; 472 if (tamanhoTela() > 0 && tamanhoTela() <= 768) { 473 ocultaTextoBanner(banner); 474 percentualASerRetirado = 95; 475 alturaImagem = listaImagens[0].offsetHeight; 476 } else if (tamanhoTela() > 768 && tamanhoTela() < 1200) { 477 percentualASerRetirado = 90; 478 alturaImagem = listaImagens[1].offsetHeight; 479 } 480 posicaoBullets = ((alturaImagem * percentualASerRetirado)/ 100); 481 if (alturaImagem == 0){ 482 bullet.style.top = 90 + '%'; 483 } else { 484 bullet.style.top = posicaoBullets + 'px'; 485 } 486 } 487 } 488 489 function ocultaTextoBanner(banner){ 490 const paragrafo = banner.querySelector('[data-texto-sobre_imagem] .paragrafo-titulo'); 491 const descricao = banner.querySelector('[data-texto-sobre_imagem] .paragrafo-descricao'); 492 if (!paragrafo || !descricao){ 493 return 494 } 495 if (paragrafo.textContent.trim() == "" && descricao.textContent.trim() == ""){ 496 banner.querySelector('[data-texto-sobre_imagem]').classList.add('oculta-elemento'); 497 } 498 } 499 500 function criaEventoClick(){ 501 const bullets = recuperaBullets(); 502 const bannerPrincipal = document.querySelectorAll('.bannerPrincipal [data-banner-home]'); 503 const tempoBannerEmSegundos = parseInt(document.querySelectorAll('.bannerPrincipal [data-tempo-banner="qtd_tempo_banner"]')[0].value) * 1000; 504 for (let x = 0; x < bullets.length; x++){ 505 bullets[x].addEventListener('click', () => { 506 ocultaBulletVisivel(bullets); 507 clearTimeout(timerIDBannerPrincipal); 508 giraBanner(x, bannerPrincipal, tempoBannerEmSegundos) 509 }) 510 } 511 } 512 513 function montaContainer(classe){ 514 const containerBullet = document.createElement('div'); 515 containerBullet.dataset.bulletBannerPrincipal = 'bullet-banner'; 516 containerBullet.classList.add(classe); 517 return containerBullet 518 } 519 520 function ocultaBulletVisivel(lista){ 521 for (let x = 0; x < lista.length; x++){ 522 if (lista[x].classList.contains("circulo-preenchido")){ 523 removeFundoPrenchido(lista[x]) 524 } 525 } 526 } 527 // Fim do tratamento da rotação do banner principal 528 529 // InÃcio do tratamento da rotação das notÃcias 530 function rotacionaNoticias(listaNoticias, tempoNoticiasEmSegundos){ 531 if (!listaNoticias || listaNoticias.length == 0){ 532 return "" 533 } 534 listaNoticias = giraNoticias(0, listaNoticias, tempoNoticiasEmSegundos); 535 } 536 537 function giraNoticias(indiceNoticia, listaNoticias, tempoNoticiasEmSegundos){ 538 indiceNoticia = movimentaNoticias(indiceNoticia, listaNoticias); 539 timerIDNoticias = setTimeout(() => { 540 giraNoticias(indiceNoticia, listaNoticias, tempoNoticiasEmSegundos); 541 }, tempoNoticiasEmSegundos); 542 } 543 544 function movimentaNoticias(indiceNoticia, listaNoticias){ 545 for (let n = 0; n < listaNoticias.length; n++){ 546 if (n == indiceNoticia){ 547 listaNoticias[n].classList.remove("oculta-elemento"); 548 indiceNoticia = n; 549 continue; 550 } 551 listaNoticias[n].classList.add("oculta-elemento"); 552 } 553 indiceNoticia++; 554 if (indiceNoticia == listaNoticias.length){ 555 indiceNoticia = 0; 556 } 557 return indiceNoticia 558 } 559 560 function apresentaNoticiaAnterior(listaNoticias, tempoNoticiasEmSegundos){ 561 let indiceNoticia = procuraNoticiaVisivel(listaNoticias) 562 indiceNoticia--; 563 if (indiceNoticia < 0){ 564 indiceNoticia = listaNoticias.length - 1; 565 } 566 clearTimeout(timerIDNoticias); 567 giraNoticias(indiceNoticia, listaNoticias, tempoNoticiasEmSegundos); 568 } 569 570 function apresentaProximaNoticia(listaNoticias, tempoNoticiasEmSegundos){ 571 let indiceNoticia = procuraNoticiaVisivel(listaNoticias) 572 indiceNoticia++ 573 if (indiceNoticia == listaNoticias.length){ 574 indiceNoticia = 0; 575 } 576 clearTimeout(timerIDNoticias); 577 giraNoticias(indiceNoticia, listaNoticias, tempoNoticiasEmSegundos); 578 } 579 580 function procuraNoticiaVisivel(listaNoticias){ 581 for (let n = 0; n < listaNoticias.length; n++){ 582 if (!listaNoticias[n].classList.contains("oculta-elemento")){ 583 return n; 584 } 585 } 586 } 587 // Fim do tratamento da rotação das notÃcias 588 589 // InÃcio do tratamento dos destaques 590 591 592 function controlaDestaques(){ 593 let ehAnimado = false;
594 let intervalo = 0; 595 const destaques = document.querySelectorAll('[data-tipo-destaques="destaques"]'); 596 if (!destaques.length){ 597 return 598 } 599 const carrossel = document.querySelector('[data-container-carrossel="carrossel"]'); 600 const viewport = document.querySelector('[data-viewport="viewport"]'); 601 const btnEsquerda = document.querySelector('[data-set-botao-esquerda="esquerda"]'); 602 const btnDireita = document.querySelector('[data-set-botao-direita="direita"]'); 603 604 // Botões 605 btnDireita.addEventListener('click', () => { 606 proximoDestaque(carrossel, ehAnimado); 607 intervalo = resetIntervalo(intervalo, carrossel, ehAnimado); 608 }); 609 610 btnEsquerda.addEventListener('click', () => { 611 destaqueAnterior(carrossel, ehAnimado); 612 intervalo = resetIntervalo(intervalo, carrossel, ehAnimado); 613 }); 614 615 // Suporte a swipe (touch) 616 let startX = 0; 617 let endX = 0; 618 619 viewport.addEventListener('touchstart', (e) => { 620 startX = e.touches[0].clientX; 621 }); 622 623 viewport.addEventListener('touchend', (e) => { 624 endX = e.changedTouches[0].clientX; 625 const diffX = endX - startX; 626 627 if (Math.abs(diffX) > 50) { 628 if (diffX < 0) { 629 proximoDestaque(carrossel, ehAnimado); 630 } else { 631 destaqueAnterior(carrossel, ehAnimado); 632 } 633 intervalo = resetIntervalo(intervalo, carrossel, ehAnimado); 634 } 635 }); 636 637 // Suporte a drag com mouse 638 // let isDown = false; 639 // let startMouseX = 0; 640 // let endMouseX = 0; 641 642 // viewport.addEventListener('mousedown', (e) => { 643 // isDown = true; 644 // startMouseX = e.clientX; 645 // viewport.style.cursor = "grabbing"; 646 // }); 647 648 // viewport.addEventListener('mouseup', (e) => { 649 // if (!isDown) return; 650 // isDown = false; 651 // viewport.style.cursor = "grab"; 652 // endMouseX = e.clientX; 653 // const diffX = endMouseX - startMouseX; 654 655 // if (Math.abs(diffX) > 50) { 656 // if (diffX < 0) { 657 // proximoDestaque(carrossel, ehAnimado); 658 // } else { 659 // destaqueAnterior(carrossel, ehAnimado); 660 // } 661 // intervalo = resetIntervalo(intervalo, carrossel, ehAnimado); 662 // } 663 // }); 664 665 // viewport.addEventListener('mouseleave', () => { 666 // isDown = false; 667 // viewport.style.cursor = "grab"; 668 // }); 669 670 // Chame atualizarLayout sempre que a tela for redimensionada 671 window.addEventListener('resize', () => atualizarLayout(carrossel, btnEsquerda, btnDireita, viewport)); 672 673 // Chame ao iniciar 674 atualizarLayout(carrossel, btnEsquerda, btnDireita, viewport); 675 676 // autoplay inicial 677 intervalo = resetIntervalo(intervalo, carrossel, ehAnimado); 678 } 679 680 // function proximoDestaque(carrossel, ehAnimado){ 681 // const totalItems = carrossel.children.length; 682 // const itensVisiveis = getItensVisiveis(); // função que retorna quantos itens cabem na tela 683 684 // if (totalItems <= itensVisiveis) return; // nada a fazer, não desliza 685 686 // if (ehAnimado) return; 687 // ehAnimado = true; 688 689 // const itemWidth = carrossel.firstElementChild.offsetWidth + 10; 690 // carrossel.style.transform = `translateX(-${itemWidth}px)`; 691 692 // carrossel.addEventListener('transitionend', function handler() { 693 // carrossel.appendChild(carrossel.firstElementChild); 694 // carrossel.style.transition = 'none'; 695 // // carrossel.style.transform = 'translateX(0)'; 696 // carrossel.style.transform = 'translateX(o)'; 697 // carrossel.offsetHeight; // força repaint 698 // carrossel.style.transition = 'transform 0.8s ease'; 699 // ehAnimado = false; 700 // carrossel.removeEventListener('transitionend', handler); 701 // }); 702 703 // } 704 705 function proximoDestaque(carrossel, ehAnimado){ 706 const totalItems = carrossel.children.length; 707 const itensVisiveis = getItensVisiveis(); 708 if (totalItems <= itensVisiveis || ehAnimado) return; 709 ehAnimado = true; 710 711 const itemWidth = carrossel.firstElementChild.offsetWidth + getGap(); 712
713 // Clona o primeiro item e coloca no fim 714 const clone = carrossel.firstElementChild.cloneNode(true); 715 carrossel.appendChild(clone); 716 717 // Anima o carrossel para a esquerda 718 carrossel.style.transition = 'transform 0.8s ease'; 719 carrossel.style.transform = `translateX(-${itemWidth}px)`; 720 721 carrossel.addEventListener('transitionend', function handler(e) { 722 if (e.propertyName !== 'transform') return; 723 724 // Remove o primeiro item original 725 carrossel.removeChild(carrossel.firstElementChild); 726 727 // Desliga transição e reseta posição 728 carrossel.style.transition = 'none'; 729 carrossel.style.transform = 'translateX(0)'; 730 731 // Força repaint 732 void carrossel.offsetWidth; 733 734 // Reativa transição para os próximos 735 carrossel.style.transition = 'transform 0.8s ease'; 736 737 ehAnimado = false; 738 carrossel.removeEventListener('transitionend', handler); 739 }); 740 } 741 742 function getGap() { 743 return parseFloat(getComputedStyle(carrossel).gap) || 0; 744 } 745 746 function destaqueAnterior(carrossel, ehAnimado){ 747 const totalItems = carrossel.children.length; 748 const itensVisiveis = getItensVisiveis(); 749 750 if (totalItems <= itensVisiveis) return; 751 752 if (ehAnimado) return; 753 ehAnimado = true; 754 755 const itemWidth = carrossel.firstElementChild.offsetWidth + 10; 756 carrossel.insertBefore(carrossel.lastElementChild, carrossel.firstElementChild); 757 carrossel.style.transition = 'none'; 758 carrossel.style.transform = `translateX(-${itemWidth}px)`; 759 carrossel.offsetHeight; 760 carrossel.style.transition = 'transform 0.8s ease'; 761 carrossel.style.transform = 'translateX(0)'; 762 763 carrossel.addEventListener('transitionend', function handler() { 764 ehAnimado = false; 765 carrossel.removeEventListener('transitionend', handler); 766 }); 767 } 768 769 function getItensVisiveis() { 770 const width = window.innerWidth; 771 772 if (width < 578) return 1; 773 if (width < 992) return 2; 774 if (width < 1200) return 3; 775 return 5; 776 } 777 778 function resetIntervalo(intervalo, carrossel, ehAnimado) { 779 clearInterval(intervalo); 780 intervalo = setInterval(() => { proximoDestaque(carrossel, ehAnimado)} , 8000); 781 return intervalo 782 } 783 784 function atualizarLayout(carrossel, btnEsquerda, btnDireita, viewport) { 785 const itensVisiveis = getItensVisiveis(); 786 if (carrossel.children.length <= itensVisiveis) { 787 carrossel.style.justifyContent = 'center'; 788 btnEsquerda.style.display = 'none'; 789 btnDireita.style.display = 'none'; 790 viewport.style.cursor = 'default'; 791 } else { 792 carrossel.style.justifyContent = 'flex-start'; 793 btnEsquerda.style.display = ''; 794 btnDireita.style.display = ''; 795 viewport.style.cursor = 'grab'; 796 } 797 } 798 799 // Fim do tratamento dos destaques 800 801});
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.