1// Função para alternar o estado do collapse 2function toggleCollapse(collapseId) { 3 var collapse = document.getElementById(collapseId); 4 var currentState = collapse.getAttribute("data-state"); 5 var newState = currentState === "open" ? "closed" : "open"; 6 collapse.setAttribute("data-state", newState); 7} 8 9function toggleNewCollapse(button) { 10 var collapseContainer = button.closest(".collapse-container"); 11 if (!collapseContainer) return; 12 13 var currentState = collapseContainer.getAttribute("data-state"); 14 var newState = currentState === "open" ? "closed" : "open"; 15 collapseContainer.setAttribute("data-state", newState); 16} 17 18// Função para o funcionamento do collapse em "publicações" 19document.addEventListener("DOMContentLoaded", function () { 20 function toggleCollapse(collapseId) { 21 var collapse = document.getElementById(collapseId); 22 var currentState = collapse.getAttribute("data-state"); 23 var newState = currentState === "open" ? "closed" : "open"; 24 collapse.setAttribute("data-state", newState); 25 26 plusButton.classList.toggle("opened", newState === "open"); 27 plusButton.classList.toggle("closed", newState === "closed"); 28 } 29 30 var plusButton = document.querySelector('.plus-button'); 31 var targetDiv = document.querySelector('.filter-block'); 32 33 if (plusButton) { 34 plusButton.addEventListener('click', function () { 35 targetDiv.classList.toggle('opened'); 36 toggleCollapse('collapse-filter-button'); 37 }); 38 } 39}); 40 41// Função para alternar a exibição entre blocos e lista na sub de publicações 42function toggleView(viewType){ 43 console.log('toggleView'); 44 if (viewType === 'blocks') { 45 document.querySelector('.publications-content').classList.remove('active-list'); 46 mamSetCookie('publication-view', 'blocks', 30); 47 } else if (viewType === 'list') { 48 document.querySelector('.publications-content').classList.add('active-list'); 49 mamSetCookie('publication-view', 'list', 30); 50 } 51} 52 53document.querySelectorAll('.button-list-desktop, .button-list-mobile, .button-blocks-desktop, .button-blocks-mobile').forEach(function (button) { 54 button.addEventListener('click', function () { 55 var viewType = button.dataset.viewType; 56 toggleView(viewType); 57 }); 58}); 59 60 61/** 62 * Exposições passadas 63 * 64 */ 65document.addEventListener('DOMContentLoaded', function() { 66 const leftArrow = document.querySelector('.arrow.left'); 67 const rightArrow = document.querySelector('.arrow.right'); 68 const yearsContainer = document.querySelector('.years'); 69 const finalYear = new Date().getFullYear(); 70 71 // Função para navegar para o collapse correspondente ao ano clicado 72 function navigateToYearCollapse(year) { 73 const yearId = `year-${year}`; 74 const targetCollapse = document.getElementById(yearId); 75 if (targetCollapse) { 76 targetCollapse.scrollIntoView({ 77 behavior: 'smooth', 78 block: 'start' 79 }); 80 if( targetCollapse.querySelector('.collapse-content').classList.contains('closed') ){ 81 targetCollapse.querySelector('.collapse-button').click(); 82 } 83 } 84 } 85 86 /** 87 * @todo js modificar url após o scroll 88 * 89 */ 90 // Adicionar evento de clique para cada botão de ano 91 const yearButtons = document.querySelectorAll('.year-button'); 92 yearButtons.forEach(button => { 93 button.addEventListener('click', function( event ) { 94 event.preventDefault(); 95 const year = parseInt(button.dataset.year); 96 navigateToYearCollapse(year); 97 }); 98 }); 99 100 // Controle de rolagem 101 if( leftArrow ){ 102 leftArrow.addEventListener('click', function() { 103 yearsContainer.scrollLeft -= 238; 104 }); 105 } 106 if( rightArrow ){ 107 rightArrow.addEventListener('click', function() { 108 yearsContainer.scrollLeft += 238; 109 }); 110 } 111}); 112 113// Funcionamento dos collapses 114document.addEventListener('DOMContentLoaded', function() { 115 const collapseButtons = document.querySelectorAll('.collapse-header button'); 116 117 collapseButtons.forEach(button => { 118 button.addEventListener('click', function() { 119 const collapseContent = button.parentElement.nextElementSibling; 120 collapseContent.classList.toggle('closed'); 121 button.classList.toggle('closed'); 122 }); 123 });
124}); 125 126 127 128/** 129 * Submenu de exposições (em-cartaz, futuras, passadas) 130 * Função para funcionamento do collapse 131 * 132 */ 133const triggerButton = document.querySelector('.trigger-icon'); 134const mobileExhibitions = document.querySelector('.mobile-exhibitions-types'); 135// Incluindo e Removendo a classe 'open' no botão 136if( triggerButton ){ 137 triggerButton.addEventListener('click', function () { 138 this.classList.toggle('open'); 139 }); 140} 141// Incluindo e Removendo a classe 'show' na div mobile-exhibitions-types 142if( mobileExhibitions ){ 143 triggerButton.addEventListener('click', function () { 144 mobileExhibitions.classList.toggle('show'); 145 }); 146} 147 148 149 150jQuery(document).ready(function ($) { 151 152 /** 153 * Menu principal 154 * 155 */ 156 $('.menu-header-buttons .button--menu').on('click', function () { 157 const $menu = $('#site-header-menu'); 158 159 $menu.css('display', 'flex'); 160 $menu.attr('aria-hidden', 'false'); 161 162 $('body').addClass('menu-open'); 163 164 $(this).attr('aria-expanded', 'true'); 165 166 // foco vai para o menu 167 $menu.focus(); 168 }); 169 170 function closeMenu() { 171 const $menu = $('#site-header-menu'); 172 const $button = $('.menu-header-buttons .button--menu'); 173 174 $menu.hide(); 175 $menu.attr('aria-hidden', 'true'); 176 177 $('body').removeClass('menu-open mobile-search-open'); 178 179 $button.attr('aria-expanded', 'false'); 180 $button.focus(); 181 } 182 183 $('.site-header-menu .close-button').on('click', function () { 184 closeMenu(); 185 }); 186 187 // Fechamento do menu utilizando ESC 188 $(document).on('keydown', function (e) { 189 if (!$('body').hasClass('menu-open')) { 190 return; 191 } 192 193 if (e.key === 'Escape') { 194 e.preventDefault(); 195 closeMenu(); 196 } 197 }); 198 199 $('.skip-link[href="#site-header-menu"]').on('click', function (e) { 200 e.preventDefault(); 201 $('.menu-header-buttons .button--menu').trigger('click'); 202 }); 203 204 // -- 205 206 function getFocusableElements($container) { 207 return $container.find( 208 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])' 209 ).filter(':visible'); 210 } 211 212 $(document).on('keydown', function (e) { 213 if (!$('body').hasClass('menu-open')) { 214 return; 215 } 216 217 const $menu = $('#site-header-menu'); 218 219 if (e.key === 'Escape') { 220 e.preventDefault(); 221 closeMenu(); 222 return; 223 } 224 225 if (e.key !== 'Tab') { 226 return; 227 } 228 229 const $focusable = getFocusableElements($menu); 230 231 if (!$focusable.length) { 232 return; 233 } 234 235 const first = $focusable[0]; 236 const last = $focusable[$focusable.length - 1]; 237 const active = document.activeElement; 238 239 // Shift + Tab no primeiro â sai do menu 240 if (e.shiftKey && active === first) { 241 e.preventDefault(); 242 closeMenu(); 243 } 244 245 // Tab no último â sai do menu 246 if (!e.shiftKey && active === last) { 247 e.preventDefault(); 248 closeMenu(); 249 } 250 }); 251 252 // -- 253 254 $('#open-search-mobile').on('click', function(){ 255 $('body').toggleClass('mobile-search-open'); 256 $('[name="busca"]').focus(); 257 }); 258 259 $('#open-search').on('click', function(){ 260 $('.menu-header-buttons .button--menu').trigger('click'); 261 $('[name="busca"]').focus(); 262 }); 263 264 265 /** 266 * Carousel cursos 267 * 268 */ 269 const prevIcon = ` 270 <span class="prev-icon"> 271 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 63.797 50.547"> 272 <defs> 273 <style> 274 @media (max-width: 991.98px) { 275 .cls-1 { 276 fill: none; 277 stroke: currentColor; 278 stroke-width: 5px; 279 } 280 } 281 @media (min-width: 992px) { 282 .cls-1 { 283 fill: none; 284 stroke: currentColor; 285 stroke-width: 2px; 286 } 287 } 288 </style> 289 </defs> 290 <g id="Componente_18_102" data-name="Componente 18 â 102" transform="translate(63.797 49.828) rotate(180)">
291 <path id="Caminho_15" data-name="Caminho 15" class="cls-1" d="M-6362.266,8382.7l25.353,24.557-25.353,24.553" transform="translate(6399.272 -8382.701)"/> 292 <path id="Caminho_16" data-name="Caminho 16" class="cls-1" d="M-6432.2,8430.611h61.139" transform="translate(6432.197 -8406.055)"/> 293 </g> 294 </svg> 295 </span> 296 `; 297 298 const nextIcon = ` 299 <span class="next-icon"> 300 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 63.797 50.547"> 301 <defs> 302 <style> 303 @media (max-width: 991.98px) { 304 .cls-1 { 305 fill: none; 306 stroke: currentColor; 307 stroke-width: 5px; 308 } 309 } 310 @media (min-width: 992px) { 311 .cls-1 { 312 fill: none; 313 stroke: currentColor; 314 stroke-width: 2px; 315 } 316 } 317 </style> 318 </defs> 319 <g id="Componente_18_101" data-name="Componente 18 â 101" transform="translate(0 0.719)"> 320 <path id="Caminho_15" data-name="Caminho 15" class="cls-1" d="M-6362.266,8382.7l25.353,24.557-25.353,24.553" transform="translate(6399.272 -8382.701)"/> 321 <path id="Caminho_16" data-name="Caminho 16" class="cls-1" d="M-6432.2,8430.611h61.139" transform="translate(6432.197 -8406.055)"/> 322 </g> 323 </svg> 324 </span> 325 `; 326 327 var owlcourses = $('.owl-carousel-courses'); 328 owlcourses.owlCarousel({ 329 loop: true, 330 autoplay: true, 331 autoplayHoverPause: true, 332 nav: false, 333 dots: false, 334 navText: [ 335 prevIcon, 336 nextIcon 337 ], 338 responsive: { 339 0: { // Dispositivos com largura menor que 992 pixels 340 items: 1, 341 margin: 16, 342 autoplayTimeout: 15000, 343 touchDrag: false, 344 mouseDrag: false 345 }, 346 992: { // Dispositivos com largura igual ou maior que 992 pixels 347 items: 3, 348 margin: 32, 349 autoplayTimeout: 10000, 350 touchDrag: true, 351 mouseDrag: true 352 } 353 }, 354 }); 355 356 357 /** 358 * Carousel acervo 359 * 360 */ 361 var owlcollection = $('.owl-carousel-collection'); 362 owlcollection.owlCarousel({ 363 center: false, 364 loop:true, 365 nav:false, 366 dots:false, 367 autoplay: true, 368 slideTransition: 'linear', 369 autoplayTimeout: 6000, 370 autoplaySpeed: 6000, 371 autoplayHoverPause: true, 372 responsive: { 373 0: { // Dispositivos com largura menor que 576 pixels 374 items: 2, 375 margin: 16, 376 }, 377 576: { // Dispositivos com largura igual ou maior que 576 pixels e menor que 768 pixels 378 items: 3, 379 margin: 20, 380 }, 381 768: { // Dispositivos com largura igual ou maior que 768 pixels e menor que 992 pixels 382 items: 4, 383 margin: 24, 384 }, 385 992: { // Dispositivos com largura igual ou maior que 992 pixels 386 items: 6, 387 margin: 32, 388 } 389 } 390 }); 391 392 393 394 /** 395 * Forçar a abertura do modal nativo de calendário ao clicar no campo de data 396 * 397 */ 398 $('input[type="date"]').on('focus, click', function(){ 399 this.showPicker(); 400 }); 401 402 403 /** 404 * Controle de collapse para block-group 405 * 406 * 407 */ 408 $('.collapse-control button').on('click', function (e) { 409 /** 410 console.log('collapse'); 411 var btn = $(this); 412 // como a ação de click é acionada 6x, aplicar a class 'active' para
412indicar o running da ação, 413 // e remover após o fim do slide up/down 414 if (!btn.hasClass('active')) { 415 btn.addClass('active'); 416 var inner = btn.closest('.wp-block-group, .page-collapse-parent').find('.wp-block-group-inner, .page-collapse-content'); 417 418 if (!inner.is(':visible')) { 419 inner.slideDown(600, function () { 420 btn.removeClass('active'); 421 }); 422 btn.removeClass('closed'); 423 } 424 else { 425 inner.slideUp(600, function () { 426 btn.removeClass('active'); 427 }); 428 btn.addClass('closed'); 429 } 430 } 431 /**/ 432 433 var btn = $(this); 434 var inner = btn.closest('.wp-block-group, .page-collapse-parent').find('.wp-block-group-inner, .page-collapse-content'); 435 inner.first().slideToggle({ 436 duration: 400, 437 start: function(){ 438 //$(this).css('display','grid'); 439 }, 440 done: function(){ 441 if( $(this).is(':visible') ){ 442 btn.removeClass('closed'); 443 } 444 else{ 445 btn.addClass('closed'); 446 } 447 } 448 } 449 ); 450 }); 451 452 453 454 /** 455 * Controle de collapse para page-header, bloco com (i) 456 * 457 */ 458 $('.mam-block-page-header .info-control').on('click', function(e){ 459 var btn = $(this); 460 var block = btn.closest('.mam-block-page-header'); 461 if( !block.hasClass('open') ){ 462 block.addClass('open'); 463 block.removeClass('sub-open'); 464 } 465 }); 466 467 $('.mam-block-page-header .close-control').on('click', function(e){ 468 var btn = $(this); 469 var block = btn.closest('.mam-block-page-header'); 470 471 // fechar bloco de informações 472 if( block.hasClass('open') ){ 473 block.removeClass('open'); 474 } 475 // abrir submenu 476 else if( !block.hasClass('sub-open') ){ 477 block.addClass('sub-open'); 478 } 479 // fechar sub menu 480 else if( block.hasClass('sub-open') ){ 481 block.removeClass('sub-open'); 482 } 483 484 // fechar lightbox 485 var lightbox = $('.lightbox'); 486 if( lightbox.length && lightbox.hasClass('lightbox-active') ){ 487 lightbox.removeClass('lightbox-active'); 488 $('.owl-carousel-lightbox').trigger('destroy.owl.carousel'); 489 } 490 }); 491 492 493 494 /** 495 * Scroll para o ano em exposições passadas onload 496 * 497 */ 498 if( $('.collapse-years').length ){ 499 var current_year = new Date().getFullYear(); 500 var page_year = $('.collapse-years').attr('data-current-year'); 501 if( current_year != page_year ){ 502 document.getElementById(`year-${page_year}`).scrollIntoView({behavior: "smooth"}); 503 } 504 } 505 506 507 508 /** 509 * Audio player individual de exposição 510 * Modo de edição template, apenas exposições antigas antes do gutenberg 511 * 512 */ 513 var box_player = $('body.expo-content-mode-template #audio-player-expo'); 514 if( box_player.length > 0 ){ 515 var player = box_player.find('audio')[0]; 516 var current_player_item = false; 517 $('.audio-item .play-button').on('click', function(){ 518 current_player_item = $(this).closest('.audio-item'); 519 var audiosrc = $(this).attr('data-audiosrc'); 520 521 box_player.addClass('playing').show(); 522 $('.audio-item.playing').removeClass('playing'); 523 current_player_item.addClass('playing'); 524 // trocar src apenas se for diferente, permitindo que continue o mesmo audio de onde parou 525 if( player.src != audiosrc ){ 526 player.src = audiosrc; 527 player.load(); 528 } 529 else{ 530 player.play(); 531 } 532 }); 533 534 // acionar o play assim que o novo src for carregado 535 player.addEventListener('loadeddata', function(){ 536 player.play(); 537 }); 538 539 // sinalizar pause nos botões do player e do item na lista 540 player.addEventListener('pause', function(){ 541 box_player.removeClass('playing'); 542 $('.audio-item.playing').removeClass('playing'); 543 }); 544 545 // sinalizar play nos botões do player e do item na lista 546 player.addEventListener('play', function(){ 547 box_player.addClass('playing'); 548 current_player_item.addClass('playing'); 549 }); 550 551 // pause na lista de audios 552 $('.audio-item .pause-button').on('click', function(){ 553 player.pause(); 554 box_player.removeClass('playing'); 555 $('.audio-item.playing').removeClass('playing'); 556 }); 557 558 // fechar player 559 $('#audio-player-expo button').on('click', function(){ 560 player.pause(); 561 box_player.removeClass('playing').hide(); 562 $('.audio-item.playing').removeClass('playing'); 563 }); 564 } 565 566 /** 567 * Player de aúdio para os blocos 568 * 569 */ 570 var boxPlayer = $('#audio-player-expo'); 571 if( boxPlayer.length ){ 572 var player = boxPlayer.find('audio')[0]; 573 var currentPlayerItem = null; 574 575 function resetButtons() { 576 $('.audio-player .pause-btn').css('display', 'none'); 577 $('.audio-player .play-btn').css('display', 'inline'); 578 } 579 580 $('.audio-player .play-btn').click(function () { 581 var audio = $(this).siblings('audio')[0]; 582 var src = audio.src; 583 584 resetButtons(); 585 currentPlayerItem = $(this).closest('.grid-item'); 586 currentPlayerItem.addClass('playing'); 587 boxPlayer.addClass('playing').css('display', 'block'); 588 589 if (player.src != src) { 590 player.src = src; 591 player.load(); 592 } else { 593 player.play(); 594 } 595 596 $(this).css('display', 'none'); 597 $(this).siblings('.pause-btn').css('display', 'inline'); 598 }); 599 600 $('.audio-player .pause-btn').click(function () { 601 player.pause(); 602 resetButtons(); 603 }); 604 605 $('#audio-player-expo .play-button').click(function () { 606 player.play(); 607 if (currentPlayerItem) { 608 currentPlayerItem.find('.play-btn').css('display', 'none'); 609 currentPlayerItem.find('.pause-btn').css('display', 'inline'); 610 } 611 }); 612 613 $('#audio-player-expo .pause-button, #audio-player-expo button').click(function () { 614 player.pause(); 615 boxPlayer.removeClass('playing').css('display', 'none'); 616 resetButtons(); 617 }); 618 619 player.addEventListener('loadeddata', function () { 620 player.play(); 621 }); 622 623 player.addEventListener('pause', function () { 624 boxPlayer.removeClass('playing'); 625 $('.grid-item.playing').removeClass('playing'); 626 resetButtons(); 627 }); 628 629 player.addEventListener('play', function () { 630 if (currentPlayerItem) { 631 currentPlayerItem.addClass('playing'); 632 currentPlayerItem.find('.play-btn').css('display', 'none'); 633 currentPlayerItem.find('.pause-btn').css('display', 'inline'); 634 } 635 }); 636 } 637 638 /** 639 * Carregar anos de exposição 640 * Buscar conteúdo do ano requisitado e salvar localStorage ou recuperar cache salvo 641 * 642 */ 643 // $('.collapse-years .collapse-header button').on('click', function(){ 644 // if( !$(this).hasClass('closed') ){ 645 // var button = $(this); 646 // var year = button.attr('data-year'); 647 // var parent = button.closest('.collapse-year'); 648 // var content = parent.find('.collapse-content .row'); 649 // var cache_key = `expos_${year}`; 650 // var cached_content = timedLocalStorage.getItem( cache_key ); 651 // //console.log( cache_key ); 652 // //console.log( cached_content ); 653 // //console.log( content.html() ); 654 // //console.log( content[0].childNodes.length ); 655 // //console.log( parent.find('.loading').length ); 656 657 // if( parent.find('.loading').length == 0 ){ 658 // return; 659 // } 660 661 // button.prop('disabled', true); 662 // if( cached_content === null ){ 663 // mam_expos_request_year( parent, year, cache_key ); 664 // } 665 // else{ 666 // if( cached_content != '' ){ 667 // console.log(`cache encontrado para ${year}`); 668 // content.html( cached_content ); 669 // button.prop('disabled', false); 670 // } 671 // else{ 672 // console.log(`cache vazio para ${year}`); 673 // } 674 // } 675 // } 676 // }); 677 678 function mam_expos_request_year( parent, year, cache_key ){ 679 console.log(`nova requisição para ${year}`); 680 681 var button = parent.find('.collapse-header button'); 682 button.prop('disabled', true); 683 684 var data = { 685 action: 'mam_expos_year', 686 year: year 687 }; 688 689 $.ajax({
690 type: "GET", 691 url: ajaxurl, 692 data: data, 693 success: function( response ){ 694 if( response != '' ){ 695 console.log(`novo conteúdo para ${year}`); 696 timedLocalStorage.setItem(cache_key, response, 10*60*1000); 697 parent.find('.collapse-content .row').html( response ); 698 button.prop('disabled', false); 699 } 700 } 701 }); 702 } 703 704 // salvar em localstorage o conteúdo ano da requisição inicial, que não será ajax 705 if( $('.collapse-years').length ){ 706 var current_year = $('.collapse-years').attr('data-current-year'); 707 708 console.log(current_year); 709 var parent = $(`#year-${current_year}`); 710 var content = parent.find('.collapse-content .row'); 711 var cache_key = `expos_${current_year}`; 712 var cached_content = timedLocalStorage.getItem( cache_key ); 713 714 console.log(parent); 715 716 if( parent.find('.loading').length != 0 ){ 717 console.log('have loading'); 718 return; 719 } 720 721 if( cached_content === null ){ 722 console.log(`salvar cache para o ano ${current_year}`); 723 timedLocalStorage.setItem(cache_key, content.html(), 10*60*1000); 724 } 725 } 726 727 728 729 /** 730 * Filtro de agenda 731 * Acionar submit quando modificar algum dos controles 732 * 733 */ 734 $('form.schedule-submenu').on('change', function(){ 735 $(this).addClass('disabled').submit(); 736 }) 737 738 /** 739 * Desabilitar o campo que não foi acionado, para que não interfira na querystring 740 * 741 */ 742 $('#control-months').on('change', function(){ 743 $('#control-day').val('').prop('disabled', true); 744 }); 745 746 $('#control-day').on('change', function(){ 747 $('#control-months').val('').prop('disabled', true); 748 }); 749 750 751 752 /** 753 * Listagem Agenda 754 * Salvar em localstorage a navegação de data 755 * 756 */ 757 $('form.schedule-submenu').on('submit', function(event){ 758 event.preventDefault(); 759 var form = $(this); 760 var formData = new FormData( form[0] ); 761 //console.log( ...formData ); 762 763 var cache_key = ''; 764 var schedule_type = ''; 765 var schedule_value = ''; 766 //$('#schedule-contents') 767 for( [key, value] of formData ){ 768 console.log( `agenda: schedule_${key}_${value}` ); 769 cache_key = `schedule4_${key}_${value}`; 770 schedule_type = key; 771 schedule_value = value; 772 } 773 774 // if( schedule_type == 'mes' ){ 775 // event.currentTarget.submit(); 776 // return; 777 // } 778 779 $('.date-controls').addClass('disabled'); 780 $('#schedule-contents').css('opacity', 0.5); 781 782 if( cache_key != '' ){ 783 var cached_content = timedLocalStorage.getItem( cache_key ); 784 console.log(`agenda: buscar cache para ${cache_key}`); 785 //console.log(cached_content); 786 787 if( cached_content === null ){ 788 console.log(`agenda: cache NÃO encontrado para ${cache_key}`); 789 var url = form.attr('action') + "?" + form.serialize(); 790 console.log(url); 791 $.get( url, function( response ){ 792 var content = $(response).find('#schedule-contents'); 793 var header = $(response).find('.date-controls').first(); 794 //console.log(content); 795 //console.log(header); 796 //console.log(response); 797 if( content != '' ){ 798 console.log('agenda: salvar novo cache'); 799 //console.log(content); 800 timedLocalStorage.setItem(cache_key, [header.html(), content.html()], 10*60*1000); 801 $('#schedule-contents').html( content.html() ); 802 $('.date-controls').html( header.html() ); 803 804 form.removeClass('disabled'); 805 $('#control-day').prop('disabled', false); 806 $('#control-months').prop('disabled', false); 807 $('#schedule-contents').css('opacity', 1); 808 } 809 else{ 810 form.submit(); 811 } 812
813 $('.date-controls').removeClass('disabled'); 814 }); 815 } 816 else{ 817 if( cached_content != '' ){ 818 console.log(`agenda: cache encontrado para ${cache_key}`); 819 //console.log(cached_content[0]); 820 //console.log(cached_content[1]); 821 $('#schedule-contents').html( cached_content[1] ); 822 $('.date-controls').html( cached_content[0] ); 823 824 form.removeClass('disabled'); 825 $('#control-day').prop('disabled', false); 826 $('#control-months').prop('disabled', false); 827 $('#schedule-contents').css('opacity', 1); 828 } 829 else{ 830 console.log(`agenda: cache encontrado, porém vazio para ${cache_key}`); 831 } 832 833 $('.date-controls').removeClass('disabled'); 834 } 835 836 // fechar caixa de filtros em mobile, caso já esteja aberta 837 if( $('.controls-area-mobile').is(':visible') && $('.has-sub-menu').is('.sub-open') ){ 838 $('.mam-block-page-header-title .close-control').trigger('click'); 839 } 840 841 // atualizar url no navegador com os novos parâmetros 842 const newUrl = new URL(window.location); 843 newUrl.searchParams.delete('mes'); 844 newUrl.searchParams.delete('data'); 845 newUrl.searchParams.set(schedule_type, schedule_value); 846 window.history.replaceState(null, "", newUrl); 847 848 } 849 else{ 850 form.submit(); 851 } 852 }); 853 854 /** 855 * Listagem Agenda: controles de dias anterior/próximo 856 * 857 */ 858 $('.item-name-agenda .date-controls').on('click', '.schedule-control', function( event ){ 859 event.preventDefault(); 860 $('form.schedule-submenu').addClass('disabled'); 861 $('#control-months').val(''); // resetar informação de mês, para não interferir na requisição de dia 862 $('#control-day').val( $(this).attr('data-date') ); 863 $('form.schedule-submenu').trigger('submit'); 864 }); 865 866 /** 867 * Listagem agenda: salvar o cache da primeira requisição da página 868 * Separar listagem de dia e mês 869 * 870 */ 871 if( $('.item-name-agenda .date-controls .current-date').length ){ 872 var date_el = $('.date-controls .current-date'); 873 var date = date_el.attr('data-date'); 874 if( date_el.attr('data-date-type') == 'month' ){ 875 date = date.slice(0, -3); 876 } 877 var cache_key = `schedule4_data_${date}`; 878 var cached_content = timedLocalStorage.getItem( cache_key ); 879 880 if( cached_content === null ){ 881 console.log(`salvar cache inicial para ${date}`); 882 var content = $('#schedule-contents'); 883 var header = $('.date-controls').first(); 884 timedLocalStorage.setItem(cache_key, [header.html(), content.html()], 10*60*1000); 885 } 886 else{ 887 console.log(`já possui cache para ${date}`); 888 } 889 } 890 891 function mam_schedule_request( cache_key ){ 892 console.log(`nova requisição para ${cache_key}`); 893 894 var data = { 895 action: 'mam_schedule_request', 896 type: schedule_type, 897 value: schedule_value, 898 }; 899 900 $.ajax({
901 type: "GET", 902 url: ajaxurl, 903 data: data, 904 success: function( response ){ 905 if( response != '' ){ 906 return response; 907 } 908 else{ 909 return false; 910 } 911 }, 912 error: function( response ){ 913 return false; 914 } 915 }); 916 } 917 918 919 920 /** 921 * Publicações: Live Filter 922 * 923 * pub_filters armazena os valores dos campos para serem usados no update da querystring; O timeout é utilizado 924 * para que o update da url aconteça apenas em intervalos 925 * 926 */ 927 var pub_filters = { 928 'pubtexto': '', 929 'pubano': '', 930 'pubcategoria': '', 931 }; 932 var pub_filters_updating = false; 933 934 if( $('#publication-keyword').length ){ 935 $('#publication-keyword').fastLiveFilter('.block-view, .publication-list, .wp-block-mam-panorama', { 936 selector: '.title, .schedule-date, .pub-type, .card-date, .card-title, .people', 937 ignore: 'empty', 938 matchAll: true, 939 notFound: '.pub-not-found', 940 callback: function(total){
941 if( 'URLSearchParams' in window && pub_filters_updating == false ){ 942 pub_filters_updating = true; 943 setTimeout(function(){ 944 pub_filters['pubtexto'] = $('#publication-keyword').val() 945 .replace(pub_filters['pubano'], '') 946 .replace(pub_filters['pubcategoria'], '') 947 .replace(/ +(?= )/g, '') 948 .trim(); 949 950 // atualizar querystring da url, adicionando ou removendo itens 951 const url = new URL(window.location); 952 Object.entries(pub_filters).forEach(entry => { 953 const [key, value] = entry; 954 if( value == '' ){ 955 url.searchParams.delete(key); 956 } 957 else{ 958 url.searchParams.set(key, value); 959 } 960 }); 961 history.replaceState(null, '', url); 962 963 //console.log(pub_filters); 964 pub_filters_updating = false; 965 }, 3000); 966 } 967 } 968 }); 969 } 970 971 $('.year-area select, .type-area select').on('change', function(){ 972 var select = $(this); 973 var select_new = select.val(); 974 var select_curr = select.attr('data-value'); 975 var search_input = $('#publication-keyword'); 976 var search_val = search_input.val(); 977 978 //console.log(`current: ${select_curr}`); 979 //console.log(`new: ${select_new}`); 980 981 if( select_curr != select_new ){ 982 var clear_val = search_val.replace(select_curr, ''); 983 //console.log(`remove current: ${clear_val}`); 984 985 var new_val = clear_val + ' ' + select_new; 986 new_val = new_val.replace(/ +(?= )/g, '').trim(); 987 search_input.val( new_val ); 988 //console.log(`add new: ${new_val}`); 989 990 // atualizar valores para querystring 991 pub_filters[ select.attr('data-qs') ] = select_new; 992 } 993 select.attr('data-value', select_new); 994 search_input.trigger('input'); 995 }); 996 997 if( $('#publication-keyword').length ){ 998 $('.year-area select, .type-area select').trigger('change'); 999 } 1000 1001 1002 1003 /** 1004 * Lightbox 1005 * 1006 */ 1007 $('a.lightbox-link').on('click', function( event ){ 1008 event.preventDefault(); 1009 1010 var button = $(this); 1011 var lightbox = $('.lightbox'); 1012 lightbox.addClass('lightbox-active'); 1013 lightbox.find('.mam-block-page-header').addClass('open'); 1014 1015 // copiar elementos presente no bloco de imagens 1016 var carousel_items = $(this).closest('.collapse-content').find('.lightbox-items').html(); 1017 $('.owl-carousel-lightbox').html( carousel_items ); 1018 1019 var carousel_title = $(this).closest('.collapse-container').find('.title-collapse').text(); 1020 lightbox.find('.mam-block-page-header-title .title span').text( carousel_title ); 1021 1022 // reiniciar o carousel com os novos itens 1023 $('.owl-carousel-lightbox').owlCarousel({ 1024 items: 1, 1025 startPosition: button.attr('data-index') 1026 }); 1027 }); 1028 1029 $('.carousel-nav .prev').on('click', function(){ 1030 $('.owl-carousel-lightbox').trigger('prev.owl.carousel'); 1031 }); 1032 $('.carousel-nav .next').on('click', function(){ 1033 $('.owl-carousel-lightbox').trigger('next.owl.carousel'); 1034 }); 1035 1036 1037 1038 /** 1039 * Form de contato: contador de caracteres 1040 * 1041 */ 1042 $('[data-action="character-count"]').each(function(){ 1043 var input = $(this); 1044 var counter = input.closest('.form-group').find('.character-counter'); 1045 1046 input.on('keyup', function(){ 1047 var max = input.prop('maxLength'); 1048 var rem = input.val().length; 1049 counter.text( `${rem}/${max}` ); 1050 }); 1051 });
1052 1053 /** 1054 * Remover querystrings de páginas de confirmação de formulários 1055 * 1056 */ 1057 const current_url = new URL(window.location); 1058 const confirmation_message = current_url.searchParams.get('msg'); 1059 if( confirmation_message !== null ){ 1060 current_url.searchParams.delete( 'msg' ); 1061 current_url.searchParams.delete( 'fm' ); 1062 history.replaceState(null, '', current_url); 1063 } 1064 1065 /** 1066 * Tabs nos forms de IR 1067 * 1068 */ 1069 $('#formularios-ir .tab').on('click', function(){ 1070 var btn = $(this); 1071 var target = btn.attr('data-target'); 1072 var parent = $(this).closest('#formularios-ir'); 1073 var tabs = parent.find('.tab'); 1074 var forms = parent.find('.form-content'); 1075 1076 tabs.removeClass('active'); 1077 btn.addClass('active'); 1078 forms.removeClass('active'); 1079 $(target).addClass('active'); 1080 }); 1081 1082 /** 1083 * Enviar form IR 1084 * A requisição é enviada para o mesmo action padrão do form, sendo recuperado apenas o elemento do form com a resposta 1085 * 1086 */ 1087 $('#formularios-ir form').on('submit', function(event){ 1088 event.preventDefault(); 1089 1090 var form = $(this); 1091 var requestData = form.serialize(); 1092 var form_id = form.attr('id'); 1093 1094 $.ajax({
1095 type: 'post', 1096 url: $(this).attr('action'), 1097 async: true, 1098 data: requestData, 1099 cache: false, 1100 processData: false, 1101 success: function( response ){ 1102 //console.log( 'success' ); 1103 form.html( $(response).find(`#${form_id}`).html() ); 1104 form.removeClass('submitting'); 1105 }, 1106 error: function( response ){ 1107 form.removeClass('submitting'); 1108 }, 1109 beforeSend: function( response ){ 1110 //console.log( requestData ); 1111 form.addClass('submitting'); 1112 form.find('input:submit').val('enviando...'); 1113 } 1114 }); 1115 }); 1116 1117 /** 1118 * Formulários newsletter 1119 * 1120 */ 1121 $('.mam-form-newsletter').on('submit', function(event){ 1122 event.preventDefault(); 1123 1124 var form = $(this); 1125 var requestData = form.serialize(); 1126 1127 $.ajax({ 1128 type: 'post', 1129 url: $(this).attr('action'), 1130 async: true, 1131 data: requestData, 1132 cache: false, 1133 processData: false, 1134 success: function( response ){ 1135 console.log( response ); 1136 if( response.success == true ){ 1137 form.find('.input-email').val(''); 1138 } 1139 form.find('.response').html( response.data ); 1140 form.removeClass('submitting'); 1141 }, 1142 error: function( response ){ 1143 form.removeClass('submitting'); 1144 }, 1145 beforeSend: function( response ){ 1146 form.find('.response').html(''); 1147 form.addClass('submitting'); 1148 } 1149 }); 1150 }); 1151 1152 /** 1153 * Formulário de busca 1154 * 1155 */ 1156 $('.mam-form-search').on('submit', function(event){ 1157 event.preventDefault(); 1158 1159 var form = $(this); 1160 var requestData = form.serialize(); 1161 1162 if( form.find('[name="busca"]').val() == '' ){ 1163 return false; 1164 } 1165 1166 $.ajax({
1167 type: 'get', 1168 url: $(this).attr('action'), 1169 async: true, 1170 data: requestData, 1171 cache: false, 1172 processData: false, 1173 success: function( response ){ 1174 form.next('.search-results').html( response.data ); 1175 form.removeClass('submitting'); 1176 }, 1177 error: function( response ){ 1178 form.removeClass('submitting'); 1179 }, 1180 beforeSend: function( response ){ 1181 form.next('.search-results').html( '<div class="section-title">buscando...</div>' ); 1182 form.addClass('submitting'); 1183 } 1184 }); 1185 }); 1186 1187 1188 1189 /** 1190 * Popup de avisos 1191 * Caso o modal esteja sinalizado como one-time, será salvo cookie para que ele não apareça novamente pelas próximas 24h 1192 * 1193 */ 1194 $('.mam-modal-backdrop, .mam-modal .close').on('click', function(event){ 1195 var parent = $(this).closest('.mam-modal'); 1196 $('.mam-modal-backdrop, .mam-modal').hide(0, function(){ 1197 if( parent.is('.one-time') ){ 1198 var modal_name = parent.attr('data-modal-name'); 1199 mamSetCookie(modal_name, true, 1); 1200 } 1201 }); 1202 }); 1203 1204 1205 /** 1206 * Caixa de cookies/privacidade 1207 * 1208 */ 1209 $('.footer-message button').on('click', function(){ 1210 mamSetCookie('cookieConsent', true, 30); 1211 $('.footer-message').css('display', 'none').remove(); 1212 }); 1213 1214 function setckieboxHeight(){ 1215 let ckiebox = $('.footer-message'); 1216 if( ckiebox.length ){ 1217 document.documentElement.style.setProperty('--ckiebox-height', ckiebox[0].offsetHeight + 'px'); 1218 } 1219 } 1220 1221 window.addEventListener('resize', function(event) { 1222 setckieboxHeight(); 1223 }, true); 1224 1225 setckieboxHeight(); 1226 1227 1228 1229 /** 1230 * Texto animado, substituir "mam" por texto colorido 1231 * Necessário a tranformação de texto via javascript para não interferir no scaneamento de texto do gtranslate, 1232 * que necessita que os textos estejam completos dentro das tags. 1233 * 1234 */ 1235 $('.scrolling-text-content').each(function(){ 1236 $(this).html( $(this).text().replace(' mam ', ' m<span class="red-a">a</span>m ') ); 1237 }); 1238 1239 1240 $('.gtranslate_wrapper .gt-current-lang').on('click', function( event ){ 1241 event.preventDefault(); 1242 var parent = $(this).closest('.gtranslate_wrapper '); 1243 parent.toggleClass('open'); 1244 }); 1245 1246 1247}); 1248 1249 1250 1251/** 1252 * ================================================== 1253 * PLUGINS ========================================== 1254 * ================================================== 1255 * 1256 * 1257 */ 1258 1259/** 1260 * Ler e setar cookies 1261 * 1262 * @link https://stackoverflow.com/a/5882352/679195 1263 * 1264 */ 1265function mamSetCookie( name, value, days ){ 1266 var expires = ""; 1267 if( days ){ 1268 var date = new Date(); 1269 date.setTime(date.getTime() + (days*24*60*60*1000)); 1270 expires = "; expires=" + date.toUTCString(); 1271 } 1272 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 1273} 1274 1275function mamGetCookie( n ){ 1276 return(n=new RegExp('(?:^|;\\s*)'+(''+n).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,'\\$&')+'=([^;]*)').exec(document.cookie))&&n[1]; 1277} 1278 1279/** 1280 * fastLiveFilter jQuery plugin 1.0.3 1281 * @link https://github.com/awbush/jquery-fastLiveFilter 1282 * 1283 * Copyright (c) 2011, Anthony Bush 1284 * License: <http://www.opensource.org/licenses/bsd-license.php> 1285 * Project Website: http://anthonybush.com/projects/jquery_fast_live_filter/ 1286 **/ 1287jQuery.fn.fastLiveFilter = function(list, options) { 1288 // Options: input, list, timeout, callback, ignore, matchAll 1289 options = options || {}; 1290 list = jQuery(list); 1291 var input = this; 1292 var lastFilter = ''; 1293 var timeout = options.timeout || 0; 1294 var callback = options.callback || function() {}; 1295 var ignore = options.ignore || false; 1296 var matchAll = options.matchAll || false; 1297 var notFound = options.notFound || false; 1298 var totalElem = options.totalElem || false; 1299 1300 var keyTimeout; 1301 1302 // NOTE: because we cache lis & len here, users would need to re-init the plugin 1303 // if they modify the list in the DOM later. This doesn't give us that much speed 1304 // boost, so perhaps it's not worth putting it here. 1305 var lis = list.children();
1306 var len = lis.length; 1307 var oldDisplay = len > 0 ? lis[0].style.display : "block"; 1308 1309 callback(len); // do a one-time callback on initialization to make sure everything's in sync 1310 1311 input.on('input', function() { 1312 // var startTime = new Date().getTime(); 1313 var filter = input.val().normalize('NFD').replace(/[\u0300-\u036f]/g, "").toLowerCase(); 1314 var srchTerms = jQuery.trim(filter).split(/\s+/); 1315 var numShown = 0; 1316 var li, innerText; 1317 1318 for (var i = 0; i < len; i++) { 1319 li = lis[i]; 1320 1321 if( filter == '' ){ 1322 li.style.display = oldDisplay; 1323 } 1324 else{ 1325 var match = -1; 1326 1327 // ignore element 1328 if( ignore != false && li.classList.contains(ignore) ){ 1329 return false; 1330 } 1331 1332 // element text 1333 innerText = !options.selector ? (li.textContent || li.innerText || "") : jQuery(li).find(options.selector).text(); 1334 1335 // normalize texts 1336 innerText = innerText.normalize('NFD').replace(/[\u0300-\u036f]/g, "").toLowerCase(); 1337 1338 //support multiple search terms 1339 if( matchAll == true){ 1340 var c = 0; 1341 for (var k in srchTerms) { 1342 if (innerText.indexOf(srchTerms[k]) >= 0) { 1343 c++; 1344 } 1345 }; 1346 if( c == srchTerms.length ){ 1347 match = c; 1348 } 1349 } 1350 else{ 1351 match = innerText.indexOf(filter); 1352 } 1353 1354 /** 1355 * Search in accented characters 1356 * @link https://stackoverflow.com/a/51874002/679195 1357 */ 1358 if (match >= 0) { 1359 if (li.style.display == "none") { 1360 li.style.display = oldDisplay; 1361 } 1362 numShown++; 1363 } else { 1364 if (li.style.display != "none") { 1365 li.style.display = "none"; 1366 } 1367 } 1368 } 1369 1370 // if no match is found i.e. when var numShown count is 0, display the notFound element 1371 if( notFound ){ 1372 var notfoundelem = jQuery(notFound); 1373 if( numShown <= 0 && srchTerms != '' ){ 1374 notfoundelem.show(); 1375 } 1376 else{ 1377 notfoundelem.hide(); 1378 } 1379 } 1380 1381 if( srchTerms != '' ){ 1382 jQuery(totalElem).text( numShown ); 1383 } 1384 else{ 1385 jQuery(totalElem).text(''); 1386 } 1387 } 1388 1389 callback(numShown); 1390 // var endTime = new Date().getTime(); 1391 // console.log('Search for ' + filter + ' took: ' + (endTime - startTime) + ' (' + numShown + ' results)'); 1392 return false; 1393 }).keydown(function() { 1394 // TODO: one point of improvement could be in here: currently the change event is 1395 // invoked even if a change does not occur (e.g. by pressing a modifier key or 1396 // something) 1397 clearTimeout(keyTimeout); 1398 keyTimeout = setTimeout(function() { 1399 if( input.val() === lastFilter ) return; 1400 lastFilter = input.val(); 1401 input.change(); 1402 }, timeout); 1403 }); 1404 return this; // maintain jQuery chainability 1405} 1406 1407// JS para o funcionamento do sub-menu do header 1408document.addEventListener('DOMContentLoaded', () => { 1409 const menuItems = document.querySelectorAll('.menu-item-has-children > a'); 1410 1411 const closeSubmenus = submenu => 1412 submenu?.querySelectorAll('.menu-item-has-children.active').forEach(child => { 1413 child.classList.remove('active'); 1414 closeSubmenus(child.querySelector('ul')); 1415 }); 1416
1417 menuItems.forEach(item => item.addEventListener('click', e => { 1418 e.preventDefault(); 1419 const parent = item.parentElement; 1420 const submenu = parent.querySelector('ul'); 1421 1422 parent.classList.toggle('active'); 1423 if (!parent.classList.contains('active')) closeSubmenus(submenu); 1424 1425 Array.from(parent.parentElement.children) 1426 .filter(listItem => listItem !== parent && listItem.classList.contains('menu-item-has-children')) 1427 .forEach(listItem => { 1428 listItem.classList.remove('active'); 1429 closeSubmenus(listItem.querySelector('ul')); 1430 }); 1431 })); 1432}); 1433
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.