1/* 2 * Details accordion layout 3 */ 4document.querySelectorAll( '.wpb5-sidebar-width details' ).forEach( ( el ) => { 5 new Accordion( { 6 el: el, 7 duration: 250 8 } ); 9} ); 10document.querySelectorAll( '#primary-menu details' ).forEach( ( el ) => { 11 new Accordion( { 12 el: el, 13 duration: 250, 14 trigger: 'hover' 15 } ); 16} ); 17 18window.addEventListener( 'load', () => { 19 'use strict'; 20 21 /* Init functions */ 22 revealPosts(); 23 24 //#pojo-a11y-toolbar pojo-a11y-toolbar-link pojo-a11y-btn-resize-font pojo-a11y-btn-resize-plus 25 const access = document.getElementById( 'accessibility' ); 26 access.querySelectorAll( '[data-bs-zoom]' ).forEach( el => { 27 el.addEventListener( 'click', e => { 28 let currentZoom = parseFloat( document.body.style.zoom ) || 1; 29 var zoom = 0.9; 30 if ( el.getAttribute( 'data-bs-zoom' ) === 'plus' ) { 31 zoom = 1.1; 32 } 33 document.body.style.zoom = currentZoom * zoom; 34 } ); 35 } ); 36 37 38 /** 39 * Disabling form submissions if there are invalid fields 40 */ 41 // Fetch all the forms we want to apply custom Bootstrap validation styles to 42 const forms = document.querySelectorAll('.needs-validation'); 43 // Loop over them and prevent submission 44 Array.from(forms).forEach( form => { 45 form.setAttribute( 'novalidate', true ); 46 form.addEventListener( 'submit', event => { 47 if ( ! form.checkValidity() ) { 48 event.preventDefault(); 49 event.stopPropagation(); 50 } 51 52 form.classList.add( 'was-validated' ); 53 }, false ); 54 }); 55 56 57 /** 58 * Menu 59 * 60 const primaryMenu = document.getElementById( 'primary-menu' ); 61 var primaryChildren = primaryMenu.querySelectorAll( '.menu-item-has-children' ); 62 primaryChildren.forEach( function ( childLink ) { 63 childLink.addEventListener( 'click', ( e ) => { 64 console.log( e ); 65 66 e.preventDefault(); 67 return false; 68 } ); 69 } ); 70 */ 71 72 73 /** 74 * Open and close the search bar 75 */ 76 const searchBar = document.querySelector( '.wpb5-topo' ).querySelector( '.search-bar' ); 77 searchBar.querySelector( '.search-bar__toggle' ).addEventListener( 'click', ( e ) => { 78 if ( !searchBar.classList.contains( 'open' ) ) { 79 e.target.closest( '.site-header' ).classList.add( 'open' ); 80 searchBar.classList.add( 'open' ); 81 searchBar.querySelector( 'input[name="s"]' ).focus(); 82 e.preventDefault(); 83 return; 84 } 85 86 searchBar.classList.remove( 'open' ); 87 } ); 88 searchBar.querySelector( '.search-bar__close' ).addEventListener( 'click', ( e ) => { 89 searchBar.classList.remove( 'open' ); 90 document.querySelector( '.site-header' ).classList.toggle( 'open' ); 91 } ); 92 93 /** 94 * Toggle Menu 95 */ 96 document.querySelector( '.navbar-toggler' ).addEventListener( 'click', ( e ) => { 97 document.querySelector( '.site-header' ).classList.toggle( 'open' ); 98 } ); 99 100 /** 101 * Add target=_blank in all external links 102 */ 103 const currentHostname = window.location.hostname; 104 document.querySelectorAll( 'a' ).forEach( link => { 105 if (link.href && link.hostname !== currentHostname && link.protocol !== 'javascript:') { 106 link.target = '_blank'; 107 } 108 }); 109 110 /** 111 * Replace all SVG images with inline SVG 112 */ 113 document.querySelectorAll( 'img.svg' ).forEach( img => { 114 let imgID = img.id; 115 let imgClass = img.className; 116 let imgURL = img.src; 117 118 fetch( imgURL ).then( response => { 119 return response.text(); 120 } ).then( text => { 121 let parser = new DOMParser(), 122 xmlDoc = parser.parseFromString( text, "text/xml" ), 123 // Get the SVG tag, ignore the rest 124 svg = xmlDoc.getElementsByTagName( 'svg' )[0]; 125 126 // Add replaced image's ID to the new SVG 127 if ( typeof imgID !== 'undefined' ) { 128 svg.setAttribute( 'id', imgID ); 129 } 130 // Add replaced image's classes to the new SVG 131 if ( typeof imgClass !== 'undefined' ) { 132 svg.setAttribute( 'class', imgClass + ' replaced-svg' ); 133 } 134
135 // Remove any invalid XML tags as per http://validator.w3.org 136 svg.removeAttribute( 'xmlns:a' ); 137 138 // Check if the viewport is set, if the viewport is not set the SVG wont't scale. 139 if ( !svg.getAttribute( 'viewBox' ) && svg.getAttribute( 'height' ) && svg.getAttribute( 'width' ) ) { 140 svg.setAttribute( 'viewBox', '0 0 ' + svg.getAttribute( 'height' ) + ' ' + svg.getAttribute( 'width' ) ); 141 } 142 143 // Replace image with new SVG 144 img.parentNode.replaceChild( svg, img ); 145 } ); 146 } ); 147 148 149 /** 150 * BS5 Lightbox 151 */ 152 //for ( const el of document.querySelectorAll( '.my-lightbox-toggle' ) ) { 153 //el.addEventListener( 'click', Lightbox.initialize ); 154 //} 155 const options = { 156 keyboard: true, 157 size: 'xl' 158 }; 159 document.querySelectorAll( '.my-lightbox-toggle' ).forEach( el => el.addEventListener( 'click', e => { 160 e.preventDefault(); 161 const lightbox = new Lightbox( el, options ); 162 lightbox.show(); 163 } ) ); 164 165 /** 166 * Ajax functions 167 */ 168 var last_scroll = 0; 169 const load_more_btn = document.querySelectorAll( '.wpb5-load-more' ); 170 const filterContainer = document.getElementById( 'wpb5-filter-container' ); 171 const filterHiddenInput = document.getElementById( 'wpb5-category-filter' ); 172 const filterAllTemas = document.getElementById( 'all-temas' ); 173 174 load_more_btn.forEach( el => el.addEventListener( 'click', () => { 175 if ( el.classList.contains( 'loading' ) ) { 176 return; 177 } 178 wpb5CategoryLoadMorePosts( el ); 179 } ) ); 180 181 if ( typeof( filterContainer ) !== 'undefined' && filterContainer !== null ) { 182 let options = filterContainer.querySelectorAll( '.wpb5-category-filter' ); 183 var counter = 0; 184 185 options.forEach( option => option.addEventListener( 'change', () => { 186 var tema = ''; 187 188 if ( option.getAttribute( 'name' ) !== 'tema' ) { 189 // Update counter 190 counter++; 191 192 // Syncronize inputs and select to work in different window sizes 193 if ( option.hasAttribute( 'id' ) ) { 194 filterContainer.querySelector( 'select' ).value = option.value; 195 } 196 else { 197 document.getElementById( 'option-' + option.value ).checked = true; 198 } 199 200 if ( typeof( filterAllTemas ) !== 'undefined' && filterAllTemas !== null ) { 201 // Update all temas 202 filterAllTemas.checked = true; 203 filterAllTemas.disabled = true; 204 filterContainer.querySelectorAll( '[name="tema"]' ).forEach( el => { 205 el.setAttribute( 'data-category', option.value ); 206 if ( el.type === 'radio' ) { 207 el.removeAttribute( 'checked' ); 208 el.removeAttribute( 'disabled' ); 209 } 210 else { 211 Array.from( el ).forEach( selectTema => { 212 selectTema.removeAttribute( 'selected' ); 213 } ); 214 el.querySelector( 'option:first-of-type' ).setAttribute( 'selected', true ); 215 } 216 217 filterHiddenInput.setAttribute( 'data-meta_value', '' ); 218 } ); 219 } 220 221 // Update hidden input 222 filterHiddenInput.setAttribute( 'data-category', option.value ); 223 if ( option.dataset.category !== undefined ) { 224 filterHiddenInput.setAttribute( 'data-category', option.dataset.category ); 225 } 226 filterHiddenInput.setAttribute( 'data-counter', counter ); 227 filterHiddenInput.value = option.value; 228 } 229 else { 230 // Syncronize inputs and select to work in different window sizes 231 if ( option.hasAttribute( 'id' ) ) { 232 filterContainer.querySelector( 'select[name="tema"]' ).value = option.value; 233 } 234 else { 235 document.getElementById( option.value ).checked = true; 236 } 237 238 // Update hidden input 239 filterHiddenInput.setAttribute( 'data-meta_value', option.value ); 240 241 tema = option.value; 242 } 243 244 // Update load more button
245 load_more_btn.forEach( loadBtn => { 246 loadBtn.setAttribute( 'data-meta_value', tema ); 247 } ); 248 249 wpb5CategoryFilter( filterHiddenInput ); 250 251 } ) ); 252 } 253 254 /** 255 * Scroll functions 256 */ 257 this.addEventListener( 'scroll', () => { 258 var scroll = this.scrollY; 259 if ( typeof( filterHiddenInput ) !== 'undefined' && filterHiddenInput !== null ){ 260 const breadcrumb = document.getElementById( 'wpb5-breadcrumb' ); 261 var tema = filterHiddenInput.getAttribute( 'data-meta_value' ); 262 263 if ( Math.abs( scroll - last_scroll ) > this.innerHeight * 0.1 ) { 264 last_scroll = scroll; 265 266 document.querySelectorAll( '.page-limit' ).forEach( el => { 267 if ( isVisible( el ) ) { 268 // Update browser address bar 269 history.replaceState( null, null, el.dataset.location ); 270 271 // Update breadcrumb 272 if ( breadcrumb.querySelector( '.small' ) !== null ) { 273 breadcrumb.querySelector('.small').remove(); 274 } 275 if ( el.dataset.paged > 1 ) { 276 breadcrumb.querySelector('.active').insertAdjacentHTML( 'beforeend', '<span class="ms-1 small">(Pág. ' + el.dataset.paged + ')</span>' ); 277 } 278 return; 279 } 280 } ); 281 } 282 } 283 } ); 284} ); 285 286/* 287 * Alternative accordion layout ( Com e para quem ) 288 */ 289var newAccordion = function( id ) { 290 const mainDiv = document.querySelector( id ); 291 const accordions = mainDiv.querySelectorAll( '.post-thumbnail' ); 292 const titles = mainDiv.querySelectorAll( '.card-title' ); 293 294 accordions.forEach( accordion => { 295 toggleAccordion( accordions, accordion ); 296 } ); 297
298 titles.forEach( title => { 299 toggleAccordion( accordions, title, false ); 300 } ); 301} 302 303function toggleAccordion( accordions, accordion, thumb = true ) { 304 if ( window.innerWidth < 1100 ) { 305 accordion.parentElement.classList.remove('open'); 306 } 307 308 accordion.addEventListener( 'click', () => { 309 var item = accordion.parentElement; 310 if ( ! item.classList.contains( 'open' ) ) { 311 if ( window.innerWidth > 1099.98 ) { 312 accordions.forEach( el => { 313 el.parentElement.classList.remove( 'open' ); 314 } ); 315 } 316 item.classList.add( 'open' ); 317 return; 318 } 319 if ( thumb === true ) { 320 item.classList.toggle( 'open' ); 321 } 322 } ); 323 324} 325 326function simulateCtrlKeyPlus() { 327 let currentZoom = parseFloat( document.body.style.zoom ) || 1 328 document.body.style.zoom = currentZoom * 1.1 329} 330 331/** 332 * Helper functions 333 */ 334async function wpb5CategoryLoadMorePosts( el ) { 335 let page = el.dataset.page; 336 let prev = el.dataset.prev; 337 let newPage = parseInt( page ) + 1; 338 let ajaxurl = el.dataset.url; 339 340 if ( typeof prev === 'undefined' ) { 341 prev = 0; 342 } 343 344 el.classList.add( 'loading' ); 345 346 let formData = new FormData(); 347 formData.append( 'page', page ); 348 formData.append( 'newPage', newPage ); 349 formData.append( 'prev', prev ); 350 formData.append( 'query_args', el.dataset.query ); 351 formData.append( 'args', el.dataset.args ); 352 formData.append( 'meta_value', el.dataset.meta_value ); 353 formData.append( 'action', 'wpb5_load_more' ); 354 355 await fetch( ajaxurl, { 356 method: 'POST', 357 body: formData 358 } ) 359 .then( response => response.json() ) 360 .then( response => { 361 const breadcrumb = document.getElementById( 'wpb5-breadcrumb' ); 362 const categoryContainer = document.querySelector( '.wpb5-category' ); 363 if ( response.no_more_posts === true ) { 364 let string = '<div class="message fade show wpb5-noresults"><h4 class="mb-0">Não há mais posts a serem exibidos!</h4></div>'; 365 hideBtn( el, categoryContainer, string ); 366 return; 367 } 368 369 if ( prev == 1 ) { 370 categoryContainer.insertAdjacentHTML( 'afterbegin', response.text ); 371 newPage = page - 1; 372 } else { 373 categoryContainer.insertAdjacentHTML( 'beforeend', response.text ); 374 el.dataset.posts = parseInt( response.num_posts ); 375 } 376 377 if ( newPage == 1 ) { 378 hideBtn( el, categoryContainer ); 379 } else { 380 el.dataset.page = newPage; 381 el.classList.remove( 'loading' ); 382 } 383 384 if ( response.load_more == 0 ) { 385 hideBtn( el, categoryContainer ); 386 } 387 388 // Update browser address bar 389 history.replaceState( null, null, response.location ); 390 391 // Update breadcrumb 392 if ( breadcrumb.querySelector( '.small' ) !== null ) { 393 breadcrumb.querySelector('.small').remove(); 394 } 395 if ( response.paged > 1 ) { 396 breadcrumb.querySelector('.active').insertAdjacentHTML( 'beforeend', '<span class="ms-1 small">(Pág. ' + response.paged + ')</span>' ); 397 } 398 399 revealPosts(); 400 } ); 401} 402 403async function wpb5CategoryFilter( el ) { 404 // Prevent double click 405 if ( el.classList.contains( 'loading' ) ) { 406 return; 407 } 408 409 document.querySelectorAll( '.wpb5-load-more' ).forEach( elem => { 410 hideBtn( elem ); 411 } ); 412 413 // Hide all articles 414 document.querySelector( '.wpb5-category' ).querySelectorAll( '.card' ).forEach( article => { 415 hideBtn( article ); 416 } ); 417 document.querySelector( '.wpb5-category' ).innerHTML = '<p class="text-center wpb5-noresults"><span class="wpb5-icon wpb5-spinner animate"</span></p>'; 418 419 let ajaxurl = el.dataset.url; 420 let args = el.dataset.args; 421 let meta_value = el.dataset.meta_value !== 'all-temas' ? el.dataset.meta_value : ''; 422 423 el.classList.add( 'loading' ); 424 425 let formData = new FormData(); 426 formData.append( 'category', el.value ); 427 formData.append( 'base', el.dataset.category ); 428 formData.append( 'origin', el.dataset.origin ); 429 formData.append( 'meta_value', meta_value ); 430 formData.append( 'query_args', el.dataset.query ); 431 formData.append( 'args', args ); 432 formData.append( 'action', 'wpb5_category_filter' ); 433 434 await fetch( ajaxurl, { 435 method: 'POST', 436 body: formData, 437 } ) 438 .then( response => response.json() ) 439 .then( response => { 440 const breadcrumb = document.getElementById( 'wpb5-breadcrumb' ); 441 const categoryContainer = document.querySelector( '.wpb5-category' ); 442 var paged = breadcrumb.querySelector( '.small' ); 443 if ( paged != null ) { 444 paged.remove(); 445 } 446 447 // Update browser address bar 448 history.replaceState( null, null, response.location ); 449 //window.location.href = response.location; 450 451 document.querySelectorAll( '.wpb5-category-filter' ).forEach( option => { 452 option.removeAttribute( 'disabled' ); 453 option.removeAttribute( 'checked' ); 454 } ); 455 456 document.getElementById( 'option-' + el.value ).setAttribute( 'checked', true ); 457 document.getElementById( 'option-' + el.value ).setAttribute( 'disabled', true ); 458 if ( el.dataset.meta_value !== '' ) { 459 document.getElementById( el.dataset.meta_value ).setAttribute( 'checked', true ); 460 document.getElementById( el.dataset.meta_value ).setAttribute( 'disabled', true ); 461 } 462 else { 463 // Update breadcrumb 464 breadcrumb.querySelectorAll( '.breadcrumb-item' ).forEach( item => { 465 if ( item.classList.contains( 'active' ) ) { 466 if ( el.dataset.origin != 0 ) { 467 if ( el.dataset.counter == 1 ) { 468 breadcrumb.querySelector( '.active' ).previousSibling.classList.add( 'base' ); 469 470 if ( el.dataset.category == 0 ) { 471 breadcrumb.querySelector( '.active' ).classList.add( 'remove' ); 472 } else { 473 breadcrumb.querySelector( '.active' ).remove(); 474 } 475 } 476 } 477 478 if ( el.dataset.category != 0 && response.category !== undefined ) { 479 item.classList.remove( 'active' ); 480 item.removeAttribute( 'aria-current' ); 481 item.classList.add( 'base' ); 482 } 483 } 484 485 if ( item.classList.contains( 'remove' ) && response.category !== undefined ) { 486 breadcrumb.querySelector( '.remove' ).remove(); 487 } 488 } ); 489 490 if ( response.category !== undefined ) { 491 document.getElementById( 'page' ).querySelector( '.page-title' ).innerHTML = response.category; 492 493 if ( el.dataset.category != 0 ) { 494 breadcrumb.innerHTML += '<li class="breadcrumb-item active remove" aria-current="page">' + response.category + '</li>'; 495 } else { 496 breadcrumb.querySelector( '.base' ).classList.add( 'active' ); 497 breadcrumb.querySelector( '.base' ).setAttribute( 'aria-current', 'page' ); 498 breadcrumb.querySelector( '.base' ).classList.remove( 'base' ); 499 } 500 } 501 } 502 503 document.querySelectorAll( '.wpb5-load-more' ).forEach( elem => { 504 var obj = JSON.parse( args ); 505 // Show only the next page load button 506 if ( ! elem.classList.contains( 'wpb5-load-prev' ) ) { 507 showBtn( elem ); 508 } 509 // Hide the next page load button if there is only one result page 510 if ( response.load_more == 0 ) { 511 hideBtn( elem, categoryContainer ); 512 } 513 elem.dataset.page = 1; 514 elem.dataset.posts = obj.posts; 515 elem.dataset.args = JSON.stringify( response.args ); 516 elem.dataset.query = JSON.stringify( response.query_args ); 517 elem.dataset.archive = response.location; 518 } ); 519 520 categoryContainer.innerHTML = response.text; 521 522 el.classList.remove( 'loading' ); 523 524 revealPosts(); 525 } ); 526} 527 528function revealPosts() { 529 let posts = document.querySelectorAll( 'article.hide' ); 530 let i = 0; 531 532 setInterval( () => { 533 if ( i >= posts.length ) { 534 return false;
535 } 536 posts[i].classList.remove( 'hide' ); 537 i++; 538 }, 100 ); 539} 540 541function isVisible( element ) { 542 var scroll_pos = window.scrollY, 543 window_height = window.innerHeight, 544 el_top = element.offsetTop, 545 el_height = element.clientHeight, 546 el_bottom = el_top + el_height; 547 548 return ( ( el_bottom - el_height * 0.25 > scroll_pos ) && ( el_top < ( scroll_pos + window_height * 0.5 ) ) ); 549} 550 551function hideBtns( elem, container = '', string = '' ) { 552 elem.forEach( el => { 553 hideBtn( el ); 554 } ); 555} 556 557function hideBtn( el, container = '', string = '' ) { 558 el.classList.add( 'hide' ); 559 if ( container !== '' ) { 560 container.innerHTML += string; 561 } 562} 563 564function showBtns( elem ) { 565 elem.forEach( el => { 566 showBtn( el ); 567 } ); 568} 569 570function showBtn( el ) { 571 el.classList.remove( 'loading' ); 572 el.classList.remove( 'hide' ); 573}
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.