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 // Comments show 55 // 56 57 $( document ).on( 'click', '.post-comments-show button', function( e ) { 58 $( this ).parent().siblings( '.post-comments' ).show(); 59 $( this ).parent().remove(); 60 } ); 61 62 ( function() { 63 var ticking = false; 64 65 var update = function() { 66 67 // Sidebar. 68 // -----------------------------------. 69 $( '.content-area .site-main' ).each( function() { 70 71 var content = $( this ).find( '.entry-content' ); 72 var sidebar = $( this ).find( '.post-sidebar-inner' ); 73 74 // Vars offset. 75 var offsetTop = 20; 76 var offsetBottom = -20; 77 78 // Search elements. 79 var elements = []; 80 81 elements.push( '> .alignfull' ); 82 elements.push( '> .alignwide' ); 83 84 var layouts = $( content ).find( elements.join( ',' ) ); 85 86 if ( 0 === sidebar.length ) { 87 return; 88 } 89 if ( 0 === layouts.length ) { 90 return; 91 } 92 93 var disabled = false; 94 95 // Get sidebar values. 96 var sidebarTop = $( sidebar ).offset().top; 97 var sidebarHeight = $( sidebar ).outerHeight( true ); 98 99 for ( let i = 0; i < $( layouts ).length; ++i ) { 100 if ( 'none' === $( layouts[ i ] ).css( 'transform' ) ) { 101 continue; 102 } 103 104 // Get layout values. 105 let layoutTop = $( layouts[ i ] ).offset().top; 106 let layoutHeight = $( layouts[ i ] ).outerHeight( true ); 107 108 // Calc points. 109 let pointTop = layoutTop - offsetTop; 110 let pointBottom = layoutTop + layoutHeight + offsetBottom; 111 112 // Detect sidebar location. 113 if ( sidebarTop + sidebarHeight >= pointTop && sidebarTop <= pointBottom ) { 114 disabled = true; 115 } 116 } 117 118 119 if ( disabled ) { 120 $( sidebar ).css( 'opacity', '0' ); 121 } else { 122 $( sidebar ).css( 'opacity', '1' ); 123 } 124 } ); 125 126 // Ticking. 127 ticking = false; 128 }; 129 130 var requestTick = function() { 131 if ( !ticking ) { 132 window.requestAnimationFrame( update ); 133 ticking = true; 134 } 135 }; 136 137 var onProcess = function() { 138 requestTick(); 139 }; 140 141 $( window ).on( 'scroll', onProcess ); 142 $( window ).on( 'resize', onProcess ); 143 $( window ).on( 'image-load', onProcess ); 144 $( window ).on( 'post-load', onProcess ); 145 146 } )(); 147 148 /** 149 * AJAX Load More. 150 * 151 * Contains functions for AJAX Load More. 152 */ 153 154 155 /** 156 * Check if Load More is defined by the wp_localize_script 157 */ 158 if ( typeof csco_ajax_pagination !== 'undefined' ) { 159 160 $( '.post-archive' ).append( '<div class="ajax-navigation"><button class="load-more">' + csco_ajax_pagination.translation.load_more + '</button></div>' ); 161 162 var query_data = $.parseJSON( csco_ajax_pagination.query_data ), 163 infinite = $.parseJSON( query_data.infinite_load ), 164 button = $( '.ajax-navigation .load-more' ), 165 page = 2, 166 loading = false, 167 scrollHandling = { 168 allow: infinite, 169 reallow: function() { 170 scrollHandling.allow = true; 171 }, 172 delay: 400 //(milliseconds) adjust to the highest acceptable value 173 }; 174 175 } 176 177 /** 178 * Get next posts 179 */ 180 function csco_ajax_get_posts() { 181 loading = true; 182 // Set class loading. 183 button.addClass( 'loading' ); 184 var data = { 185 action: 'csco_ajax_load_more', 186 page: page, 187 posts_per_page: csco_ajax_pagination.posts_per_page, 188 query_data: csco_ajax_pagination.query_data, 189 _ajax_nonce: csco_ajax_pagination.nonce, 190 }; 191 192 // Request Url. 193 var csco_pagination_url; 194 if ( 'ajax_restapi' === csco_ajax_pagination.type ) { 195 csco_pagination_url = csco_ajax_pagination.rest_url; 196 } else { 197 csco_pagination_url = csco_ajax_pagination.url; 198 } 199 200 // Send Request. 201 $.post( csco_pagination_url, data, function( res ) { 202 if ( res.success ) { 203 204 // Get the posts. 205 var data = $( res.data.content ); 206 207 // Check if there're any posts. 208 if ( data.length ) { 209 210 var cscoAppendEnd = function() { 211 212 // WP Post Load trigger. 213 $( document.body ).trigger( 'post-load' ); 214 215 // Reinit Facebook widgets. 216 if ( $( '#fb-root' ).length ) { 217 FB.XFBML.parse(); 218 } 219 220 // Remove class loading. 221 button.removeClass( 'loading' ); 222 223 // Increment a page. 224 page = page + 1; 225 226 // Set the loading state. 227 loading = false;
228 }; 229 230 // Append new posts to archives. 231 if ( $( '.post-archive .archive-main' ).hasClass( 'archive-masonry' ) ) { 232 data.imagesLoaded( function() { 233 // Append new posts to masonry layout. 234 $( '.post-archive .archive-main' ).colcade( 'append', data ); 235 236 cscoAppendEnd(); 237 } ); 238 } else { 239 $( '.post-archive .archive-main' ).append( data ); 240 241 cscoAppendEnd(); 242 } 243 } 244 245 // Remove Button on Posts End. 246 if ( res.data.posts_end || !data.length ) { 247 248 // Remove Load More button. 249 $( '.ajax-navigation' ).remove(); 250 } 251 252 } else { 253 // console.log(res); 254 } 255 } ).fail( function( xhr, textStatus, e ) { 256 // console.log(xhr.responseText); 257 } ); 258 } 259 260 /** 261 * Check if Load More is defined by the wp_localize_script 262 */ 263 if ( typeof csco_ajax_pagination !== 'undefined' ) { 264 265 // On Scroll Event. 266 $( window ).scroll( function() { 267 if ( button.length && !loading && scrollHandling.allow ) { 268 scrollHandling.allow = false; 269 setTimeout( scrollHandling.reallow, scrollHandling.delay ); 270 var offset = $( button ).offset().top - $( window ).scrollTop(); 271 if ( 4000 > offset ) { 272 csco_ajax_get_posts(); 273 } 274 } 275 } ); 276 277 // On Click Event. 278 $( 'body' ).on( 'click', '.load-more', function() { 279 if ( !loading ) { 280 csco_ajax_get_posts(); 281 } 282 } ); 283 284 } 285 286 /** 287 * AJAX Auto Load Next Post. 288 * 289 * Contains functions for AJAX Auto Load Next Post. 290 */ 291 292 293 /** 294 * Check if Load Nextpost is defined by the wp_localize_script 295 */ 296 if ( typeof csco_ajax_nextpost !== 'undefined' ) { 297 298 var objNextparent = $( '.site-primary > .site-content' ), 299 objNextsect = '.cs-nextpost-section', 300 objNextpost = null, 301 currentNTitle = document.title, 302 currentNLink = window.location.href, 303 loadingNextpost = false, 304 scrollNextpost = { 305 allow: true, 306 reallow: function() { 307 scrollNextpost.allow = true; 308 }, 309 delay: 400 //(milliseconds) adjust to the highest acceptable value 310 }; 311 312 // Init. 313 if ( csco_ajax_nextpost.next_post ) { 314 $( objNextparent ).after( '<div class="cs-nextpost-inner"></div>' ); 315 316 objNextpost = $( '.cs-nextpost-inner' ); 317 } 318 } 319 320 /** 321 * Get next post 322 */ 323 function csco_ajax_get_nextpost() { 324 loadingNextpost = true; 325 326 // Set class loading. 327 var data = { 328 action: 'csco_ajax_load_nextpost', 329 not_in: csco_ajax_nextpost.not_in, 330 current_user: csco_ajax_nextpost.current_user, 331 nonce: csco_ajax_nextpost.nonce, 332 next_post: csco_ajax_nextpost.next_post, 333 }; 334 335 // Request Url. 336 var csco_ajax_nextpost_url; 337 if ( 'ajax_restapi' === csco_ajax_nextpost.type ) { 338 csco_ajax_nextpost_url = csco_ajax_nextpost.rest_url; 339 } else { 340 csco_ajax_nextpost_url = csco_ajax_nextpost.url; 341 } 342 343 // Send Request. 344 $.post( csco_ajax_nextpost_url, data, function( res ) { 345 346 csco_ajax_nextpost.next_post = false; 347 348 if ( res.success ) { 349 350 // Get the posts. 351 var data = $( res.data.content ); 352 353 // Check if there're any posts. 354 if ( data.length ) { 355 // Set the loading state. 356 loadingNextpost = false; 357 358 // Set not_in. 359 csco_ajax_nextpost.not_in = res.data.not_in; 360 361 // Set next data. 362 csco_ajax_nextpost.next_post = res.data.next_post; 363 364 // Remove loader. 365 $( objNextpost ).siblings( '.cs-nextpost-loading' ).remove(); 366 367 // Append new post. 368 $( objNextpost ).append( data ); 369 370 // Reinit facebook. 371 if ( $( '#fb-root' ).length ) { 372 FB.XFBML.parse(); 373 } 374 375 $( document.body ).trigger( 'post-load' ); 376 } 377 } else { 378 // console.log(res); 379 } 380 } ).fail( function( xhr, textStatus, e ) { 381 // console.log(xhr.responseText); 382 } ); 383 } 384 385 /** 386 * Check if Load Nextpost is defined by the wp_localize_script 387 */ 388 if ( typeof csco_ajax_nextpost !== 'undefined' ) { 389 390 // On Scroll Event. 391 $( window ).scroll( function() { 392 var scrollTop = $( window ).scrollTop(); 393 394 // Init nextpost. 395 if ( csco_ajax_nextpost.next_post ) { 396 397 if ( objNextpost.length && !loadingNextpost && scrollNextpost.allow ) { 398 scrollNextpost.allow = false; 399 setTimeout( scrollNextpost.reallow, scrollNextpost.delay ); 400 // Calc current offset. 401 let offset = objNextpost.offset().top + objNextpost.innerHe
401ight() - scrollTop; 402 // Load nextpost. 403 if ( 4000 > offset ) { 404 $( objNextpost ).after( '<div class="cs-nextpost-loading"></div>' ); 405 406 csco_ajax_get_nextpost(); 407 } 408 } 409 } 410 411 // Reset browser data link. 412 let objFirst = $( objNextsect ).first(); 413 414 if ( objFirst.length ) { 415 let firstTop = $( objFirst ).offset().top; 416 // If there has been a change. 417 if ( scrollTop < firstTop && window.location.href !== currentNLink ) { 418 document.title = currentNTitle; 419 window.history.pushState( null, currentNTitle, currentNLink ); 420 } 421 } 422 423 // Set browser data link. 424 $( objNextsect ).each( function( index, elem ) { 425 426 let elemTop = $( elem ).offset().top; 427 let elemHeight = $( elem ).innerHeight(); 428 429 if ( scrollTop > elemTop && scrollTop < elemTop + elemHeight ) { 430 // If there has been a change. 431 if ( window.location.href !== $( elem ).data( 'url' ) ) { 432 // New title. 433 document.title = $( elem ).data( 'title' ); 434 // New link. 435 window.history.pushState( null, $( elem ).data( 'title' ), $( elem ).data( 'url' ) ); 436 // Google Analytics. 437 if ( typeof gtag === 'function' && typeof window.gaData === 'object' ) { 438 439 var trackingId = Object.keys( window.gaData )[ 0 ]; 440 if ( trackingId ) { 441 gtag( 'config', trackingId, { 442 'page_title': $( elem ).data( 'title' ), 443 'page_location': $( elem ).data( 'url' ) 444 } ); 445 446 gtag( 'event', 'page_view', { 'send_to': trackingId } ); 447 } 448 } 449 } 450 } 451 } ); 452 } ); 453 } 454 455 /** 456 * Masonry Widget Area 457 */ 458 459 function initMasonrySidebar() { 460 461 /** 462 * Masonry Options 463 */ 464 var masonrySidebar = $( '.sidebar-area' ), 465 masonrySidebarOptions = { 466 columns: '.sidebar', 467 items: '.widget' 468 }; 469 470 // Set Masonry. 471 $( masonrySidebar ).imagesLoaded( function() { 472 $( masonrySidebar ).colcade( masonrySidebarOptions ); 473 } ); 474 } 475 476 $( document ).ready( function() { 477 initMasonrySidebar(); 478 } ); 479 480 /** 481 * Masonry Archive 482 */ 483 484 function initMasonry() { 485 486 var masonryArchive = $( '.archive-masonry' ), 487 masonryArchiveOptions = { 488 columns: '.archive-col', 489 items: 'article' 490 }; 491 492 $( masonryArchive ).imagesLoaded( function() { 493 $( masonryArchive ).colcade( masonryArchiveOptions ); 494 } ); 495 } 496 497 $( document ).ready( function() { 498 initMasonry(); 499 } ); 500 501 /* 502 * Load Mega Menu Posts 503 */ 504 function cscoLoadMenuPosts( menuItem ) { 505 var dataCat = menuItem.children( 'a' ).data( 'cat' ), 506 dataType = menuItem.children( 'a' ).data( 'type' ), 507 dataNumberposts = menuItem.children( 'a' ).data( 'numberposts' ), 508 menuContainer, 509 postsContainer; 510 511 // Containers. 512 if ( menuItem.hasClass( 'cs-mega-menu-has-category' ) ) { 513 menuContainer = menuItem; 514 postsContainer = menuContainer.find( '.cs-mm-posts' ); 515 } else { 516 menuContainer = menuItem.closest( '.sub-menu' ); 517 postsContainer = menuContainer.find( '.cs-mm-posts[data-cat="' + dataCat + '"]' ); 518 } 519 520 // Set Active. 521 menuContainer.find( '.menu-item, .cs-mm-posts' ).removeClass( 'active-item' ); 522 menuItem.addClass( 'active-item' ); 523 524 if ( postsContainer ) { 525 postsContainer.addClass( 'active-item' ); 526 } 527 528 // Check Loading. 529 if ( menuItem.hasClass( 'cs-mm-loading' ) || menuItem.hasClass( 'cs-mm-loaded' ) ) { 530 return false; 531 } 532 533 // Check Category. 534 if ( !dataCat || typeof dataCat === 'undefined' ) { 535 return false; 536 } 537 538 // Check Container. 539 if ( !postsContainer || typeof postsContainer === 'undefined' ) { 540 return false; 541 } 542 543 // Create Data. 544 var data = { 545 'cat': dataCat, 546 'type': dataType, 547 'per_page': dataNumberposts 548 }; 549 550 // Get Results. 551 $.ajax( { 552 url: csco_mega_menu.rest_url, 553 type: 'GET', 554 data: data, 555 global: false, 556 async: true, 557 beforeSend: function() { 558 menuItem.addClass( 'cs-mm-loading' ); 559 postsContainer.addClass( 'cs-mm-loading' ); 560 }, 561 success: function( res ) { 562 if ( res.status && 'success' === res.status ) { 563 564 // Set the loaded state. 565 menuItem.addClass( 'cs-mm-loaded' ); 566 postsContainer.addClass( 'cs-mm-loaded' ); 567 568 // Check if there're any posts. 569 if ( res.content && res.content.length ) { 570 571 $( res.content ).imagesLoaded( function() { 572 573 // Append Data. 574 postsContainer.html( res.content ); 575 } ); 576 } 577 } 578 },
579 complete: function() { 580 menuItem.removeClass( 'cs-mm-loading' ); 581 postsContainer.removeClass( 'cs-mm-loading' ); 582 } 583 } ); 584 } 585 586 /* 587 * Get First Tab 588 */ 589 function cscoGetFirstTab( container ) { 590 var firstTab = false; 591 592 container.find( '.cs-mega-menu-child' ).each( function( index, el ) { 593 if ( $( el ).hasClass( 'menu-item-object-category' ) ) { 594 firstTab = $( el ); 595 return false; 596 } 597 if ( $( el ).hasClass( 'menu-item-object-post_tag' ) ) { 598 firstTab = $( el ); 599 return false; 600 } 601 } ); 602 603 return firstTab; 604 } 605 606 /* 607 * Menu on document ready 608 */ 609 $( document ).ready( function() { 610 611 /* 612 * Get Menu Posts on Hover 613 */ 614 $( '.navbar-nav .menu-item.cs-mega-menu-has-category, .navbar-nav .menu-item.cs-mega-menu-child' ).on( 'hover', function() { 615 cscoLoadMenuPosts( $( this ) ); 616 } ); 617 618 /* 619 * Load First Tab on Mega Menu Hover 620 */ 621 $( '.navbar-nav .menu-item.cs-mega-menu-has-categories' ).on( 'hover', function() { 622 var tab = cscoGetFirstTab( $( this ) ); 623 624 if ( tab ) { 625 cscoLoadMenuPosts( tab ); 626 } 627 } ); 628 } ); 629 630 /* 631 * Load First Tab on Navbar Ready. 632 */ 633 $( document, '.navbar-nav' ).ready( function() { 634 var tab = false; 635 636 // Autoload First Tab. 637 $( '.navbar-nav .menu-item.cs-mega-menu-has-categories' ).each( function( index, el ) { 638 tab = cscoGetFirstTab( $( this ) ); 639 if ( tab ) { 640 cscoLoadMenuPosts( tab ); 641 } 642 } ); 643 644 // Autoload Category. 645 $( '.navbar-nav .menu-item.cs-mega-menu-has-category' ).each( function( index, el ) { 646 cscoLoadMenuPosts( $( this ) ); 647 } ); 648 } ); 649 650 // 651 // Responsive Navigation 652 // 653 654 $.fn.responsiveNav = function() { 655 this.removeClass( 'menu-item-expanded' ); 656 if ( this.prev().hasClass( 'submenu-visible' ) ) { 657 this.prev().removeClass( 'submenu-visible' ).slideUp( 350 ); 658 this.parent().removeClass( 'menu-item-expanded' ); 659 } else { 660 this.parent().parent().find( '.menu-item .sub-menu' ).removeClass( 'submenu-visible' ).slideUp( 350 ); 661 this.parent().parent().find( '.menu-item-expanded' ).removeClass( 'menu-item-expanded' ); 662 this.prev().toggleClass( 'submenu-visible' ).hide().slideToggle( 350 ); 663 this.parent().toggleClass( 'menu-item-expanded' ); 664 } 665 }; 666 667 // 668 // Navigation Menu Widget 669 // 670 671 $( document ).ready( function( e ) { 672 673 $( '.widget_nav_menu .menu-item-has-children' ).each( function( e ) { 674 675 // Add a caret. 676 $( this ).append( '<span></span>' ); 677 678 // Fire responsiveNav() when clicking a caret. 679 $( '> span', this ).on( 'click', function( e ) { 680 e.preventDefault(); 681 $( this ).responsiveNav(); 682 } ); 683 684 // Fire responsiveNav() when clicking a parent item with # href attribute. 685 if ( '#' === $( '> a', this ).attr( 'href' ) ) { 686 $( '> a', this ).on( 'click', function( e ) { 687 e.preventDefault(); 688 $( this ).next().next().responsiveNav(); 689 } ); 690 } 691 692 } ); 693 694 } ); 695 696 /* 697 * ---------------------------------------------------------------------------- 698 * Navigation 699 */ 700 701 var cscoNavigation = {}; 702 703 ( function() { 704 var $this; 705 706 cscoNavigation = { 707 sScrollAllow: false, 708 sInFirst: true, 709 sInterval: 0, 710 sPrevious: 0, 711 sDirection: 0, 712 713 loadStickyOffset: 0, 714 loadAdminBar: false, 715 716 Sticky: $( 'body' ).hasClass( 'navbar-sticky-enabled' ), 717 StickyUp: $( 'body' ).hasClass( 'navbar-smart-enabled' ), 718 StickyNav: $( '.site-header .navbar-primary' ), 719 StickyHeader: $( '.site-header' ), 720 StickyOffsetType: 'auto', 721 StickyOffset: 0, 722 StickyOffsetFull: 0, 723 724 /* 725 * Initialize 726 */ 727 init: function( e ) { 728 $this = cscoNavigation; 729 730 // Init events. 731 $this.events( e ); 732 }, 733 734 /* 735 * Events 736 */ 737 events: function( e ) { 738 // DOM Load 739 document.addEventListener( 'DOMContentLoaded', function( e ) { 740 $this.stickyInit( e ); 741 $this.smartLevels( e ); 742 $this.adaptTablet( e ); 743 } ); 744 // Resize 745 window.addEventListener( 'resize', function( e ) { 746 $this.stickyInit( e ); 747 $this.smartLevels( e ); 748 $this.adaptTablet( e ); 749 } ); 750 // Scroll 751 window.addEventListener( 'scroll', function( e ) { 752 window.requestAnimationFrame( $this.stickyScroll ); 753 } ); 754 755 // Add dynamic search support. 756 $( document ).on( 'animate-search', function( e ) { 757 $this.animateSearch( e ); 758 } ); 759 $( document ).on( 'animate-search-start', function( e ) { 760 $this.animateSearchStart( e ); 761 } ); 762 $( document ).on( 'animate-search-done', function( e ) { 763 $this.animateSearchDone( e ); 764 } ); 765 }, 766 767 /* 768 * Init nav bar sticky 769 */ 770 stickyInit: function( e ) { 771 772 if ( !$this.Sticky ) { 773 return; 774 } 775 776 $this.sScrollAllow = false;
777 778 // Calc sticky offset. 779 if ( $this.StickyOffsetType !== 'size' ) { 780 781 var calcbar = 0; 782 var wpadminbar = 0; 783 784 if ( $( '#wpadminbar' ).length > 0 ) { 785 calcbar = $( '#wpadminbar' ).outerHeight(); 786 787 wpadminbar = calcbar; 788 789 if ( 'resize' !== e.type ) { 790 $this.loadAdminBar = wpadminbar; 791 } 792 793 if ( 'absolute' === $( '#wpadminbar' ).css( 'position' ) ) { 794 wpadminbar = 0; 795 796 if ( 'resize' !== e.type ) { 797 $this.loadAdminBar = 0; 798 } 799 } 800 } 801 802 // Calc outside header. 803 $this.StickyOffsetFull = $this.StickyHeader.outerHeight(); 804 805 // Calc on load offset top. 806 var elOffset = $this.StickyNav.not( '.sticky-nav' ).offset(); 807 808 if ( elOffset && !$this.StickyNav.hasClass( '.sticky-nav' ) ) { 809 810 $this.StickyOffset = elOffset.top; 811 812 $this.loadStickyOffset = elOffset.top; 813 } else { 814 $this.StickyOffset = $this.loadStickyOffset; 815 } 816 817 // Consider the size of the wpadminbar. 818 if ( 32 === $this.loadAdminBar ) { 819 if ( 46 === calcbar ) { 820 $this.StickyOffset = $this.StickyOffset - wpadminbar + 14; 821 } else { 822 $this.StickyOffset = $this.StickyOffset - wpadminbar; 823 } 824 } else if ( 46 === $this.loadAdminBar || 0 === $this.loadAdminBar ) { 825 826 if ( 32 === calcbar ) { 827 $this.StickyOffset = $this.StickyOffset - wpadminbar - 14; 828 } else { 829 $this.StickyOffset = $this.StickyOffset - wpadminbar; 830 } 831 } 832 } 833 834 // Nav Height. 835 var navHeight = $this.StickyNav.outerHeight(); 836 837 // Set the min-height default of the header. 838 $this.StickyHeader.data( 'min-height', $this.StickyOffsetFull - navHeight ); 839 840 // Document ready. 841 if ( 'resize' !== e.type ) { 842 843 // Add nav dummy. 844 $this.StickyNav.after( '<div class="navbar-dummy"></div>' ); 845 $this.StickyHeader.find( '.navbar-dummy' ).height( navHeight ); 846 847 // Set type slide. 848 if ( $this.StickyUp ) { 849 $this.StickyHeader.addClass( 'sticky-type-slide' ); 850 } 851 } 852 853 // Allow. 854 $this.sScrollAllow = true; 855 }, 856 857 /* 858 * Make nav bar sticky 859 */ 860 stickyScroll: function( e ) { 861 if ( !$this.sScrollAllow ) { 862 return; 863 } 864 865 var scrollCurrent = $( window ).scrollTop(); 866 867 if ( $this.StickyUp ) { 868 869 if ( scrollCurrent > $this.StickyOffsetFull ) { 870 $this.StickyNav.addClass( 'sticky-nav' ); 871 } 872 873 if ( scrollCurrent <= $this.StickyOffset ) { 874 $this.StickyNav.removeClass( 'sticky-nav' ); 875 } 876 877 // Set scroll temporary vars. 878 if ( scrollCurrent > $this.sPrevious ) { 879 $this.sInterval = 0; 880 $this.sDirection = 'down'; 881 882 $this.StickyNav.addClass( 'sticky-down' ).removeClass( 'sticky-up' ); 883 } else { 884 $this.sInterval += $this.sPrevious - scrollCurrent; 885 $this.sDirection = 'up'; 886 887 $this.StickyNav.addClass( 'sticky-up' ).removeClass( 'sticky-down' ); 888 } 889 890 // Сonditions. 891 if ( $this.sInterval > 150 && 'up' === $this.sDirection ) { 892 $this.StickyNav.addClass( 'sticky-nav-slide-visible' ); 893 894 $( document ).trigger( 'sticky-nav-visible' ); 895 } else { 896 $this.StickyNav.removeClass( 'sticky-nav-slide-visible' ); 897 898 $( document ).trigger( 'sticky-nav-hide' ); 899 } 900 901 if ( scrollCurrent > $this.StickyOffsetFull + 150 ) { 902 $this.StickyNav.addClass( 'sticky-nav-slide' ); 903 } else { 904 $this.StickyNav.removeClass( 'sticky-nav-slide' ); 905 } 906 907 // Show onload document. 908 if ( $this.sInFirst && scrollCurrent > $this.StickyOffsetFull + 150 ) { 909 $this.StickyNav.addClass( ' sticky-nav-slide-visible sticky-up' ); 910 $this.StickyNav.addClass( 'sticky-nav-slide' ); 911 912 $( document ).trigger( 'sticky-nav-visible' ); 913 914 $this.sDirection = 'up'; 915 $this.sInterval = 151; 916 $this.sInFirst = false; 917 } 918 } else { 919 // Сonditions. 920 if ( scrollCurrent > $this.StickyOffset ) { 921 $this.StickyNav.addClass( 'sticky-nav' ); 922 923 $( document ).trigger( 'sticky-nav-visible' ); 924 } else { 925 $this.StickyNav.removeClass( 'sticky-nav' ); 926 $( document ).trigger( 'sticky-nav-hide' ); 927 } 928 } 929 930 $this.sPrevious = scrollCurrent; 931 }, 932 933 /* 934 * Dynamic search support 935 */ 936 animateSearch: function( e ) { 937 var minHeightMain = $this.StickyHeader.data( 'min-height' ); 938 var navHeight = $this.StickyNav.outerHeight(); 939 940 $this.StickyOffsetFull = ( minHeightMain + navHeight ); 941
942 $this.StickyHeader.find( '.navbar-dummy' ).height( navHeight ); 943 }, 944 945 /* 946 * Start: Dynamic search support 947 */ 948 animateSearchStart: function( e ) { 949 $this.sScrollAllow = false; 950 }, 951 952 /* 953 * Done: Dynamic search support 954 */ 955 animateSearchDone: function( e ) { 956 var minHeightMain = $this.StickyHeader.data( 'min-height' ); 957 var navHeight = $this.StickyNav.outerHeight(); 958 959 $this.sScrollAllow = true; 960 961 $this.sPrevious = $this.sPrevious + ( navHeight - minHeightMain ); 962 }, 963 964 /* 965 * Smart multi-Level menu 966 */ 967 smartLevels: function( e ) { 968 969 var windowWidth = $( window ).width(); 970 971 // Reset Calc. 972 $( '.navbar-nav li' ).removeClass( 'cs-mm-level' ); 973 $( '.navbar-nav li' ).removeClass( 'cs-mm-position-left cs-mm-position-right' ); 974 $( '.navbar-nav li .sub-menu' ).removeClass( 'cs-mm-position-init' ); 975 976 // Set Settings. 977 $( '.navbar-nav > li.menu-item' ).not( '.cs-mega-menu' ).each( function( index, parent ) { 978 var position = 'cs-mm-position-right'; 979 var objPrevWidth = 0; 980 981 $( parent ).find( '.sub-menu' ).each( function( index, el ) { 982 983 // Reset child levels. 984 $( el ).parent().next( 'li' ).addClass( 'cs-mm-level' ); 985 986 if ( $( el ).parent().hasClass( 'cs-mm-level' ) ) { 987 988 $( el ).parent().removeClass( 'cs-mm-level' ); 989 990 position = 'cs-mm-position-right'; 991 objPrevWidth = 0; 992 } 993 994 // Find out position items. 995 var offset = $( el ).offset(); 996 var objOffset = offset.left; 997 998 if ( 'cs-mm-position-right' === position && $( el ).outerWidth() + objOffset > windowWidth ) { 999 position = 'cs-mm-position-left'; 1000 } 1001 1002 if ( 'cs-mm-position-left' === position && objOffset - ( $( el ).outerWidth() + objPrevWidth ) < 0 ) { 1003 position = 'cs-mm-position-right'; 1004 } 1005 1006 objPrevWidth = $( el ).outerWidth(); 1007 1008 $( el ).addClass( 'cs-mm-position-init' ).parent().addClass( position ); 1009 } ); 1010 1011 } ); 1012 }, 1013 1014 /* 1015 * Adapting nav bar for tablet 1016 */ 1017 adaptTablet: function( e ) { 1018 // Click outside. 1019 $( document ).on( 'touchstart', function( e ) { 1020 1021 if ( !$( e.target ).closest( '.navbar-nav' ).length ) { 1022 $( '.navbar-nav .menu-item-has-children' ).removeClass( 'submenu-visible' ); 1023 } else { 1024 $( e.target ).parents( '.menu-item' ).siblings().find( '.menu-item' ).removeClass( 'submenu-visible' ); 1025 $( e.target ).parents( '.menu-item' ).siblings().closest( '.menu-item' ).removeClass( 'submenu-visible' ); 1026 } 1027 } ); 1028 1029 $( '.navbar-nav .menu-item-has-children' ).each( function( e ) { 1030 1031 // Reset class. 1032 $( this ).removeClass( 'submenu-visible' ); 1033 1034 // Remove expanded. 1035 $( this ).find( '> a > .expanded' ).remove(); 1036 1037 // Add a caret. 1038 if ( 'ontouchstart' in document.documentElement ) { 1039 $( this ).find( '> a' ).append( '<span class="expanded"></span>' ); 1040 } 1041 1042 // Check touch device. 1043 $( this ).addClass( 'ontouchstart' in document.documentElement ? 'touch-device' : '' ); 1044 1045 $( '> a .expanded', this ).on( 'touchstart', function( e ) { 1046 e.preventDefault(); 1047 1048 $( this ).closest( '.menu-item-has-children' ).toggleClass( 'submenu-visible' ); 1049 } ); 1050 1051 1052 if ( '#' === $( '> a', this ).attr( 'href' ) ) { 1053 $( '> a', this ).on( 'touchstart', function( e ) { 1054 e.preventDefault(); 1055 1056 if ( !$( e.target ).hasClass( 'expanded' ) ) { 1057 $( this ).closest( '.menu-item-has-children' ).toggleClass( 'submenu-visible' ); 1058 } 1059 } ); 1060 } 1061 } ); 1062 } 1063 }; 1064 1065 } )(); 1066 1067 // Initialize. 1068 cscoNavigation.init(); 1069 1070 // 1071 // Mobile Menu 1072 // 1073 1074 $( '.toggle-offcanvas, .site-overlay' ).on( 'click', function( e ) { 1075 e.preventDefault(); 1076 1077 // Transition. 1078 if ( !$( 'body' ).hasClass( 'offcanvas-active' ) ) { 1079 $( 'body' ).addClass( 'offcanvas-transition' ); 1080 } else { 1081 setTimeout( function() { 1082 $( 'body' ).removeClass( 'offcanvas-transition' ); 1083 }, 400 ); 1084 } 1085 1086 // Toogle offcanvas. 1087 $( 'body' ).toggleClass( 'offcanvas-active' ); 1088 } ); 1089 1090 /** 1091 * Site Search 1092 */ 1093 1094 function triggerSearch() { 1095 $( document ).trigger( 'animate-search-start' ); 1096 1097 // Start repeats at intervals of 25 milliseconds. 1098 var timerSearchId = setInterval( function() { 1099 $( document ).trigger( 'animate-search' ); 1100 }, 25 ); 1101 1102 // After 400 milliseconds sec stop replays. 1103 setTimeout( function() { 1104 clearInterval( timerSearchId ); 1105 }, 399 ); 1106 1107 setTimeout( function() { 1108 $( document ).trigger( 'animate-search-done' ); 1109 }, 400 ); 1110 } 1111 1112 $( '.toggle-search' ).on( 'click', function( event ) { 1113 1114 event.preventDefault(); 1115 1116 var container = $( '#search' ), 1117 field = $( 'input[type="search"]', container ); 1118 1119 // Toggle class on search button. 1120 $( this ).toggleClass( 'toggle-close' ); 1121 1122 // Add class to container. 1123 container.toggleClass( 'search-open' ); 1124 1125 // Slide toggle the container. 1126 triggerSearch(); 1127 1128 // Focus on / blur input field. 1129 if ( container.hasClass( 'search-open' ) ) { 1130 field.focus(); 1131 } else { 1132 field.blur(); 1133 } 1134 } ); 1135 1136 $( '#search, .search-close' ).on( 'click keyup', function( event ) { 1137 // Fire only when pressing Escape or clicking the .search-toggle button. 1138 if ( event.target.className === 'search-close' || event.keyCode === 27 ) { 1139 event.preventDefault(); 1140 // Toggle class on search button. 1141 $( '.toggle-search' ).removeClass( 'toggle-close' ); 1142 1143 // Remove class from container. 1144 $( '#search' ).removeClass( 'search-open' ); 1145 1146 $( '#search input[type="search"]' ).blur(); 1147 // Slide toggle the container. 1148 triggerSearch(); 1149 } 1150 } ); 1151 1152 /** 1153 * Sticky Sidebar 1154 */ 1155 1156 var stickyElements = []; 1157 1158 stickyElements.push( '.sticky-sidebar-enabled.stick-to-top .sidebar-1' ); 1159 stickyElements.push( '.sticky-sidebar-enabled.stick-last .sidebar .widget:last-child' ); 1160 1161 $( document ).ready( function() { 1162 1163 // Sticky sidebar for mozilla. 1164 if ( $.browser.mozilla ) { 1165 stickyElements.push( '.sticky-sidebar-enabled.stick-to-bottom .sidebar-1' ); 1166 } 1167 1168 // Join elements. 1169 stickyElements = stickyElements.join( ',' ); 1170 1171 // Sticky nav visible. 1172 $( document ).on( 'sticky-nav-visible', function() { 1173 var navBarHeight = $( '.navbar-primary' ).innerHeight(); 1174
1175 $( stickyElements ).css( 'top', 32 + navBarHeight + 'px' ); 1176 } ); 1177 1178 // Sticky nav hide. 1179 $( document ).on( 'sticky-nav-hide', function() { 1180 $( stickyElements ).css( 'top', 32 + 'px' ); 1181 } ); 1182 1183 } ); 1184 ( function() { 1185 var initAPI = false; 1186 var process = false; 1187 var contex = []; 1188 var players = []; 1189 var attrs = []; 1190 1191 // Create deferred object 1192 var YTdeferred = $.Deferred(); 1193 window.onYouTubePlayerAPIReady = function() { 1194 // Resolve when youtube callback is called 1195 // passing YT as a parameter. 1196 YTdeferred.resolve( window.YT ); 1197 }; 1198 1199 // Embedding youtube iframe api. 1200 function embedYoutubeAPI() { 1201 var tag = document.createElement( 'script' ); 1202 tag.src = 'https://www.youtube.com/iframe_api'; 1203 var firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ]; 1204 firstScriptTag.parentNode.insertBefore( tag, firstScriptTag ); 1205 } 1206 1207 // Video rescale. 1208 function rescaleVideoBackground() { 1209 $( '.cs-video-init' ).each( function() { 1210 let w = $( this ).parent().width(); 1211 let h = $( this ).parent().height(); 1212 1213 var hideControl = 400; 1214 1215 let id = $( this ).attr( 'data-uid' ); 1216 1217 if ( w / h > 16 / 9 ) { 1218 players[ id ].setSize( w, w / 16 * 9 + hideControl ); 1219 } else { 1220 players[ id ].setSize( h / 9 * 16, h + hideControl ); 1221 } 1222 } ); 1223 } 1224 1225 // Init video background. 1226 function initVideoBackground() { 1227 1228 if ( process ) { 1229 return; 1230 } 1231 1232 process = true; 1233 1234 // Smart init API. 1235 if ( !initAPI ) {
1236 let elements = $( '.cs-video-wrapper[data-video-id]' ); 1237 1238 if ( elements.length ) { 1239 embedYoutubeAPI(); 1240 1241 initAPI = true; 1242 } 1243 } 1244 1245 if ( !initAPI ) { 1246 process = false; 1247 1248 return; 1249 } 1250 1251 // Whenever youtube callback was called = deferred resolved 1252 // your custom function will be executed with YT as an argument. 1253 YTdeferred.done( function( YT ) { 1254 1255 $( '.cs-video-inner' ).each( function() { 1256 1257 // The state. 1258 var isInit = $( this ).hasClass( 'cs-video-init' ); 1259 1260 var id = null; 1261 1262 // Generate unique ID. 1263 if ( !isInit ) { 1264 id = Math.random().toString( 36 ).substr( 2, 9 ); 1265 } else { 1266 id = $( this ).attr( 'data-uid' ); 1267 } 1268 1269 // Create contex. 1270 contex[ id ] = this; 1271 1272 // The actived. 1273 var isActive = $( contex[ id ] ).hasClass( 'active' ); 1274 1275 // The monitor. 1276 var isInView = $( contex[ id ] ).isInViewport(); 1277 1278 // Initialization. 1279 if ( isInView && !isInit ) { 1280 // Add init class. 1281 $( contex[ id ] ).addClass( 'cs-video-init' ); 1282 1283 // Add unique ID. 1284 $( contex[ id ] ).attr( 'data-uid', id ); 1285 1286 // Get video attrs. 1287 let videoID = $( contex[ id ] ).parent().data( 'video-id' ); 1288 let videoStart = $( contex[ id ] ).parent().data( 'video-start' ); 1289 let videoEnd = $( contex[ id ] ).parent().data( 'video-end' ); 1290 1291 // Check video id. 1292 if ( typeof videoID === 'undefined' || !videoID ) { 1293 return; 1294 } 1295 1296 // Video attrs. 1297 attrs[ id ] = { 1298 'videoId': videoID, 1299 'startSeconds': videoStart, 1300 'endSeconds': videoEnd, 1301 'suggestedQuality': 'hd720' 1302 }; 1303 1304 // Creating a player. 1305 players[ id ] = new YT.Player( contex[ id ], { 1306 playerVars: { 1307 autoplay: 0, 1308 autohide: 1, 1309 modestbranding: 1, 1310 rel: 0, 1311 showinfo: 0, 1312 controls: 0, 1313 disablekb: 1, 1314 enablejsapi: 0, 1315 iv_load_policy: 3, 1316 playsinline: 1, 1317 loop: 1, 1318 }, 1319 events: { 1320 'onReady': function() { 1321 players[ id ].loadVideoById( attrs[ id ] ); 1322 players[ id ].mute(); 1323 }, 1324 'onStateChange': function( e ) { 1325 if ( e.data === 1 ) { 1326 $( contex[ id ] ).parents( '.cs-overlay, .cs-video-wrap' ).addClass( 'cs-video-bg-init' ); 1327 $( contex[ id ] ).addClass( 'active' ); 1328 } else if ( e.data === 0 ) { 1329 players[ id ].seekTo( attrs[ id ].startSeconds ); 1330 } 1331 } 1332 } 1333 } ); 1334 rescaleVideoBackground(); 1335 } 1336 1337 // Pause and play. 1338 let control = $( contex[ id ] ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-player-state' ); 1339 1340 if ( isActive && isInit && !$( control ).hasClass( 'cs-player-upause' ) ) { 1341 1342 if ( isInView && $( control ).hasClass( 'cs-player-play' ) ) { 1343 // Change icon. 1344 $( control ).removeClass( 'cs-player-play' ).addClass( 'cs-player-pause' ); 1345 // Pause video. 1346 players[ id ].playVideo(); 1347 } 1348 1349 if ( !isInView && $( control ).hasClass( 'cs-player-pause' ) ) { 1350 // Change icon. 1351 $( control ).removeClass( 'cs-player-pause' ).addClass( 'cs-player-play' ); 1352 // Pause video. 1353 players[ id ].pauseVideo(); 1354 } 1355 } 1356 } ); 1357 } ); 1358 1359 process = false; 1360 } 1361 1362 // State Control. 1363 $( document ).on( 'click', '.cs-player-state', function() { 1364 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1365 1366 let id = $( container ).attr( 'data-uid' ); 1367 1368 $( this ).toggleClass( 'cs-player-pause cs-player-play' ); 1369 1370 if ( $( this ).hasClass( 'cs-player-pause' ) ) { 1371 $( this ).removeClass( 'cs-player-upause' ); 1372 players[ id ].playVideo(); 1373 } else { 1374 $( this ).addClass( 'cs-player-upause' ); 1375 players[ id ].pauseVideo(); 1376 } 1377 } ); 1378 1379 // Stop Control. 1380 $( document ).on( 'click', '.cs-player-stop', function() { 1381 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1382 1383 let id = $( container ).attr( 'data-uid' ); 1384 1385 $( this ).siblings( '.cs-player-state' ).removeClass( 'cs-player-pause' ).addClass( 'cs-player-play' ); 1386 1387 $( this ).siblings( '.cs-player-state' ).addClass( 'cs-player-upause' ); 1388 1389 players[ id ].pauseVideo(); 1390 } ); 1391 1392 // Volume Control. 1393 $( document ).on( 'click', '.cs-player-volume', function() { 1394 let container = $( this ).parents( '.cs-overlay, .cs-video-wrap' ).find( '.cs-video-inner' ); 1395 1396 let id = $( container ).attr( 'data-uid' ); 1397 1398 $( this ).toggleClass( 'cs-player-mute cs-player-unmute' ); 1399 1400 if ( $( this ).hasClass( 'cs-player-unmute' ) ) { 1401 players[ id ].unMute(); 1402 } else { 1403 players[ id ].mute(); 1404 } 1405 } ); 1406 1407 // Document scroll. 1408 $( window ).on( 'load scroll resize scrollstop', function() {
1409 initVideoBackground(); 1410 } ); 1411 1412 // Document ready. 1413 $( document ).ready( function() { 1414 initVideoBackground(); 1415 } ); 1416 1417 // Post load. 1418 $( document.body ).on( 'post-load', function() { 1419 initVideoBackground(); 1420 } ); 1421 1422 // Document resize. 1423 $( window ).on( 'resize', function() { 1424 rescaleVideoBackground(); 1425 } ); 1426 1427 // Init. 1428 initVideoBackground(); 1429 1430 } )(); 1431 1432} )( 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.