1( function( $ ) { 2 "use strict"; 3 4 /** 5 * Throttle's decorator 6 * @param {Function} fn original function 7 * @param {Number} timeout timeout 8 */ 9 function throttle( func, ms ) { 10 var isThrottled = false, 11 savedArgs, 12 savedThis; 13 14 function wrapper() { 15 16 if ( isThrottled ) { 17 savedArgs = arguments; 18 savedThis = this; 19 return; 20 } 21 22 func.apply( this, arguments ); 23 24 isThrottled = true; 25 26 setTimeout( function() { 27 isThrottled = false; 28 if ( savedArgs ) { 29 wrapper.apply( savedThis, savedArgs ); 30 savedArgs = savedThis = null; 31 } 32 }, ms ); 33 } 34 35 return wrapper; 36 } 37 // Get notified when a DOM element enters or exits the viewport. 38 $.fn.isInViewport = function() { 39 var elementTop = $( this ).offset().top; 40 var elementBottom = elementTop + $( this ).outerHeight(); 41 42 var viewportTop = $( window ).scrollTop(); 43 var viewportBottom = viewportTop + $( window ).height(); 44 45 return elementBottom > viewportTop && elementTop < viewportBottom; 46 }; 47 48 // Initialization objectFitImages. 49 $( document ).ready( function() { 50 objectFitImages(); 51 } ); 52 53 /** 54 * Post Carousel 55 */ 56 $( '.cs-post-carousel-items' ).imagesLoaded( function( instance ) { 57 58 var rtl = $( 'body' ).hasClass( 'rtl' ) ? true : false; 59 60 $( instance.elements ).each( function( index, el ) { 61 62 $( el ).flickity( { 63 cellAlign: rtl ? 'right' : 'left', 64 wrapAround: true, 65 contain: true, 66 autoPlay: false, 67 adaptiveHeight: false, 68 prevNextButtons: false, 69 pageDots: true, 70 rightToLeft: rtl, 71 on: { 72 ready: function() { 73 $( el ).addClass( 'is-animate' ); 74 } 75 } 76 } ); 77 78 var container = $( el ).parents( '.cs-post-carousel' ); 79 80 // Select the previous slide. 81 $( container ).find( '.carousel-previous' ).on( 'click', function( event ) { 82 event.preventDefault(); 83 84 var type = rtl ? 'next' : 'previous'; 85 86 $( el ).flickity( type, true ); 87 } ); 88 89 // Select the next slide. 90 $( container ).find( '.carousel-next' ).on( 'click', function( event ) { 91 event.preventDefault(); 92 93 var type = rtl ? 'previous' : 'next'; 94 95 $( el ).flickity( type, true ); 96 } ); 97 } ); 98 99 } ); 100 101 /** 102 * Featured Posts 103 */ 104 $( '.pk-widget-posts-template-carousel > ul' ).imagesLoaded( function( instance ) { 105 106 var rtl = $( 'body' ).hasClass( 'rtl' ) ? true : false; 107 108 $( instance.elements ).each( function( index, el ) { 109 110 $( el ).flickity( { 111 wrapAround: true, 112 adaptiveHeight: true, 113 prevNextButtons: false, 114 pageDots: true, 115 rightToLeft: rtl, 116 on: { 117 ready: function() { 118 $( el ).addClass( 'is-animate' ); 119 } 120 } 121 } ); 122 } ); 123 124 } ); 125 126 /** 127 * Footer Slider 128 */ 129 $( '.footer-instagram-modern .pk-alt-instagram-items' ).imagesLoaded( function( instance ) { 130 131 // Set unique id. 132 var requestId; 133 134 // Set rtl status. 135 var rtl = $( 'body' ).hasClass( 'rtl' ) ? true : false; 136 137 $( instance.elements ).each( function( index, el ) { 138 139 const mainTicker = new Flickity( el, { 140 freeScroll: 'stepwise' === csco_config.instagram_animation ? false : true, 141 percentPosition: 'stepwise' === csco_config.instagram_animation ? false : true, 142 autoPlay: false, 143 pauseAutoPlayOnHover: false, 144 accessibility: true, 145 resize: true, 146 wrapAround: true, 147 prevNextButtons: false, 148 pageDots: false, 149 setGallerySize: true, 150 rightToLeft: rtl, 151 on: { 152 ready: function() { 153 $( el ).addClass( 'is-animate' ); 154 } 155 } 156 } ); 157 158 mainTicker.initAnimation = false; 159 160 // Set initial position to be 0 161 mainTicker.x = 0; 162 163 // Main function that 'plays' the marquee. 164 function flickity_play() { 165 if ( 'continuous' === csco_config.instagram_animation ) { 166 // Set the decrement of position x 167 mainTicker.x = mainTicker.x - 0.75; 168 169 170 // Settle position into the slider 171 mainTicker.settle( mainTicker.x ); 172 173 // Set the requestId to the local variable 174 requestId = window.requestAnimationFrame( flickity_play ); 175 } else { 176 177 mainTicker.playPlayer(); 178 } 179 } 180 181 // Main function to cancel the animation. 182 function flickity_pause() { 183 if ( 'continuous' === csco_config.instagram_animation ) { 184 if ( requestId ) { 185 // Cancel the animation. 186 window.cancelAnimationFrame( requestId ); 187 188 requestId = undefined; 189 } 190 } else { 191 192 mainTicker.stopPlayer(); 193 } 194 } 195 196 // Main function init 197 function flickity_init() { 198 // The monitor. 199 var isInView = $( el ).isInViewport(); 200 201 if ( isInView ) { 202 if ( !mainTicker.initAnimation ) { 203 flickity_play(); 204 205 mainTicker.initAnimation = true; 206 } 207 } else { 208 flickity_pause(); 209 210 mainTicker.initAnimation = false; 211 } 212 } 213 214 // Document scroll. 215 $( window ).on( 'load scroll resize scrollstop', function() { 216 flickity_init(); 217 } ); 218 219 // Document ready. 220 $( document ).ready( function() { 221 flickity_init(); 222 } ); 223 224 // Pause on hover/focus. 225 $( el ).find( '.pk-alt-instagram-link img' ).on( 'mouseenter focusin', e => { 226 flickity_pause(); 227 } ); 228 229 // Unpause on mouse out / defocus. 230 $( el ).find( '.pk-alt-instagram-link img' ).on( 'mouseleave', e => { 231 flickity_play(); 232 } ); 233 234 } ); 235 236 } ); 237 // 238 // Comments show 239 // 240 241 $( document ).on( 'click', '.post-comments-show button', function( e ) { 242 $( this ).parent().siblings( '.post-comments' ).show(); 243 $( this ).parent().remove(); 244 } ); 245 246 ( function() { 247 var ticking = false; 248 249 var update = function() { 250 251 // Sidebar. 252 // -----------------------------------. 253 $( '.content-area .site-main' ).each( function() { 254 255 var content = $( this ).find( '.entry-content' ); 256 var sidebar = $( this ).find( '.post-sidebar-inner' ); 257 258 // Vars offset. 259 var offsetTop = 20; 260 var offsetBottom = -20; 261 262 // Search elements. 263 var elements = []; 264 265 elements.push( '> .alignfull' ); 266 elements.push( '> .alignwide' ); 267 268 var layouts = $( content ).find( elements.join( ',' ) ); 269 270 if ( 0 === sidebar.length ) { 271 return; 272 } 273 if ( 0 === layouts.length ) { 274 return; 275 } 276 277 var disabled = false; 278 279 // Get sidebar values. 280 var sidebarTop = $( sidebar ).offset().top; 281 var sidebarHeight = $( sidebar ).outerHeight( true ); 282 283 for ( let i = 0; i < $( layouts ).length; ++i ) { 284 if ( 'none' === $( layouts[ i ] ).css( 'transform' ) ) { 285 continue; 286 } 287 288 // Get layout values. 289 let layoutTop = $( layouts[ i ] ).offset().top; 290 let layoutHeight = $( layouts[ i ] ).outerHeight( true ); 291 292 // Calc points. 293 let pointTop = layoutTop - offsetTop; 294 let pointBottom = layoutTop + layoutHeight + offsetBottom; 295 296 // Detect sidebar location. 297 if ( sidebarTop + sidebarHeight >= pointTop && sidebarTop <= pointBottom ) { 298 disabled = true; 299 } 300 } 301 302 303 if ( disabled ) { 304 $( sidebar ).css( 'opacity', '0' ); 305 } else { 306 $( sidebar ).css( 'opacity', '1' ); 307 } 308 } ); 309 310 // Pagination. 311 // -----------------------------------. 312 $( '.content-area .site-main' ).each( function() { 313 314 var content = $( this ).find( '.entry-content' ); 315 var pagination = $( this ).find( '.post-prev-next-along article' ); 316 317 // Vars offset. 318 var offsetTop = -20; 319 var offsetBottom = -150; 320 321 // Search elements. 322 var elements = []; 323 324 elements.push( '> .alignfull' ); 325 326 var layouts = $( content ).find( elements.join( ',' ) ); 327 328 if ( 0 === pagination.length ) { 329 return; 330 } 331 if ( 0 === layouts.length ) { 332 return; 333 } 334 335 var disabled = false; 336 337 // Get pagination values. 338 var paginationTop = $( pagination ).offset().top; 339 var paginationHeight = $( pagination ).outerHeight( true ); 340 341 for ( let i = 0; i < $( layouts ).length; ++i ) { 342 if ( 'none' === $( layouts[ i ] ).css( 'transform' ) ) { 343 continue; 344 } 345 346 // Get layout values. 347 let layoutTop = $( layouts[ i ] ).offset().top; 348 let layoutHeight = $( layouts[ i ] ).outerHeight( true ); 349 350 // Calc points. 351 let pointTop = layoutTop - offsetTop; 352 let pointBottom = layoutTop + layoutHeight + offsetBottom; 353 354 // Detect pagination location. 355 if ( paginationTop + paginationHeight >= pointTop && paginationTop <= pointBottom ) { 356 disabled = true; 357 } 358 } 359 360 361 if ( disabled ) { 362 $( pagination ).parent().css( 'opacity', '0' ); 363 $( pagination ).parent().css( 'visibility', 'hidden' ); 364 } else { 365 $( pagination ).parent().css( 'opacity', '1' ); 366 $( pagination ).parent().css( 'visibility', 'visible' ); 367 } 368 } ); 369 370 // Ticking. 371 ticking = false; 372 }; 373 374 var requestTick = function() { 375 if ( !ticking ) { 376 window.requestAnimationFrame( update ); 377 ticking = true; 378 } 379 }; 380 381 var onProcess = function() { 382 requestTick(); 383 }; 384 385 $( window ).on( 'scroll', onProcess ); 386 $( window ).on( 'resize', onProcess ); 387 $( window ).on( 'image-load', onProcess ); 388 $( window ).on( 'post-load', onProcess ); 389 390 } )(); 391 392 /** 393 * AJAX Load More. 394 * 395 * Contains functions for AJAX Load More. 396 */ 397 398 399 /**
400 * Check if Load More is defined by the wp_localize_script 401 */ 402 if ( typeof csco_ajax_pagination !== 'undefined' ) { 403 404 $( '.post-archive' ).append( '<div class="ajax-navigation"><button class="load-more">' + csco_ajax_pagination.translation.load_more + '</button></div>' ); 405 406 var query_data = $.parseJSON( csco_ajax_pagination.query_data ), 407 infinite = $.parseJSON( query_data.infinite_load ), 408 button = $( '.ajax-navigation .load-more' ), 409 page = 2, 410 loading = false, 411 scrollHandling = { 412 allow: infinite, 413 reallow: function() { 414 scrollHandling.allow = true; 415 }, 416 delay: 400 //(milliseconds) adjust to the highest acceptable value 417 }; 418 419 } 420 421 /** 422 * Get next posts 423 */ 424 function csco_ajax_get_posts() { 425 loading = true; 426 // Set class loading. 427 button.addClass( 'loading' ); 428 var data = { 429 action: 'csco_ajax_load_more', 430 page: page, 431 posts_per_page: csco_ajax_pagination.posts_per_page, 432 query_data: csco_ajax_pagination.query_data, 433 _ajax_nonce: csco_ajax_pagination.nonce, 434 }; 435 436 // Request Url. 437 var csco_pagination_url; 438 if ( 'ajax_restapi' === csco_ajax_pagination.type ) { 439 csco_pagination_url = csco_ajax_pagination.rest_url; 440 } else { 441 csco_pagination_url = csco_ajax_pagination.url; 442 } 443 444 // Send Request. 445 $.post( csco_pagination_url, data, function( res ) { 446 if ( res.success ) { 447 448 // Get the posts. 449 var data = $( res.data.content ); 450 451 // Check if there're any posts. 452 if ( data.length ) { 453 454 var cscoAppendEnd = function() { 455 456 // WP Post Load trigger. 457 $( document.body ).trigger( 'post-load' ); 458 459 // Reinit Facebook widgets. 460 if ( $( '#fb-root' ).length && 'object' === typeof FB ) { 461 FB.XFBML.parse(); 462 } 463 464 // Remove class loading. 465 button.removeClass( 'loading' ).blur(); 466 467 // Increment a page. 468 page = page + 1; 469 470 // Set the loading state. 471 loading = false; 472 }; 473 474 // Check archive type. 475 if ( $( '.post-archive .archive-wrap' ).hasClass( 'archive-type-mixed' ) ) { 476 477 for ( var key in data ) { 478 479 if ( key % 1 !== 0 ) { 480 continue; 481 } 482 483 var last_section = $( '.archive-wrap .archive-main' ).last(); 484 485 var last_posts = $( last_section ).find( 'article' ).length; 486 var last_class = $( last_section ).attr( 'class' ); 487 var new_section = false; 488 var point_end = 4; 489 490 if ( $( '.site-content' ).hasClass( 'sidebar-disabled' ) ) { 491 point_end = 6; 492 } 493 494 if ( $( last_section ).hasClass( 'archive-full' ) ) { 495 new_section = 'archive-grid'; 496 } 497 498 if ( $( last_section ).hasClass( 'archive-grid' ) && last_posts === point_end ) { 499 new_section = 'archive-full'; 500 } 501 502 // Append new section. 503 if ( new_section ) { 504 $( '<div></div>' ).appendTo( '.archive-wrap' ) 505 .addClass( last_class ) 506 .removeClass( 'archive-full archive-grid' ) 507 .addClass( new_section ); 508 } 509 510 // Append new posts to layout. 511 $( '.archive-wrap .archive-main' ).last().append( data[ key ] ); 512 } 513 514 cscoAppendEnd(); 515 516 } else { 517 if ( $( '.post-archive .archive-main' ).hasClass( 'archive-masonry' ) ) { 518 data.imagesLoaded( function() { 519 // Append new posts to masonry layout. 520 $( '.post-archive .archive-main' ).colcade( 'append', data ); 521 522 cscoAppendEnd(); 523 } ); 524 } else { 525 $( '.post-archive .archive-main' ).append( data ); 526 527 cscoAppendEnd(); 528 } 529 } 530 } 531 532 // Remove Button on Posts End. 533 if ( res.data.posts_end || !data.length ) { 534 535 // Remove Load More button. 536 $( '.ajax-navigation' ).remove(); 537 } 538 539 } else { 540 // console.log(res); 541 } 542 } ).fail( function( xhr, textStatus, e ) { 543 // console.log(xhr.responseText); 544 } ); 545 } 546 547 /** 548 * Check if Load More is defined by the wp_localize_script 549 */ 550 if ( typeof csco_ajax_pagination !== 'undefined' ) { 551 552 // On Scroll Event. 553 $( window ).scroll( function() { 554 if ( button.length && !loading && scrollHandling.allow ) { 555 scrollHandling.allow = false; 556 setTimeout( scrollHandling.reallow, scrollHandling.delay ); 557 var offset = $( button ).offset().top - $( window ).scrollTop(); 558 if ( 4000 > offset ) { 559 csco_ajax_get_posts(); 560 } 561 } 562 } ); 563 564 // On Click Event. 565 $( 'body' ).on( 'click', '.load-more', function() { 566 if ( !loading ) { 567 csco_ajax_get_posts(); 568 } 569 } ); 570 571 } 572 573 /** 574 * AJAX Auto Load Next Post. 575 * 576 * Contains functions for AJAX Auto Load Next Post. 577 */ 578 579 580 /**
581 * Check if Load Nextpost is defined by the wp_localize_script 582 */ 583 if ( typeof csco_ajax_nextpost !== 'undefined' ) { 584 585 var objNextparent = $( '.site-primary > .site-content' ), 586 objNextsect = '.cs-nextpost-section', 587 objNextpost = null, 588 currentNTitle = document.title, 589 currentNLink = window.location.href, 590 loadingNextpost = false, 591 scrollNextpost = { 592 allow: true, 593 reallow: function() { 594 scrollNextpost.allow = true; 595 }, 596 delay: 400 //(milliseconds) adjust to the highest acceptable value 597 }; 598 599 // Init. 600 if ( csco_ajax_nextpost.next_post ) { 601 $( objNextparent ).after( '<div class="cs-nextpost-inner"></div>' ); 602 603 objNextpost = $( '.cs-nextpost-inner' ); 604 } 605 } 606 607 /** 608 * Get next post 609 */ 610 function csco_ajax_get_nextpost() { 611 loadingNextpost = true; 612 613 // Set class loading. 614 var data = { 615 action: 'csco_ajax_load_nextpost', 616 not_in: csco_ajax_nextpost.not_in, 617 current_user: csco_ajax_nextpost.current_user, 618 nonce: csco_ajax_nextpost.nonce, 619 next_post: csco_ajax_nextpost.next_post, 620 }; 621 622 // Request Url. 623 var csco_ajax_nextpost_url; 624 if ( 'ajax_restapi' === csco_ajax_nextpost.type ) { 625 csco_ajax_nextpost_url = csco_ajax_nextpost.rest_url; 626 } else { 627 csco_ajax_nextpost_url = csco_ajax_nextpost.url; 628 } 629 630 // Send Request. 631 $.post( csco_ajax_nextpost_url, data, function( res ) { 632 633 csco_ajax_nextpost.next_post = false; 634 635 if ( res.success ) { 636 637 // Get the posts. 638 var data = $( res.data.content ); 639 640 // Check if there're any posts. 641 if ( data.length ) { 642 // Set the loading state. 643 loadingNextpost = false; 644 645 // Set not_in. 646 csco_ajax_nextpost.not_in = res.data.not_in; 647 648 // Set next data. 649 csco_ajax_nextpost.next_post = res.data.next_post; 650 651 // Remove loader. 652 $( objNextpost ).siblings( '.cs-nextpost-loading' ).remove(); 653 654 // Append new post. 655 $( objNextpost ).append( data ); 656 657 // Reinit facebook. 658 if ( $( '#fb-root' ).length && 'object' === typeof FB ) { 659 FB.XFBML.parse(); 660 } 661 662 $( document.body ).trigger( 'post-load' ); 663 } 664 } else { 665 // console.log(res); 666 } 667 } ).fail( function( xhr, textStatus, e ) { 668 // console.log(xhr.responseText); 669 } ); 670 } 671 672 /** 673 * Check if Load Nextpost is defined by the wp_localize_script 674 */ 675 if ( typeof csco_ajax_nextpost !== 'undefined' ) { 676 677 // On Scroll Event. 678 $( window ).scroll( function() { 679 var scrollTop = $( window ).scrollTop(); 680 681 // Init nextpost. 682 if ( csco_ajax_nextpost.next_post ) { 683 684 if ( objNextpost.length && !loadingNextpost && scrollNextpost.allow ) { 685 scrollNextpost.allow = false; 686 setTimeout( scrollNextpost.reallow, scrollNextpost.delay ); 687 // Calc current offset. 688 let offset = objNextpost.offset().top + objNextpost.innerHeight() - scrollTop; 689 // Load nextpost. 690 if ( 4000 > offset ) { 691 $( objNextpost ).after( '<div class="cs-nextpost-loading"></div>' ); 692 693 csco_ajax_get_nextpost(); 694 } 695 } 696 } 697 698 // Reset browser data link. 699 let objFirst = $( objNextsect ).first(); 700 701 if ( objFirst.length ) { 702 let firstTop = $( objFirst ).offset().top; 703 // If there has been a change. 704 if ( scrollTop < firstTop && window.location.href !== currentNLink ) { 705 document.title = currentNTitle; 706 window.history.pushState( null, currentNTitle, currentNLink ); 707 } 708 } 709 710 // Set browser data link. 711 $( objNextsect ).each( function( index, elem ) { 712 713 let elemTop = $( elem ).offset().top; 714 let elemHeight = $( elem ).innerHeight(); 715 716 if ( scrollTop > elemTop && scrollTop < elemTop + elemHeight ) { 717 // If there has been a change. 718 if ( window.location.href !== $( elem ).data( 'url' ) ) { 719 // New title. 720 document.title = $( elem ).data( 'title' ); 721 // New link. 722 window.history.pushState( null, $( elem ).data( 'title' ), $( elem ).data( 'url' ) ); 723 // Google Analytics. 724 if ( typeof gtag === 'function' && typeof window.gaData === 'object' ) { 725 726 var trackingId = Object.keys( window.gaData )[ 0 ]; 727 if ( trackingId ) { 728 gtag( 'config', trackingId, { 729 'page_title': $( elem ).data( 'title' ), 730 'page_location': $( elem ).data( 'url' ) 731 } ); 732 733 gtag( 'event', 'page_view', { 'send_to': trackingId } ); 734 } 735 } 736 } 737 } 738 } ); 739 } ); 740 } 741 742 /** 743 * Masonry Widget Area 744 */ 745 746 function initMasonrySidebar() { 747 748 /** 749 * Masonry Options 750 */ 751 var masonrySidebar = $( '.sidebar-area' ), 752 masonrySidebarOptions = { 753 columns: '.sidebar', 754 items: '.widget' 755 }; 756 757 // Set Masonry. 758 $( masonrySidebar ).imagesLoaded( function() { 759 $( masonrySidebar ).colcade( masonrySidebarOptions ); 760 } ); 761 } 762 763 $( document ).ready( function() { 764 initMasonrySidebar(); 765 } ); 766 767 /** 768 * Masonry Archive 769 */ 770 771 function initMasonry() { 772 773 var masonryArchive = $( '.archive-masonry' ), 774 masonryArchiveOptions = { 775 columns: '.archive-col', 776 items: 'article'
777 }; 778 779 $( masonryArchive ).imagesLoaded( function() { 780 $( masonryArchive ).colcade( masonryArchiveOptions ); 781 } ); 782 } 783 784 $( document ).ready( function() { 785 initMasonry(); 786 } ); 787 788 /* 789 * Load Mega Menu Posts 790 */ 791 function cscoLoadMenuPosts( menuItem ) { 792 var dataCat = menuItem.children( 'a' ).data( 'cat' ), 793 dataType = menuItem.children( 'a' ).data( 'type' ), 794 dataNumberposts = menuItem.children( 'a' ).data( 'numberposts' ), 795 menuContainer, 796 postsContainer; 797 798 // Containers. 799 if ( menuItem.hasClass( 'cs-mega-menu-has-category' ) ) { 800 menuContainer = menuItem; 801 postsContainer = menuContainer.find( '.cs-mm-posts' ); 802 } else { 803 menuContainer = menuItem.closest( '.sub-menu' ); 804 postsContainer = menuContainer.find( '.cs-mm-posts[data-cat="' + dataCat + '"]' ); 805 } 806 807 // Set Active. 808 menuContainer.find( '.menu-item, .cs-mm-posts' ).removeClass( 'active-item' ); 809 menuItem.addClass( 'active-item' ); 810 811 if ( postsContainer ) { 812 postsContainer.addClass( 'active-item' ); 813 } 814 815 // Check Loading. 816 if ( menuItem.hasClass( 'cs-mm-loading' ) || menuItem.hasClass( 'cs-mm-loaded' ) ) { 817 return false; 818 } 819 820 // Check Category. 821 if ( !dataCat || typeof dataCat === 'undefined' ) { 822 return false; 823 } 824 825 // Check Container. 826 if ( !postsContainer || typeof postsContainer === 'undefined' ) { 827 return false; 828 } 829 830 // Create Data. 831 var data = { 832 'cat': dataCat, 833 'type': dataType, 834 'per_page': dataNumberposts 835 }; 836 837 // Get Results. 838 $.ajax( { 839 url: csco_mega_menu.rest_url, 840 type: 'GET', 841 data: data, 842 global: false, 843 async: true, 844 beforeSend: function() { 845 menuItem.addClass( 'cs-mm-loading' ); 846 postsContainer.addClass( 'cs-mm-loading' ); 847 }, 848 success: function( res ) { 849 if ( res.status && 'success' === res.status ) { 850 851 // Set the loaded state. 852 menuItem.addClass( 'cs-mm-loaded' ); 853 postsContainer.addClass( 'cs-mm-loaded' ); 854 855 // Check if there're any posts. 856 if ( res.content && res.content.length ) { 857 858 $( res.content ).imagesLoaded( function() { 859 860 // Append Data. 861 postsContainer.html( res.content ); 862 } ); 863 } 864 } 865 }, 866 complete: function() { 867 menuItem.removeClass( 'cs-mm-loading' ); 868 postsContainer.removeClass( 'cs-mm-loading' ); 869 } 870 } ); 871 } 872 873 /* 874 * Get First Tab 875 */ 876 function cscoGetFirstTab( container ) { 877 var firstTab = false; 878 879 container.find( '.cs-mega-menu-child' ).each( function( index, el ) { 880 if ( $( el ).hasClass( 'menu-item-object-category' ) ) { 881 firstTab = $( el ); 882 return false; 883 } 884 if ( $( el ).hasClass( 'menu-item-object-post_tag' ) ) { 885 firstTab = $( el ); 886 return false; 887 } 888 } ); 889 890 return firstTab; 891 } 892 893 /* 894 * Menu on document ready 895 */ 896 $( document ).ready( function() { 897 898 /* 899 * Get Menu Posts on Hover 900 */ 901 $( '.navbar-nav .menu-item.cs-mega-menu-has-category, .navbar-nav .menu-item.cs-mega-menu-child' ).on( 'mouseenter', function() { 902 cscoLoadMenuPosts( $( this ) ); 903 } ); 904 905 /* 906 * Load First Tab on Mega Menu Hover 907 */ 908 $( '.navbar-nav .menu-item.cs-mega-menu-has-categories' ).on( 'mouseenter', function() { 909 var tab = cscoGetFirstTab( $( this ) ); 910 911 if ( tab ) { 912 cscoLoadMenuPosts( tab ); 913 } 914 } ); 915 } ); 916 917 /* 918 * Load First Tab on Navbar Ready. 919 */ 920 $( document, '.navbar-nav' ).ready( function() { 921 var tab = false; 922 923 // Autoload First Tab. 924 $( '.navbar-nav .menu-item.cs-mega-menu-has-categories' ).each( function( index, el ) { 925 tab = cscoGetFirstTab( $( this ) ); 926 if ( tab ) { 927 cscoLoadMenuPosts( tab ); 928 } 929 } ); 930 931 // Autoload Category. 932 $( '.navbar-nav .menu-item.cs-mega-menu-has-category' ).each( function( index, el ) { 933 cscoLoadMenuPosts( $( this ) ); 934 } ); 935 } ); 936 937 // 938 // Responsive Navigation 939 // 940 941 $.fn.responsiveNav = function() { 942 this.removeClass( 'menu-item-expanded' ); 943 if ( this.prev().hasClass( 'submenu-visible' ) ) {
944 this.prev().removeClass( 'submenu-visible' ).slideUp( 350 ); 945 this.parent().removeClass( 'menu-item-expanded' ); 946 } else { 947 this.parent().parent().find( '.menu-item .sub-menu' ).removeClass( 'submenu-visible' ).slideUp( 350 ); 948 this.parent().parent().find( '.menu-item-expanded' ).removeClass( 'menu-item-expanded' ); 949 this.prev().toggleClass( 'submenu-visible' ).hide().slideToggle( 350 ); 950 this.parent().toggleClass( 'menu-item-expanded' ); 951 } 952 }; 953 954 // 955 // Navigation Menu Widget 956 // 957 958 $( document ).ready( function( e ) { 959 960 $( '.widget_nav_menu .menu-item-has-children' ).each( function( e ) { 961 962 // Add a caret. 963 $( this ).append( '<span></span>' ); 964 965 // Fire responsiveNav() when clicking a caret. 966 $( '> span', this ).on( 'click', function( e ) { 967 e.preventDefault(); 968 $( this ).responsiveNav(); 969 } ); 970 971 // Fire responsiveNav() when clicking a parent item with # href attribute. 972 if ( '#' === $( '> a', this ).attr( 'href' ) ) { 973 $( '> a', this ).on( 'click', function( e ) { 974 e.preventDefault(); 975 $( this ).next().next().responsiveNav(); 976 } ); 977 } 978 979 } ); 980 981 } ); 982 983 /* 984 * ---------------------------------------------------------------------------- 985 * Navigation 986 */ 987 988 var cscoNavigation = {}; 989 990 ( function() { 991 var $this; 992 993 cscoNavigation = { 994 sScrollAllow: false, 995 sInFirst: true, 996 sInterval: 0, 997 sPrevious: 0, 998 sDirection: 0, 999 1000 loadStickyOffset: 0, 1001 loadAdminBar: false, 1002 1003 Sticky: $( 'body' ).hasClass( 'navbar-sticky-enabled' ), 1004 StickyUp: $( 'body' ).hasClass( 'navbar-smart-enabled' ), 1005 StickyNav: $( '.site-header .navbar-primary' ), 1006 StickyHeader: $( '.site-header' ), 1007 StickyOffsetType: 'auto', 1008 StickyOffset: 0, 1009 StickyOffsetFull: 0, 1010 1011 /* 1012 * Initialize 1013 */ 1014 init: function( e ) { 1015 $this = cscoNavigation; 1016 1017 // Init events. 1018 $this.events( e ); 1019 }, 1020 1021 /* 1022 * Events 1023 */ 1024 events: function( e ) { 1025 // DOM Load 1026 window.addEventListener( 'load', function( e ) { 1027 $this.stickyInit( e ); 1028 $this.smartLevels( e ); 1029 $this.adaptTablet( e ); 1030 } ); 1031 // Resize 1032 window.addEventListener( 'resize', function( e ) { 1033 $this.stickyInit( e ); 1034 $this.smartLevels( e ); 1035 $this.adaptTablet( e ); 1036 } ); 1037 // Scroll 1038 window.addEventListener( 'scroll', function( e ) { 1039 window.requestAnimationFrame( $this.stickyScroll ); 1040 } ); 1041 1042 // Add dynamic search support. 1043 $( document ).on( 'animate-search', function( e ) { 1044 $this.animateSearch( e ); 1045 } ); 1046 $( document ).on( 'animate-search-start', function( e ) { 1047 $this.animateSearchStart( e ); 1048 } ); 1049 $( document ).on( 'animate-search-done', function( e ) { 1050 $this.animateSearchDone( e ); 1051 } ); 1052 }, 1053 1054 /* 1055 * Init nav bar sticky 1056 */ 1057 stickyInit: function( e ) { 1058 1059 if ( !$this.Sticky ) { 1060 return; 1061 } 1062 1063 $this.sScrollAllow = false; 1064 1065 // Calc sticky offset. 1066 if ( $this.StickyOffsetType !== 'size' ) { 1067 1068 var calcbar = 0; 1069 var wpadminbar = 0; 1070 1071 if ( $( '#wpadminbar' ).length > 0 ) { 1072 calcbar = $( '#wpadminbar' ).outerHeight(); 1073 1074 wpadminbar = calcbar; 1075 1076 if ( 'resize' !== e.type ) { 1077 $this.loadAdminBar = wpadminbar; 1078 } 1079 1080 if ( 'absolute' === $( '#wpadminbar' ).css( 'position' ) ) { 1081 wpadminbar = 0; 1082 1083 if ( 'resize' !== e.type ) { 1084 $this.loadAdminBar = 0; 1085 } 1086 } 1087 } 1088 1089 // Calc outside header. 1090 $this.StickyOffsetFull = $this.StickyHeader.outerHeight(); 1091 1092 // Calc on load offset top. 1093 var elOffset = $this.StickyNav.not( '.sticky-nav' ).offset(); 1094 1095 if ( elOffset && !$this.StickyNav.hasClass( '.sticky-nav' ) ) { 1096 1097 $this.StickyOffset = elOffset.top; 1098 1099 $this.loadStickyOffset = elOffset.top; 1100 } else { 1101 $this.StickyOffset = $this.loadStickyOffset; 1102 } 1103 1104 // Consider the size of the wpadminbar. 1105 if ( 32 === $this.loadAdminBar ) { 1106 if ( 46 === calcbar ) { 1107 $this.StickyOffset = $this.StickyOffset - wpadminbar + 14; 1108 } else { 1109 $this.StickyOffset = $this.StickyOffset - wpadminbar; 1110 } 1111 } else if ( 46 === $this.loadAdminBar || 0 === $this.loadAdminBar ) { 1112 1113 if ( 32 === calcbar ) { 1114 $this.StickyOffset = $this.StickyOffset - wpadminbar - 14; 1115 } else { 1116 $this.StickyOffset = $this.StickyOffset - wpadminbar; 1117 } 1118 } 1119 } 1120 1121 // Nav Height. 1122 var navHeight = $this.StickyNav.outerHeight(); 1123 1124 // Set the min-height default of the header. 1125 $this.StickyHeader.data( 'min-height', $this.StickyOffsetFull - navHeight ); 1126 1127 // Document ready. 1128 if ( 'resize' !== e.type ) { 1129 1130 // Add nav dummy. 1131 $this.StickyNav.after( '<div class="navbar-dummy"></div>' );
1132 $this.StickyHeader.find( '.navbar-dummy' ).height( navHeight ); 1133 1134 // Set type slide. 1135 if ( $this.StickyUp ) { 1136 $this.StickyHeader.addClass( 'sticky-type-slide' ); 1137 } 1138 } 1139 1140 // Allow. 1141 $this.sScrollAllow = true; 1142 }, 1143 1144 /* 1145 * Make nav bar sticky 1146 */ 1147 stickyScroll: function( e ) { 1148 if ( !$this.sScrollAllow ) { 1149 return; 1150 } 1151 1152 var scrollCurrent = $( window ).scrollTop(); 1153 1154 if ( $this.StickyUp ) { 1155 1156 if ( scrollCurrent > $this.StickyOffsetFull ) { 1157 $this.StickyNav.addClass( 'sticky-nav' ); 1158 } 1159 1160 if ( scrollCurrent <= $this.StickyOffset ) { 1161 $this.StickyNav.removeClass( 'sticky-nav' ); 1162 } 1163 1164 // Set scroll temporary vars. 1165 if ( scrollCurrent > $this.sPrevious ) { 1166 $this.sInterval = 0; 1167 $this.sDirection = 'down'; 1168 1169 $this.StickyNav.addClass( 'sticky-down' ).removeClass( 'sticky-up' ); 1170 } else { 1171 $this.sInterval += $this.sPrevious - scrollCurrent; 1172 $this.sDirection = 'up'; 1173 1174 $this.StickyNav.addClass( 'sticky-up' ).removeClass( 'sticky-down' ); 1175 } 1176 1177 // Сonditions. 1178 if ( $this.sInterval > 150 && 'up' === $this.sDirection ) { 1179 $this.StickyNav.addClass( 'sticky-nav-slide-visible' ); 1180 1181 $( document ).trigger( 'sticky-nav-visible' ); 1182 } else { 1183 $this.StickyNav.removeClass( 'sticky-nav-slide-visible' ); 1184 1185 $( document ).trigger( 'sticky-nav-hide' ); 1186 } 1187 1188 if ( scrollCurrent > $this.StickyOffsetFull + 150 ) { 1189 $this.StickyNav.addClass( 'sticky-nav-slide' ); 1190 } else { 1191 $this.StickyNav.removeClass( 'sticky-nav-slide' ); 1192 } 1193 1194 // Show onload document. 1195 if ( $this.sInFirst && scrollCurrent > $this.StickyOffsetFull + 150 ) { 1196 $this.StickyNav.addClass( ' sticky-nav-slide-visible sticky-up' ); 1197 $this.StickyNav.addClass( 'sticky-nav-slide' ); 1198 1199 $( document ).trigger( 'sticky-nav-visible' ); 1200 1201 $this.sDirection = 'up'; 1202 $this.sInterval = 151; 1203 $this.sInFirst = false; 1204 } 1205 } else { 1206 // Сonditions. 1207 if ( scrollCurrent > $this.StickyOffset ) { 1208 $this.StickyNav.addClass( 'sticky-nav' ); 1209 1210 $( document ).trigger( 'sticky-nav-visible' ); 1211 } else { 1212 $this.StickyNav.removeClass( 'sticky-nav' ); 1213 $( document ).trigger( 'sticky-nav-hide' ); 1214 } 1215 } 1216 1217 $this.sPrevious = scrollCurrent; 1218 }, 1219 1220 /* 1221 * Dynamic search support 1222 */ 1223 animateSearch: function( e ) { 1224 var minHeightMain = $this.StickyHeader.data( 'min-height' ); 1225 var navHeight = $this.StickyNav.outerHeight(); 1226 1227 $this.StickyOffsetFull = ( minHeightMain + navHeight ); 1228 1229 $this.StickyHeader.find( '.navbar-dummy' ).height( navHeight ); 1230 }, 1231 1232 /* 1233 * Start: Dynamic search support 1234 */ 1235 animateSearchStart: function( e ) { 1236 $this.sScrollAllow = false; 1237 }, 1238 1239 /* 1240 * Done: Dynamic search support 1241 */ 1242 animateSearchDone: function( e ) { 1243 var minHeightMain = $this.StickyHeader.data( 'min-height' ); 1244 var navHeight = $this.StickyNav.outerHeight(); 1245 1246 $this.sScrollAllow = true; 1247 1248 $this.sPrevious = $this.sPrevious + ( navHeight - minHeightMain ); 1249 }, 1250 1251 /* 1252 * Smart multi-Level menu 1253 */ 1254 smartLevels: function( e ) { 1255 1256 var windowWidth = $( window ).width(); 1257 1258 // Reset Calc. 1259 $( '.navbar-nav li' ).removeClass( 'cs-mm-level' ); 1260 $( '.navbar-nav li' ).removeClass( 'cs-mm-position-left cs-mm-position-right' ); 1261 $( '.navbar-nav li .sub-menu' ).removeClass( 'cs-mm-position-init' ); 1262 1263 // Set Settings. 1264 $( '.navbar-nav > li.menu-item' ).not( '.cs-mega-menu' ).each( function( index, parent ) { 1265 var position = 'cs-mm-position-right'; 1266 var objPrevWidth = 0; 1267 1268 $( parent ).find( '.sub-menu' ).each( function( index, el ) { 1269 1270 // Reset child levels. 1271 $( el ).parent().next( 'li' ).addClass( 'cs-mm-level' ); 1272 1273 if ( $( el ).parent().hasClass( 'cs-mm-level' ) ) { 1274 1275 $( el ).parent().removeClass( 'cs-mm-level' ); 1276 1277 position = 'cs-mm-position-right'; 1278 objPrevWidth = 0; 1279 } 1280 1281 // Find out position items. 1282 var offset = $( el ).offset(); 1283 var objOffset = offset.left; 1284 1285 if ( 'cs-mm-position-right' === position && $( el ).outerWidth() + objOffset > windowWidth ) { 1286 position = 'cs-mm-position-left'; 1287 } 1288 1289 if ( 'cs-mm-position-left' === position && objOffset - ( $( el ).outerWidth() + objPrevWidth ) < 0 ) { 1290 position = 'cs-mm-position-right'; 1291 } 1292 1293 objPrevWidth = $( el ).outerWidth(); 1294 1295 $( el ).addClass( 'cs-mm-position-init' ).parent().addClass( position ); 1296 } ); 1297 1298 } ); 1299 }, 1300 1301 /* 1302 * Adapting nav bar for tablet 1303 */ 1304 adaptTablet: function( e ) { 1305 // Click outside. 1306 $( document ).on( 'touchstart', function( e ) { 1307 1308 if ( !$( e.target ).closest( '.navbar-nav' ).length ) { 1309 $( '.navbar-nav .menu-item-has-children' ).removeClass( 'submenu-visible' ); 1310 } else { 1311 $( e.target ).parents( '.menu-item' ).siblings().find( '.menu-item' ).removeClass( 'submenu-visible' ); 1312 $( e.target ).parents( '.menu-item' ).siblings().closest( '.menu-item' ).removeClass( 'submenu-visible' ); 1313 } 1314 } ); 1315 1316 $( '.navbar-nav .menu-item-has-children' ).each( function( e ) { 1317 1318 // Reset class. 1319 $( this ).removeClass( 'submenu-visible' ); 1320 1321 // Remove expanded. 1322 $( this ).find( '> a > .expanded' ).remove(); 1323 1324 // Add a caret. 1325 if ( 'ontouchstart' in document.documentElement ) { 1326 $( this ).find( '> a' ).append( '<span class="expanded"></span>' ); 1327 } 1328 1329 // Check touch device. 1330 $( this ).addClass( 'ontouchstart' in document.documentElement ? 'touch-device' : '' ); 1331 1332 $( '> a .expanded', this ).on( 'touchstart', function( e ) { 1333 e.preventDefault(); 1334 1335 $( this ).closest( '.menu-item-has-children' ).toggleClass( 'submenu-visible' ); 1336 } ); 1337 1338 1339 if ( '#' === $( '> a', this ).attr( 'href' ) ) { 1340 $( '> a', this ).on( 'touchstart', function( e ) { 1341 e.preventDefault(); 1342 1343 if ( !$( e.target ).hasClass( 'expanded' ) ) { 1344 $( this ).closest( '.menu-item-has-children' ).toggleClass( 'submenu-visible' ); 1345 } 1346 } ); 1347 } 1348 } ); 1349 } 1350 }; 1351 1352 } )(); 1353 1354 // Initialize. 1355 cscoNavigation.init(); 1356 1357 // 1358 // Mobile Menu 1359 // 1360 1361 $( '.toggle-offcanvas, .site-overlay' ).on( 'click', function( e ) { 1362 e.preventDefault(); 1363 1364 // Transition. 1365 if ( !$( 'body' ).hasClass( 'offcanvas-active' ) ) { 1366 $( 'body' ).addClass( 'offcanvas-transition' ); 1367 } else { 1368 setTimeout( function() { 1369 $( 'body' ).removeClass( 'offcanvas-transition' ); 1370 }, 400 ); 1371 } 1372 1373 // Toogle offcanvas. 1374 $( 'body' ).toggleClass( 'offcanvas-active' ); 1375 } ); 1376 1377 ( function() { 1378 var viewport = $( window ).height(); 1379 var lastScrollY = 0; 1380 var ticking = false; 1381 var offset = 200; 1382 1383 var update = function() { 1384 var article = $( '.single-post .site-main > article' ); 1385 1386 if ( 1 === article.length ) { 1387 let articleHeight = $( article ).innerHeight(); 1388 1389 // Pagination points. 1390 let topPoint = $( article ).offset().top; 1391 let bottomPoint = topPoint + articleHeight + offset; 1392 1393 if ( lastScrollY > topPoint && lastScrollY + viewport < bottomPoint ) { 1394 $( '.post-prev-next-along' ).addClass( 'pagination-visible' ); 1395 } else { 1396 $( '.post-prev-next-along' ).removeClass( 'pagination-visible' ); 1397 } 1398 } 1399 1400 ticking = false; 1401 }; 1402 1403 var requestTick = function() { 1404 if ( !ticking ) { 1405 window.requestAnimationFrame( update ); 1406 ticking = true; 1407 } 1408 }; 1409 1410 var onProcess = function() { 1411 lastScrollY = window.scrollY; 1412 1413 requestTick(); 1414 }; 1415 1416 $( window ).on( 'scroll', onProcess ); 1417 $( window ).on( 'resize', onProcess ); 1418 $( window ).on( 'slider-refresh', onProcess ); 1419 1420 } )(); 1421 1422 /** 1423 * Responsive Embeds 1424 */ 1425 1426 ( function() { 1427 /** 1428 * Add max-width & max-height to <iframe> elements, depending on their width & height props. 1429 */ 1430 function initResponsiveEmbeds() { 1431 var proportion, parentWidth; 1432 1433 // Loop iframe elements. 1434 $( '.entry-content' ).find( 'iframe' ).each( function( index, iframe ) { 1435 // Don't handle if the parent automatically resizes itself.
1436 if ( $( iframe ).closest( 'div' ).is( '[data-video-start], [data-video-end]' ) ) { 1437 return; 1438 } 1439 // Only continue if the iframe has a width & height defined. 1440 if ( iframe.width && iframe.height ) { 1441 // Calculate the proportion/ratio based on the width & height. 1442 proportion = parseFloat( iframe.width ) / parseFloat( iframe.height ); 1443 // Get the parent element's width. 1444 parentWidth = parseFloat( window.getComputedStyle( iframe.parentElement, null ).width.replace( 'px', '' ) ); 1445 // Set the max-width & height. 1446 iframe.style.maxWidth = '100%'; 1447 iframe.style.maxHeight = Math.round( parentWidth / proportion ).toString() + 'px'; 1448 } 1449 } ); 1450 } 1451 1452 // Document ready. 1453 $( document ).ready( function() { 1454 initResponsiveEmbeds(); 1455 } ); 1456 1457 // Document resize. 1458 $( window ).on( 'resize', function() { 1459 initResponsiveEmbeds(); 1460 } ); 1461 1462 // Post load. 1463 $( 'body' ).on( 'post-load', function() { 1464 initResponsiveEmbeds(); 1465 } ); 1466 1467 // Run on initial load. 1468 initResponsiveEmbeds(); 1469 } )(); 1470 1471 /** 1472 * Site Search 1473 */ 1474 1475 function triggerSearch() { 1476 $( document ).trigger( 'animate-search-start' ); 1477 1478 // Start repeats at intervals of 25 milliseconds. 1479 var timerSearchId = setInterval( function() { 1480 $( document ).trigger( 'animate-search' ); 1481 }, 25 ); 1482 1483 // After 400 milliseconds sec stop replays. 1484 setTimeout( function() { 1485 clearInterval( timerSearchId ); 1486 }, 399 ); 1487 1488 setTimeout( function() { 1489 $( document ).trigger( 'animate-search-done' ); 1490 }, 400 ); 1491 } 1492 1493 $( '.toggle-search' ).on( 'click', function( event ) { 1494 1495 event.preventDefault(); 1496 1497 var container = $( '#search' ), 1498 field = $( 'input[type="search"]', container ); 1499 1500 // Toggle class on search button. 1501 $( this ).toggleClass( 'toggle-close' ); 1502 1503 // Add class to container. 1504 container.toggleClass( 'search-open' ); 1505 1506 // Slide toggle the container. 1507 triggerSearch(); 1508 1509 // Focus on / blur input field. 1510 if ( container.hasClass( 'search-open' ) ) { 1511 field.focus(); 1512 } else { 1513 field.blur(); 1514 } 1515 } ); 1516 1517 $( '#search, .search-close' ).on( 'click keyup', function( event ) { 1518 // Fire only when pressing Escape or clicking the .search-toggle button. 1519 if ( event.target.className === 'search-close' || event.keyCode === 27 ) { 1520 event.preventDefault(); 1521 // Toggle class on search button. 1522 $( '.toggle-search' ).removeClass( 'toggle-close' ); 1523 1524 // Remove class from container. 1525 $( '#search' ).removeClass( 'search-open' ); 1526 1527 $( '#search input[type="search"]' ).blur(); 1528 // Slide toggle the container. 1529 triggerSearch(); 1530 } 1531 } ); 1532 1533 /** 1534 * Sticky Sidebar 1535 */ 1536 1537 var stickyElements = []; 1538 1539 stickyElements.push( '.sticky-sidebar-enabled.stick-to-top .sidebar-1' ); 1540 stickyElements.push( '.sticky-sidebar-enabled.stick-last .sidebar .widget:last-child' ); 1541 1542 $( document ).ready( function() { 1543 1544 // Sticky sidebar for mozilla. 1545 if ( navigator.userAgent.toLowerCase().indexOf( 'firefox' ) > -1 ) { 1546 stickyElements.push( '.sticky-sidebar-enabled.stick-to-bottom .sidebar-1' ); 1547 } 1548 1549 // Join elements. 1550 stickyElements = stickyElements.join( ',' ); 1551 1552 // Sticky nav visible. 1553 $( document ).on( 'sticky-nav-visible', function() { 1554 var navBarHeight = $( '.navbar-primary' ).innerHeight(); 1555 1556 $( stickyElements ).css( 'top', 32 + navBarHeight + 'px' ); 1557 } ); 1558 1559 // Sticky nav hide. 1560 $( document ).on( 'sticky-nav-hide', function() { 1561 $( stickyElements ).css( 'top', 32 + 'px' ); 1562 } ); 1563 1564 } ); 1565 1566 ( function() { 1567 var initAPI = false; 1568 var process = false; 1569 var contex = []; 1570 var players = []; 1571 var attrs = []; 1572 1573 // Create deferred object 1574 var YTdeferred = $.Deferred(); 1575 window.onYouTubePlayerAPIReady = function() { 1576 // Resolve when youtube callback is called 1577 // passing YT as a parameter. 1578 YTdeferred.resolve( window.YT ); 1579 }; 1580 1581 // Embedding youtube iframe api. 1582 function embedYoutubeAPI() { 1583 var tag = document.createElement( 'script' ); 1584 tag.src = 'https://www.youtube.com/iframe_api'; 1585 var firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ]; 1586 firstScriptTag.parentNode.insertBefore( tag, firstScriptTag ); 1587 } 1588 1589 // Video rescale.
1590 function rescaleVideoBackground() { 1591 $( '.cs-video-init' ).each( function() { 1592 let w = $( this ).parent().width(); 1593 let h = $( this ).parent().height(); 1594 1595 var hideControl = 400; 1596 1597 let id = $( this ).attr( 'data-uid' ); 1598 1599 if ( w / h > 16 / 9 ) { 1600 players[ id ].setSize( w, w / 16 * 9 + hideControl ); 1601 } else { 1602 players[ id ].setSize( h / 9 * 16, h + hideControl ); 1603 } 1604 } ); 1605 } 1606 1607 // Init video background. 1608 function initVideoBackground() { 1609 1610 if ( process ) { 1611 return; 1612 } 1613 1614 process = true; 1615 1616 // Smart init API. 1617 if ( !initAPI ) { 1618 let elements = $( '.cs-video-wrapper[data-video-id]' ); 1619 1620 if ( elements.length ) { 1621 embedYoutubeAPI(); 1622 1623 initAPI = true; 1624 } 1625 } 1626 1627 if ( !initAPI ) { 1628 process = false; 1629 1630 return; 1631 } 1632 1633 // Whenever youtube callback was called = deferred resolved 1634 // your custom function will be executed with YT as an argument. 1635 YTdeferred.done( function( YT ) { 1636 1637 $( '.cs-video-inner' ).each( function() { 1638 1639 // The state. 1640 var isInit = $( this ).hasClass( 'cs-video-init' ); 1641 1642 var id = null; 1643 1644 // Generate unique ID. 1645 if ( !isInit ) { 1646 id = Math.random().toString( 36 ).substr( 2, 9 ); 1647 } else { 1648 id = $( this ).attr( 'data-uid' ); 1649 } 1650 1651 // Create contex. 1652 contex[ id ] = this; 1653 1654 // The actived. 1655 var isActive = $( contex[ id ] ).hasClass( 'active' ); 1656 1657 // The monitor. 1658 var isInView = $( contex[ id ] ).isInViewport(); 1659 1660 // Initialization. 1661 if ( isInView && !isInit ) { 1662 // Add init class. 1663 $( contex[ id ] ).addClass( 'cs-video-init' ); 1664 1665 // Add unique ID. 1666 $( contex[ id ] ).attr( 'data-uid', id ); 1667 1668 // Get video attrs. 1669 let videoID = $( contex[ id ] ).parent().data( 'video-id' ); 1670 let videoStart = $( contex[ id ] ).parent().data( 'video-start' ); 1671 let videoEnd = $( contex[ id ] ).parent().data( 'video-end' ); 1672 1673 // Check video id. 1674 if ( typeof videoID === 'undefined' || !videoID ) { 1675 return; 1676 } 1677 1678 // Video attrs. 1679 attrs[ id ] = { 1680 'videoId': videoID, 1681 'startSeconds': videoStart, 1682 'endSeconds': videoEnd, 1683 'suggestedQuality': 'hd720' 1684 }; 1685 1686 // Creating a player. 1687 players[ id ] = new YT.Player( contex[ id ], { 1688 playerVars: { 1689 autoplay: 0, 1690 autohide: 1, 1691 modestbranding: 1, 1692 rel: 0, 1693 showinfo: 0, 1694 controls: 0, 1695 disablekb: 1, 1696 enablejsapi: 0, 1697 iv_load_policy: 3, 1698 playsinline: 1, 1699 loop: 1, 1700 }, 1701 events: { 1702 'onReady': function() { 1703 players[ id ].loadVideoById( attrs[ id ] ); 1704 players[ id ].mute(); 1705 }, 1706 'onStateChange': function( e ) { 1707 if ( e.data === 1 ) { 1708 $( contex[ id ] ).parents( '.cs-overlay, .cs-video-wrap' ).addClass( 'cs-video-bg-init' ); 1709 $( contex[ id ] ).addClass( 'active' ); 1710 } else if ( e.data === 0 ) { 1711 players[ id ].seekTo( attrs[ id ].startSeconds ); 1712 } 1713 } 1714 } 1715 } ); 1716 rescaleVideoBackground(); 1717 } 1718 1719 // Pause and play. 1720 let control = $( contex[ id ] ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-player-state' ); 1721 1722 if ( isActive && isInit && !$( control ).hasClass( 'cs-player-upause' ) ) { 1723 1724 if ( isInView && $( control ).hasClass( 'cs-player-play' ) ) { 1725 // Change icon. 1726 $( control ).removeClass( 'cs-player-play' ).addClass( 'cs-player-pause' ); 1727 // Pause video. 1728 players[ id ].playVideo(); 1729 } 1730 1731 if ( !isInView && $( control ).hasClass( 'cs-player-pause' ) ) { 1732 // Change icon. 1733 $( control ).removeClass( 'cs-player-pause' ).addClass( 'cs-player-play' ); 1734 // Pause video. 1735 players[ id ].pauseVideo(); 1736 } 1737 } 1738 } ); 1739 } ); 1740 1741 process = false; 1742 } 1743 1744 // State Control. 1745 $( document ).on( 'click', '.cs-player-state', function() { 1746 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1747 1748 let id = $( container ).attr( 'data-uid' ); 1749 1750 $( this ).toggleClass( 'cs-player-pause cs-player-play' ); 1751 1752 if ( $( this ).hasClass( 'cs-player-pause' ) ) { 1753 $( this ).removeClass( 'cs-player-upause' ); 1754 players[ id ].playVideo(); 1755 } else { 1756 $( this ).addClass( 'cs-player-upause' ); 1757 players[ id ].pauseVideo(); 1758 } 1759 } ); 1760 1761 // Stop Control. 1762 $( document ).on( 'click', '.cs-player-stop', function() { 1763 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1764 1765 let id = $( container ).attr( 'data-uid' ); 1766 1767 $( this ).siblings( '.cs-player-state' ).removeClass( 'cs-player-pause' ).addClass( 'cs-player-play' ); 1768 1769 $( this ).siblings( '.cs-player-state' ).addClass( 'cs-player-upause' ); 1770 1771 players[ id ].pauseVideo(); 1772 } ); 1773 1774 // Volume Control. 1775 $( document ).on( 'click', '.cs-player-volume', function() { 1776 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1777 1778 let id = $( container ).attr( 'data-uid' ); 1779 1780 $( this ).toggleClass( 'cs-player-mute cs-player-unmute' ); 1781 1782 if ( $( this ).hasClass( 'cs-player-unmute' ) ) { 1783 players[ id ].unMute(); 1784 } else { 1785 players[ id ].mute(); 1786 } 1787 } ); 1788 1789 // Document scroll. 1790 $( window ).on( 'load scroll resize scrollstop', function() {
1791 initVideoBackground(); 1792 } ); 1793 1794 // Document ready. 1795 $( document ).ready( function() { 1796 initVideoBackground(); 1797 } ); 1798 1799 // Post load. 1800 $( document.body ).on( 'post-load', function() { 1801 initVideoBackground(); 1802 } ); 1803 1804 // Document resize. 1805 $( window ).on( 'resize', function() { 1806 rescaleVideoBackground(); 1807 } ); 1808 1809 // Init. 1810 initVideoBackground(); 1811 1812 } )(); 1813 1814} )( jQuery );
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.