1/** 2 * File navigation.js. 3 * 4 * Handles toggling the navigation menu for small screens and enables TAB key 5 * navigation support for dropdown menus. 6 */ 7(function () { 8 var container, button, menu, links, i, len; 9 10 container = document.getElementById('site-navigation'); 11 reportContainer = jQuery('.article__report__sticky-nav__left').eq(0)[0]; 12 body = document.body; 13 if (!container) { 14 return; 15 } 16 17 // button = container.getElementsByClassName('menu-toggle')[0]; 18 button = container.getElementsByClassName('menu-toggle-no-js')[0]; 19 if ('undefined' === typeof button) { 20 // console.log('Button Not Found'); 21 return; 22 } 23 24 menu = container.getElementsByTagName('ul')[0]; 25 26 // Hide menu toggle button if menu is empty and return early. 27 if ('undefined' === typeof menu) { 28 button.style.display = 'none'; 29 return; 30 } 31 32 // if (-1 === menu.className.indexOf('nav-menu')) { 33 // menu.className += ' nav-menu'; 34 // } 35 36 button.onclick = () => { 37 if (-1 !== body.className.indexOf('toggled')) { 38 // container.className = container.className.replace(' toggled', ''); 39 body.className = body.className.replace(' toggled', ''); 40 button.setAttribute('aria-expanded', 'false'); 41 } else { 42 // container.className += ' toggled'; 43 body.className += ' toggled'; 44 button.setAttribute('aria-expanded', 'true'); 45 } 46 }; 47 48 // Close small menu when user clicks outside 49 document.addEventListener('click', (event) => { 50 var isClickInside = container && container.contains(event.target); 51 var isClickInsideReport = reportContainer && reportContainer.contains(event.target); 52 53 if (reportContainer) { 54 if (!isClickInside && !isClickInsideReport) { 55 container.className = container.className.replace(' toggled', ''); 56 body.className = body.className.replace(' toggled', ''); 57 button.setAttribute('aria-expanded', 'false'); 58 } 59 } else { 60 if (!isClickInside) { 61 container.className = container.className.replace(' toggled', ''); 62 body.className = body.className.replace(' toggled', ''); 63 button.setAttribute('aria-expanded', 'false'); 64 } 65 } 66 }); 67 68 // Get all the link elements within the menu. 69 links = menu.getElementsByTagName('a'); 70 71 // Each time a menu link is focused or blurred, toggle focus. 72 for (i = 0, len = links.length; i < len; i++) { 73 links[i].addEventListener('focus', toggleFocus, true); 74 links[i].addEventListener('blur', toggleFocus, true); 75 } 76 77 /** 78 * Sets or removes .focus class on an element. 79 */ 80 function toggleFocus() { 81 var self = this; 82 83 // Move up through the ancestors of the current link until we hit .nav-menu. 84 // while (-1 === self.className.indexOf('nav-menu')) { 85 while (-1 === self.className.indexOf('menu')) { 86 // On li elements toggle the class .focus. 87 if ('li' === self.tagName.toLowerCase()) { 88 if (-1 !== self.className.indexOf('focus')) { 89 self.className = self.className.replace(' focus', ''); 90 } else { 91 self.className += ' focus'; 92 } 93 } 94 95 self = self.parentElement; 96 } 97 } 98 99 /** 100 * Toggles `focus` class to allow submenu access on tablets. 101 */ 102 (function () { 103 var touchStartFn, 104 parentLink = container.querySelectorAll( 105 '.menu-item-has-children > a, .page_item_has_children > a', 106 ); 107 108 if ('ontouchstart' in window) { 109 touchStartFn = function (e) { 110 var menuItem = this.parentNode; 111 112 if (!menuItem.classList.contains('focus')) { 113 e.preventDefault(); 114 for (i = 0; i < menuItem.parentNode.children.length; ++i) { 115 if (menuItem === menuItem.parentNode.children[i]) { 116 continue; 117 } 118 menuItem.parentNode.children[i].classList.remove(
119 'focus', 120 ); 121 } 122 menuItem.classList.add('focus'); 123 } else { 124 menuItem.classList.remove('focus'); 125 } 126 }; 127 128 for (i = 0; i < parentLink.length; ++i) { 129 parentLink[i].addEventListener( 130 'touchstart', 131 touchStartFn, 132 false, 133 ); 134 } 135 } 136 })(container); 137})(); 138 139/* eslint-disable */ 140jQuery(document).ready(function ($) { 141 const $body = $('body'); 142 // Add a class on body for MacOS users 143 if (window.navigator.userAgent.match(/Macintosh/)) { 144 $body.addClass('runs-on-mac'); 145 } 146 147 /** 148 * Hide header on scroll down, show on scroll back up 149 */ 150 var didScroll; 151 var lastScrollTop = 0; 152 var delta = 115; 153 var navbarHeight = $('header').outerHeight(); 154 var articleReportTop = ($('.article.article--post.category-reports .article__report').length === 1) ? $('.article__report').position().top : false; 155 156 window.addEventListener('load', function () { 157 if ( 158 window.scrollY > delta || 159 document.documentElement.scrollTop > delta 160 ) { 161 $('body').removeClass('nav-up').addClass('nav-down'); 162 } 163 }); 164 165 $(window).scroll(function (event) { 166 didScroll = true; 167 }); 168 169 setInterval(function () { 170 if (didScroll) { 171 hasScrolled(); 172 didScroll = false; 173 } 174 }, 250); 175 176 function hasScrolled() { 177 var st = $(this).scrollTop(); 178 179 // Make sure they scroll more than delta 180 if (Math.abs(lastScrollTop - st) <= delta) return; 181 182 // If they scrolled down and are past the navbar, add class .nav-up. 183 if (st > lastScrollTop && st > navbarHeight) { 184 // Scroll Down 185 $('body').removeClass('nav-down').addClass('nav-up'); 186 $('li.ubermenu-item').each(function () { 187 var element = $(this); 188 189 // Check if the current element has the specific class 190 if (element.hasClass('ubermenu-active')) { 191 // Remove the old class and add the new class 192 element 193 .removeClass('ubermenu-active') 194 .addClass('ubermenu-active-up'); 195 } 196 }); 197 } else { 198 // Scroll Up 199 if (st + $(window).height() < $(document).height()) { 200 $('body').removeClass('nav-up').addClass('nav-down'); 201 $('li.ubermenu-item').each(function () { 202 var element = $(this); 203 204 // Check if the current element has the specific class 205 if (element.hasClass('ubermenu-active-up')) { 206 // Remove the old class and add the new class 207 element 208 .removeClass('ubermenu-active-up') 209 .addClass('ubermenu-active'); 210 } 211 }); 212 } 213 } 214 215 if (articleReportTop !== false && st > articleReportTop) { 216 $('body').addClass('show-report-sticky-nav'); 217 } else { 218 $('body').removeClass('show-report-sticky-nav'); 219 } 220 221 // If at top remove background on nav 222 if (st < delta) { 223 $('body').removeClass('nav-down'); 224 } 225 226 lastScrollTop = st; 227 } 228 229 /** 230 * Clients Slider 231 */ 232 var clients = $('.clients-slider'); 233 if (clients.length) { 234 //start the slider 235 clients.slick({ 236 infinite: false, 237 slidesToShow: 1, 238 slidesToScroll: 1, 239 smoothHeight: true, 240 arrows: false, 241 dots: true, 242 }); 243 } 244 245 /** 246 * Quotes Slider 247 */ 248 var quotes = $('.quotes-slider'); 249 if (quotes.length) { 250 //start the slider 251 quotes.slick({ 252 slidesToShow: 1, 253 autoplay: true, 254 dots: true,
255 arrows: false, 256 fade: true, 257 pauseOnHover: true, 258 speed: 500, 259 autoplaySpeed: 4000, 260 slide: '.quote-slide' 261 }); 262 } 263 264 /** 265 * Bio Popups 266 */ 267 if ( 268 $('.popup-with-zoom-anim').length && 269 typeof jQuery.fn.magnificPopup === 'function' 270 ) { 271 $('.popup-with-zoom-anim').magnificPopup({ 272 type: 'inline', 273 fixedContentPos: false, 274 fixedBgPos: true, 275 overflowY: 'auto', 276 closeBtnInside: true, 277 preloader: false, 278 midClick: true, 279 removalDelay: 300, 280 mainClass: 'my-mfp-zoom-in', 281 }); 282 } 283 284 /** 285 * Tabbed Content Block 286 */ 287 $('.wp-block.acf-block.tabbedcontent').each(function () { 288 const $block = $(this); 289 const $tabs = $block.find('.tab-links'); 290 291 if ($tabs.length && window.location.hash) { 292 const id = window.location.hash.replace('#', ''); 293 294 $block.find('.tab-links li').removeClass('active'); 295 $block.find('a[href="#' + id + '"]') 296 .parent('li') 297 .addClass('active'); 298 299 // $block.find('.tab').removeClass('active'); 300 // $block.find('#' + id).addClass('active'); 301 $block.find('.tab').removeAttr('open'); 302 $block.find('#' + id).attr('open', ''); 303 } 304 305 $block.on('click', '.tab-links a', function (e) { 306 // Prevent default on tabbed content that is not tabbed anchor links content 307 if ($(this).parents('.tabbedcontent').length) { 308 e.preventDefault(); 309 } 310 311 const hash = $(this) 312 .attr('href') 313 .substring($(this).attr('href').indexOf('#') + 1); 314 315 // Remove active class from all tab links and tabs 316 $('.tab-links li').removeClass('active'); 317 $('.tab').removeAttr('open'); 318 // $('.tab').removeClass('active'); 319 320 // Add active class to the clicked tab link and corresponding tab 321 $(this).parent('li').addClass('active'); 322 // $('#' + hash).addClass('active'); 323 $('#' + hash).attr('open', ''); 324 }); 325 326 $block.find('.tab').each(function () { 327 this.addEventListener("toggle", (event) => { 328 if (event.target.open) { 329 $block.find('.tab-links a[href*=#' + event.target.id + ']') 330 .parent('li') 331 .addClass('active'); 332 333 if (window.matchMedia('(max-width: 1023px)').matches) { 334 window.scroll({ 335 top: $block.find('.tab').eq(0).offset().top - 80 + $(event.target).index() * 55, 336 left: 0, 337 behavior: "smooth", 338 }); 339 340 setTimeout(() => { 341 event.target.scrollIntoView({ behavior: 'smooth' }); 342 }, 500); 343 } 344 } else { 345 $block.find('.tab-links a[href*=#' + event.target.id + ']') 346 .parent('li') 347 .removeClass('active'); 348 } 349 }); 350 }); 351 }); 352 353 /** 354 * Resource accordion Block 355 */ 356 $('.wp-block.wak-acf-block.wak-acf-block-altrata-resourceaccordion').each(function () { 357 const $block = $(this); 358 359 $block.find('.wak-accordion').each(function () { 360 this.addEventListener("toggle", (event) => { 361 if (event.target.open) { 362 const accordion_rect = event.target.getBoundingClientRect(); 363 364 if (!( 365 accordion_rect.top >= 80 && 366 accordion_rect.left >= 0 && 367 accordion_rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 368 accordion_rect.right <= (window.innerWidth || document.documentElement.clientWidth) 369 )) { 370 window.scroll({ 371 top: $block.find('.wak-accordion').eq(0).offset().top - 80 - 20 + $(event.target).index() * 145, 372 left: 0, 373 behavior: "smooth", 374 }); 375 376 setTimeout(() => { 377 event.target.scrollIntoView({ behavior: 'smooth' }); 378 }, 500); 379 } 380 } 381 }); 382 }); 383 }); 384 385 /** 386 * Resource Expandable Block 387 */ 388 $('.wp-block.wak-acf-block.wak-acf-block-altrata-resourceexpandable').each(function () { 389 const $block = $(this); 390 391 $block.find('.wak-ec-details').each((index, el) => { 392 el.addEventListener("toggle", (event) => { 393 if (event.target.open) { 394 let block_rect = $block[0].getBoundingClientRect(); 395 396 if (!( 397 block_rect.top >= 80 && 398 block_rect.left >= 0 && 399 block_rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 400 block_rect.right <= (window.innerWidth || document.documentElement.clientWidth) 401 )) { 402 window.scroll({ 403 top: $block.offset().top - 80 - 20, 404 left: 0, 405 behavior: "smooth", 406 }); 407 } 408 409 setTimeout(() => { 410 block_rect = $block[0].getBoundingClientRect(); 411 412 if (!( 413 block_rect.top >= 80 && 414 block_rect.left >= 0 && 415 block_rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 416 block_rect.right <= (window.innerWidth || document.documentElement.clientWidth) 417 )) { 418 $block[0].scrollIntoView({ behavior: 'smooth' }); 419 } 420 }, 500); 421 } 422 }); 423 }); 424 }); 425 426 /** 427 * Resource Expandable Block 428 */ 429 $('.wp-block.wak-acf-block.wak-acf-block-altrata-resourcehero, .wp-block.wak-acf-block-altrata-reporthero').each(function () { 430 const $block = $(this); 431 const $reading_speed = $block.find('.wak-reading-time'); 432 433 if ($reading_speed.length === 0) { 434 return; 435 } 436 437 const reading_speed = parseInt($reading_speed.data('readingSpeed')); 438 439 function get_text(el) { 440 let ret = ""; 441 const length = el.childNodes.length; 442 443 for (let i = 0; i < length; i++) { 444 const node = el.childNodes[i]; 445 446 if ( 447 node.nodeName.toLowerCase() === 'style' || node.nodeName.toLowerCase() === 'script' || 448 node.nodeName.toLowerCase() === 'input' || node.nodeName.toLowerCase() === 'textarea' 449 ) { 450 continue; 451 } 452 453 if (node.nodeType != 8) { 454 ret += node.nodeType != 1 ? ' ' + node.nodeValue.trim() : get_text(node); 455 } 456 } 457 return ret; 458 } 459 460 const words = get_text(document.getElementById('main')); 461 const count = words.split(/\s+/).length; 462 463 $reading_speed.html(Math.ceil(count / reading_speed) + 'min.'); 464 }); 465 466 var dc_template = $('.page-template-template-dc, .new-style-blocks'); 467 if (dc_template.length) { 468 /** 469 * Animate Numbers 470 */ 471 function animateNumber(element, startNumber, targetNumber, duration) { 472 // Remove non-numeric characters and parse as float 473 // let startNumber = parseFloat(
474 // element.innerText.replace(/[^0-9.-]+/g, ''), 475 // ); 476 let increment = (targetNumber - startNumber) / (duration / 16); 477 let currentNumber = startNumber; 478 let interval = setInterval(function () { 479 currentNumber += increment; 480 // Format the number before setting it 481 element.innerText = formatNumber(currentNumber, targetNumber); 482 if ( 483 (increment > 0 && currentNumber >= targetNumber) || 484 (increment < 0 && currentNumber <= targetNumber) 485 ) { 486 clearInterval(interval); 487 element.innerText = formatNumber( 488 targetNumber, 489 targetNumber, 490 ); 491 } 492 }, 16); 493 } 494 495 // Format number to US format, with or without decimal places 496 function formatNumber(currentNumber, targetNumber) { 497 const hasDecimal = targetNumber % 1 !== 0; 498 return new Intl.NumberFormat('en-US', { 499 maximumFractionDigits: hasDecimal ? 2 : 0, 500 minimumFractionDigits: hasDecimal ? 1 : 0, 501 }).format(currentNumber); 502 } 503 504 // Animation Intersection Observer callback function 505 function handleAnimation(entries, observer) { 506 entries.forEach((entry) => { 507 if (entry.isIntersecting) { 508 // If numbers animateNumber 509 if ($(entry.target).hasClass('number')) { 510 const startNumber = 511 parseFloat(entry.target.getAttribute('data-start')) ?? 0; 512 const targetNumber = 513 parseFloat(entry.target.getAttribute('data-target')); 514 const duration = 2000; 515 animateNumber(entry.target, startNumber, targetNumber, duration); 516 } else { 517 // Handle other animations add trigger class 518 entry.target.classList.toggle('trigger'); 519 } 520 521 // Stop observing once animation is triggered 522 observer.unobserve(entry.target); 523 } 524 }); 525 } 526 527 // Create an Intersection Observer 528 let animation_observer = new IntersectionObserver(handleAnimation, { 529 threshold: 0.30, 530 }); 531 // Target animation elements to observe 532 let animation = document.querySelectorAll('.animated'); 533 // Start observing each target element 534 animation.forEach((target) => { 535 animation_observer.observe(target); 536 }); 537 } 538 539 // Resources and filters 540 $('.resource-style').on('click', function (e) { 541 e.preventDefault(); 542 $('.resource-style').removeClass('active'); 543 $(this).addClass('active'); 544 545 var style = $(this).data('style'); 546 if (style === 'list') { 547 $('.article-resources').removeClass('tile').addClass(style); 548 } else { 549 $('.article-resources').removeClass('list').addClass(style); 550 } 551 }); 552 553 $('.resources_loadmore').on('click', function (e) { 554 e.preventDefault(); 555 556 var maxpages = $(this).attr('data-maxpages'); 557 var block_type = $(this).closest('section').data('block'); 558 var block_tags = $(this).closest('section').data('tags'); 559 var block_posts = $(this).closest('section').data('posts'); 560 var block_cat = $(this).closest('section').attr('data-cat'); 561 var block_news = $(this).closest('section').attr('data-news'); 562 563 var featured_ids = []; 564 $('.resources .featured-resources article').each(function (index, el) { 565 featured_ids.push(parseInt(el.id.replace('post-', ''))); 566 }); 567 568 var selectedTypes = []; 569 $('.types input[name="type"]:checked').each(function () { 570 selectedTypes.push($(this).val()); 571 }); 572 573 var selectedNews = []; 574 $('.types input[name="news"]:checked').each(function () { 575 selectedNews.push($(this).val()); 576 }); 577 578 var button = $(this), 579 data = { 580 action: 'loadmore', 581 security: altrata_loadmore_params.loadmore_nounce, 582 page: altrata_loadmore_params.current_page, 583 featured_ids: featured_ids 584 }; 585 586 if (selectedTypes.length > 0) { 587 data.types = selectedTypes; 588 } 589 590 if (selectedNews.length > 0) { 591 data.news = selectedNews; 592 } 593 594 if(block_type){ //if automated content 595 data.block_type = block_type; 596 data.block_tags = block_tags; 597 data.block_posts = block_posts; 598 data.block_cat = block_cat; 599 data.block_news = block_news; 600 } 601 602 $.ajax({ 603 url: altrata_loadmore_params.ajaxurl, 604 data: data, 605 type: 'POST', 606 beforeSend: function (xhr) { 607 button.text('Loading...'); 608 }, 609 success: function (data) { 610 button.text('More Resources'); 611 if (data) { 612 $('.article-resources') 613 .append(data) 614 .find('.resource-loaded') 615 .hide() 616 .fadeIn(500) 617 .removeClass('resource-loaded'); 618 altrata_loadmore_params.current_page++; 619 620 console.log( 621 'Current Page: ' + 622 altrata_loadmore_params.current_page + 623 ' Max Page: ' + 624 maxpages, 625 ); 626 // if last page, remove the button 627 if (altrata_loadmore_params.current_page == maxpages) { 628 button.hide(); 629 } 630 } else { 631 button.hide(); 632 } 633 }, 634 }); 635 }); 636 637 $(".filters input[type='checkbox']").on('change', function () { 638 $(this).parent('.checkbox-container').toggleClass('active'); 639 var block_type = $(this).closest('section').data('block'); 640 var block_tags = $(this).closest('section').data('tags'); 641 var block_posts = $(this).closest('section').data('posts'); 642 var block_cat = $(this).closest('section').data('cat'); 643 var block_news = $(this).closest('section').data('news'); 644 var block_section = $(this).closest('section'); 645 646 // Filter resources 647 filter_resources(block_type, block_tags, block_posts, block_cat, block_news, block_section); 648 }); 649 650 $('.clear-filters').on('click', function () { 651 $(".resources .filters input[type='checkbox']").prop('checked', false); 652 $('.resources .checkbox-container').removeClass('active'); 653 654 var block_type = $(this).closest('section').data('block'); 655 var block_tags = $(this).closest('section').data('tags'); 656 var block_posts = $(this).closest('section').data('posts'); 657 var block_cat = $(this).closest('section').data('cat'); 658 var block_news = $(this).closest('section').data('news'); 659 var block_section = $(this).closest('section'); 660 // Re filter when removing filters 661 filter_resources(block_type, block_tags, block_posts, block_cat, block_news, block_section); 662 }); 663 664 $("body").on('click', ".featured-resources .resource .cat-link, .resources .article-resources .resource .cat-link", function (e) { 665 e.preventDefault(); 666 667 const filter_value = $(this).data('filter'); 668 669 $(".resources .filters input[type='checkbox'][value='" + filter_value + "']").prop('checked', true); 670 $(".resources .filters input[type='checkbox'][value='" + filter_value + "']").parent('.checkbox-container').addClass('active'); 671 672 var block_type = $(this).closest('section').data('block'); 673 var block_tags = $(this).closest('section').data('tags'); 674 var block_posts = $(this).closest('section').data('posts'); 675 var block_cat = $(this).closest('section').data('cat'); 676 var block_news = $(this).closest('section').data('news'); 677 var block_section = $(this).closest('section'); 678 // Filter resources 679 filter_resources(block_type, block_tags, block_posts, block_cat, block_news, block_section); 680 681 document.querySelector('.resources .row.featured-resources + .row').scrollIntoView({ behavior: 'smooth' }); 682 }); 683 684 function filter_resources(block_type, block_tags, block_posts, block_cat, block_news, block_section) { 685 let selected_types_slugs = []; 686 687 // Get the filterd category 688 var selectedTypes = []; 689 $('.types input[name="type"]:checked').each(function () { 690 selectedTypes.push($(this).val()); 691 selected_types_slugs.push($(this).data('slug')); 692 }); 693 694 // Get the news post type filter 695 var selectedNews = []; 696 $('.types input[name="news"]:checked').each(function () { 697 selectedNews.push($(this).val()); 698 selected_types_slugs.push($(this).data('slug')); 699 }); 700 701 if(block_type){ 702 // altrata_loadmore_params.current_page = 1; 703 if(block_section.find('.types input[name="news"]').is(':checked')){ 704 block_section.attr('data-news', "1"); 705 } else { 706 block_section.attr('data-news', ""); 707 } 708 709 if(selectedTypes){ 710 block_section.attr('data-cat', selectedTypes.join(',')); 711 } else { 712 block_section.attr('data-cat', ''); 713 } 714 715 if(!block_section.find('.types input[name="news"]').is(':checked') && selectedTypes.length === 0){ 716 var data_news_default = block_section.attr('data-news-default'); 717 var data_cat_default = block_section.attr('data-cat-default'); 718 block_section.attr('data-news', data_news_default); 719 block_section.attr('data-cat', data_cat_default); 720 if(data_cat_default.indexOf(',') !== -1){ 721 selectedTypes = data_cat_default.split(','); 722 } else { 723 selectedTypes = [data_cat_default]; 724 } 725 selectedNews.push('news'); 726 } 727 } 728 729 update_address_bar(selected_types_slugs, block_type); 730 // console.log('selected_types_slugs', selected_types_slugs); 731 732 if (selectedTypes.length || selectedNews.length) { 733 $('.clear-filters').show(); 734 } else { 735 $('.clear-filters').hide(); 736 } 737 738 var data = { 739 action: 'filter', 740 security: altrata_loadmore_params.loadmore_nounce, 741 }; 742 743 if (selectedTypes.length > 0) { 744 data.types = selectedTypes; 745 } 746 747 if (selectedNews.length > 0) { 748 data.news = selectedNews; 749 } 750 751 if(block_type){ 752 data.block_type = block_type; 753 data.block_tags = block_tags; 754 data.block_posts = block_posts; 755 data.block_cat = block_cat; 756 data.block_news = block_news; 757 } 758 759 $.ajax({ 760 url: altrata_loadmore_params.ajaxurl, 761 data: data, 762 dataType: 'json', 763 type: 'POST', 764 beforeSend: function (xhr) { 765 let skeleton = ''; 766 for (var i = 0; i < 3; i++) { 767 skeleton = 768 skeleton + 769 '<div class="col-md-4 resource mb-5 card-skeleton"><div class="inner">
769<div class="skeleton skeleton-image"></div><div class="entry-content"><div class="skeleton skeleton-tag"></div><div class="skeleton skeleton-heading"></div><div class="skeleton skeleton-date"></div><div class="skeleton skeleton-more"></div></div></div></div>'; 770 } 771 $('.article-resources').empty().append(skeleton); 772 }, 773 success: function (data) { 774 // when filter applied: 775 // set the current page to 1 776 altrata_loadmore_params.current_page = 1; 777 778 // set the new max page parameter on the button which we get from load more 779 $('.resources_loadmore').attr('data-maxpages', data.max_page); 780 781 // hide load more button if not enough posts to show it 782 if (data.max_page < 2) { 783 $('.resources_loadmore').hide(); 784 } else { 785 $('.resources_loadmore').show(); 786 } 787 788 // insert the posts to the container 789 if (data) { 790 $('.article-resources') 791 .html(data.content) 792 .find('.resource-loaded') 793 .hide() 794 .fadeIn(500) 795 .removeClass('resource-loaded'); 796 } 797 }, 798 }); 799 } 800 801 function update_address_bar(resource_types, block_type) { 802 if(block_type !== 'automated'){ 803 if (resource_types.length === 0) { 804 history.pushState({}, null, '/resources'); 805 } else { 806 history.pushState({}, null, '/resources/types/' + resource_types.join()); 807 } 808 } 809 } 810 811 /** 812 * Report autho load more reports 813 */ 814 $('.report-author--load-more-btn').on('click', function (e) { 815 e.preventDefault(); 816 817 const $button = $(this); 818 819 let data = { 820 action: 'loadmore_author_reports', 821 security: altrata_loadmore_params.loadmore_nounce, 822 report_author: $button.data('reportAuthorId'), 823 page: $button.data('currentPage') + 1 824 }; 825 826 $.ajax({ 827 url: altrata_loadmore_params.ajaxurl, 828 data: data, 829 type: 'POST', 830 beforeSend: function (xhr) { 831 832 }, 833 success: function (data) { 834 if (data) { 835 $('.article.article--report-author .article--report-author--reports-listing .report-author--listing-wrapper') 836 .append(data) 837 .find('.resource-loaded') 838 .hide() 839 .fadeIn(500) 840 .removeClass('resource-loaded'); 841 842 $button.data('currentPage', $button.data('currentPage') + 1); 843 844 if ($button.data('currentPage') == $button.data('maxPages')) { 845 $button.hide(); 846 } 847 } else { 848 $button.hide(); 849 } 850 }, 851 }); 852 }); 853 854 /** 855 * Resource Download Dropdown Block 856 */ 857 $('.wak-acf-block.wak-acf-block-altrata-resourcedownloaddropdown .wak-download-dropdown-item').each(function () { 858 const $block = $(this); 859 860 $block.on('click', function (e) { 861 e.preventDefault(); 862 $block.toggleClass('wak-download-dropdown-open'); 863 }) 864 }); 865 866 /** 867 * Resource Contents Block 868 */ 869 $('.wak-acf-block.wak-acf-block-altrata-resourcecontents').each(function () { 870 const $block = $(this); 871 const dc_contents_is_automated = $block.find('.wak-resource-contents-automatically').val(); 872 873 $block.find('.wak-contents-socials-share-copy').on('click', (e) => { 874 const $body = $('body'); 875 const $button = $(e.target); 876 const $temp = $('<input>'); 877 878 $body.append($temp); 879 $temp.val(window.location.href).select(); 880 document.execCommand('copy'); 881 $temp.remove(); 882 883 $button.parents('.wak-contents-socials-share-link-group').find('.wak-contents-socials-copy-link-notification').addClass('show-notification'); 884 885 setTimeout(() => { 886 $button.parents('.wak-contents-socials-share-link-group').find('.wak-contents-socials-copy-link-notification').removeClass('show-notification'); 887 }, 2000); 888 }); 889 890 if( dc_contents_is_automated === '1' ) { 891 892 let dc_contents_anchor_block_data = []; 893 // add some container in which to find the acf blocks 894 $('.wak-resource-contents-right-column section.wak-acf-block').each(function(){ 895 const _that = $(this); 896 let dc_contents_block_data = {} 897 const dc_contents_block_id = _that.attr('id');
898 const dc_contents_block_title = _that.find('h2.wak-title').eq(0).html(); 899 if(dc_contents_block_title){ 900 dc_contents_block_data['id'] = dc_contents_block_id; 901 dc_contents_block_data['title'] = dc_contents_block_title; 902 dc_contents_anchor_block_data.push(dc_contents_block_data); 903 } 904 }); 905 906 if(dc_contents_anchor_block_data.length !== 0) { 907 let dc_contents_anchor_items = ''; 908 let dc_contents_anchor_items_mob = '<option class="wak-ui-small-text" disabled selected value="">Content</option>'; 909 910 dc_contents_anchor_block_data.forEach(function(anchor, index){ 911 dc_contents_anchor_items += '<a href="#'+ anchor['id'] +'" class="wak-resource-contents-anchor wak-ui-small-text">'+ anchor['title'] +'</a>'; 912 dc_contents_anchor_items_mob += '<option class="wak-ui-small-text" value="#'+ anchor['id'] +'">'+ anchor['title'] +'</option>'; 913 }); 914 915 $block.find('.wak-resource-contents-anchors-list').html(dc_contents_anchor_items); 916 $block.find('.wak-contents-socials-anchors-select').html(dc_contents_anchor_items_mob); 917 } 918 } 919 920 $block.find('.wak-resource-contents-anchors-list .wak-resource-contents-anchor').on('click', function (e) { 921 e.preventDefault(); 922 const _that = $(this); 923 const elem = _that.attr('href'); 924 if($(elem).length !== 0){ 925 $('html, body').animate({ 926 scrollTop: $(elem).offset().top - 130 927 }, 'fast'); 928 } 929 }); 930 931 $block.find('.wak-contents-socials-anchors-select').on('change', function (e) { 932 e.preventDefault(); 933 const _that = $(this); 934 const elem = _that.val(); 935 if($(elem).length !== 0){ 936 $('html, body').animate({ 937 scrollTop: $(elem).offset().top - 140 938 }, 'fast'); 939 _that.val(''); 940 } 941 }); 942 }); 943 944 if($('.wak-acf-block.wak-acf-block-altrata-resourcecontents').length){ 945 $(document).scroll(function(){ 946 $('.wak-acf-block.wak-acf-block-altrata-resourcecontents a.wak-resource-contents-anchor').each(function(){ 947 const _that = $(this); 948 const dc_contents_container = _that.attr('href'); 949 if($(dc_contents_container).length !== 0){ 950 const dc_contents_container_offset = $(dc_contents_container).offset().top; 951 const dc_contents_container_height = $(dc_contents_container).outerHeight(); 952 const dc_contents_container_bottom = dc_contents_container_offset + dc_contents_container_height; 953 const dc_contents_scroll_position = $(document).scrollTop(); 954 955 if(dc_contents_scroll_position < dc_contents_container_bottom - 140 && dc_contents_scroll_position >= dc_contents_container_offset - 140){ 956 _that.addClass('wak-resource-contents-anchor-selected'); 957 } else{ 958 _that.removeClass('wak-resource-contents-anchor-selected'); 959 } 960 } 961 }); 962 }); 963 } 964 965 $body.on('click', '.article__report__details__share-btn', (e) => { 966 const $button = $(e.target); 967 const $temp = $('<input>'); 968 969 $body.append($temp); 970 $temp.val(window.location.href).select(); 971 document.execCommand('copy'); 972 $temp.remove(); 973 974 $button.parents('.article__report__details__share-link-group').find('.article__report__details__share-link-notification').addClass('show-notification'); 975 976 setTimeout(() => { 977 $button.parents('.article__report__details__share-link-group').find('.article__report__details__share-link-notification').removeClass('show-notification'); 978 }, 2000); 979 }); 980 981 $body.on('click', '.article__report__sticky-nav__mobile-contents-btn', () => { 982 $body.toggleClass('toggled'); 983 }); 984 985 $body.on('click', '.article__report__details__back-to-btn', () => { 986 window.scroll({ 987 top: 0, 988 left: 0, 989 behavior: "smooth", 990 }); 991 }); 992 993 $body.on('click', '.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link', () => { 994 setTimeout(() => { 995 $('.article__report__sticky-nav__mobile-contents-btn').removeAttr('open'); 996 $body.removeClass('toggled'); 997 }, 400); 998 }); 999 1000 function report_scroll_spy(e) { 1001 const scroll_margin_top = 71 + 8 + 140; 1002 const contents_list_items = []; 1003 1004 $('.article.article--post.category-reports .article__report .article__report__contents-wrapper .article__report__contents-list .article__report__contents__link').each((i, el) => { 1005 let section_top = 0; 1006 1007 let body_rect = document.body.getBoundingClientRect(); 1008 const section_el = document.getElementById(el.href.split('#')[1]) 1009 let el_rect = section_el ? section_el.getBoundingClientRect() : {}; 1010 section_top = section_el ? (el_rect.top - body_rect.top) : 0; 1011 1012 if (section_top !== 0) { 1013 contents_list_items.push({ 1014 element: el, 1015 link_id: el.dataset.reportContentsListItemLinkId, 1016 section_id: el.href.split('#')[1], 1017 section_top: section_top 1018 }); 1019 } 1020 }); 1021 1022 if (contents_list_items.length > 0) { 1023 for (let i = 0; i < contents_list_items.length; i++) { 1024 if (i === 0) { 1025 if ( 1026 (contents_list_items.length === 1) || 1027 ( 1028 contents_list_items.length > 1 && 1029 window.scrollY < (contents_list_items[i + 1].section_top - scroll_margin_top) 1030 ) 1031 ) { 1032 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link').removeClass('active'); 1033 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link[data-report-contents-list-item-link-id="' + contents_list_items[i].link_id + '"]').addClass('active'); 1034 1035 break; 1036 } 1037 } 1038 1039 if (i > 0 && i < (contents_list_items.length - 1)) { 1040 if ( 1041 window.scrollY >= (contents_list_items[i].section_top - scroll_margin_top) && 1042 window.scrollY < (contents_list_items[i + 1].section_top - scroll_margin_top) 1043 ) { 1044 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link').removeClass('active'); 1045 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link[data-report-contents-list-item-link-id="' + contents_list_items[i].link_id + '"]').addClass('active'); 1046 1047 break; 1048 } 1049 } 1050 1051 if (i === (contents_list_items.length - 1)) { 1052 if (window.scrollY > (contents_list_items[i].section_top - scroll_margin_top)) { 1053 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link').removeClass('active'); 1054 $('.article.article--post.category-reports .article__report .article__report__contents-list .article__report__contents__link[data-report-contents-list-item-link-id="' + contents_list_items[i].link_id + '"]').addClass('active'); 1055 1056 break; 1057 } 1058 } 1059 } 1060 } 1061 1062 // console.log('contents_list_items', contents_list_items, 'window.scrollY', window.scrollY); 1063 } 1064 1065 function updateProgressBar (e) { 1066 const progressBarFill = $('.wak-scroll-progressbar-fill'); 1067 const scrollableHeight = $(document).height() - $(window).height(); 1068 const currentScroll = $(window).scrollTop(); 1069 const scrolledHeight = (currentScroll / scrollableHeight) * 100; 1070 1071 progressBarFill.css('width', scrolledHeight + '%'); 1072 }; 1073 1074 if ($('.article.article--post.category-reports .article__report').length === 1) { 1075 $(window).scroll(report_scroll_spy); 1076 $(window).scroll(updateProgressBar); 1077 } 1078});
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.