1/* 2 * Frontend JS 3 * 4 * @package Kahuna 5 */ 6 7jQuery( document ).ready( function() { 8 /*cryoutLpBoxesRatios();*/ 9 cryoutMobileMenuInit(); 10 cryoutFixedMobileMenu(); 11 cryoutInitNav( '#mobile-menu' ); 12 cryoutMenuAnimate(); 13 cryoutBackToTop(); 14 cryoutSearchFormAnimation(); 15 cryoutSocialTitles(); 16 cryoutBodyClasses(); 17 cryoutTabsWidget(); 18 cryoutPortfolioFilter(); 19 cryoutRemoveFocus(); 20 21 if ( typeof cryout_theme_settings !== 'undefined' ) { 22 23 if ( ( ( cryout_theme_settings.fitvids == 2 ) && ( cryout_theme_settings.is_mobile == 1 ) ) || 24 ( cryout_theme_settings.fitvids == 1 ) 25 ) { 26 jQuery( '.entry-content' ).fitVids(); 27 } 28 29 if ( cryout_theme_settings.autoscroll == 1 ) { 30 cryoutAutoScroll(); 31 } 32 33 /* Animate articles */ 34 animateScroll( '#content-masonry > article', 'animated-article' ); 35 36 } /* typeof cryout_theme_settings check */ 37 38 jQuery( window ).on( 'scroll', function() { 39 40 if ( jQuery( this ).scrollTop() > 30 ) { 41 jQuery( '#nav-fixed' ).addClass( 'nav-fixed-show' ); 42 } else { 43 jQuery( '#nav-fixed' ).removeClass( 'nav-fixed-show' ); 44 } 45 46 if ( jQuery( this ).scrollTop() > 70 ) { 47 jQuery( '.kahuna-fixed-menu #site-header-main' ).addClass( 'header-fixed' ); 48 } else { 49 jQuery( '.kahuna-fixed-menu #site-header-main' ).removeClass( 'header-fixed' ); 50 } 51 52 } ); 53} ); /* document.ready */ 54 55jQuery( window ).on( 'load', function() { 56 57 jQuery( window ).trigger( 'scroll' ); 58 cryoutMasonry(); 59 cryoutPortfolioMasonry(); 60} ); /* window.load */ 61 62 63/* 64 * Functions 65**/ 66 67/* Force LP boxes images ratios */ 68/* function cryoutLpBoxesRatios() { 69 for ( var index = 1; index <= cryout_theme_settings.lpboxratios.length; ++index ) { 70 jQuery( '.lp-boxes-' + index + ' .lp-box-image' ).keepRatio( cryout_theme_settings.lpboxratios[index-1] ); 71 } 72} */ /* cryoutLpBoxesRatios() */ 73 74/* Menu animation */ 75function cryoutMenuAnimate() { 76 container = jQuery('#access'); 77 container.find( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false"></button>' ); 78 container.find( '.page_item_has_children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false"></button>' ); 79 80 jQuery( '#access > .menu ul li > a:not(:only-child)' ).attr( 'aria-haspopup', 'true' );/* IE10 mobile Fix */ 81 82 jQuery( '#access li' ).on( 'mouseenter', function() { 83 jQuery( this ).addClass( 'menu-hover' ); 84 } ).on( 'mouseleave', function() { 85 jQuery( this ).removeClass( 'menu-hover' ); 86 } ); 87 88 jQuery( '#access ul' ).find( '.dropdown-toggle' ).on( 'click', function() { 89 if (jQuery( this ).parents( '.menu-item, .page_item' ).hasClass( 'menu-hover' )) { 90 jQuery( this ).parents( '.menu-item, .page_item' ).removeClass( 'menu-hover' ); 91 } else { 92 jQuery( this ).parents( '.menu-item, .page_item' ).addClass( 'menu-hover' ); 93 } 94 } ); 95 96 jQuery( '#access ul' ).find( '.dropdown-toggle' ).on( 'blur', function() { 97 jQuery( this ).parents( '.menu-item, .page_item' ).removeClass( 'menu-hover' ); 98 } ); 99} /* cryoutMenuAnimate() */ 100 101/* Back to top button animation */ 102function cryoutBackToTop() { 103 jQuery( window ).on( 'scroll', function() { 104 if ( jQuery( this ).scrollTop() > 500 ) { 105 jQuery( '#toTop' ).addClass( 'toTop-show' ); 106 } else { 107 jQuery( '#toTop' ).removeClass( 'toTop-show' ); 108 } 109 110 } ); 111 112 jQuery( '#toTop' ).on( 'click', function( event ) { 113 event.preventDefault(); 114 jQuery( 'html, body' ).animate( { scrollTop: 0 }, 500 ); 115 return false; 116 } ); 117 118} /* cryoutBackToTop() */ 119 120/* Search form animation */ 121function cryoutSearchFormAnimation() { 122 var searchIcon = jQuery( '#access .menu-search-animated > button' ), 123 searchForm = jQuery( '.menu-search-animated .searchform, .menu-main-search .icon-cancel' ), 124 searchInput = jQuery( '#access .menu-search-animated .s' ); 125 126 searchIcon.on( 'click', function( event ) { /* never on focus! */ 127 event.preventDefault(); 128 searchForm.fadeIn( 200, function() { 129 searchInput.trigger( 'focus' ); 130 searchInput.css( 'outline', 'none' ); 131 } ); 132 event.stopPropagation(); 133 } ); 134 135 searchForm.on( 'click', function( event ) { 136 event.stopPropagation(); 137 } ); 138 139 searchInput.on( 'blur', function() { 140 searchForm.fadeOut( 200 ); 141 } ); 142 143} /* cryoutSearchFormAnimation() */ 144 145/* Mobile Menu */ 146function cryoutMobileMenuInit() { 147 148 /* First and last elements in the menu */ 149 var firstTab = jQuery( 'nav#mobile-menu #mobile-nav > li:first-child a' ), 150 lastTab = jQuery( '#nav-cancel' ); /* Cancel button will always be last */ 151 152 jQuery( '#nav-toggle' ).on( 'click', function( e ) { 153 e.preventDefault(); 154 e.stopPropagation(); 155 jQuery( '#mobile-menu' ).show().animate( {top: '0', opacity: 1 }, 500 ); 156 jQuery( 'body' ).addClass( 'noscroll' ); 157 firstTab.trigger( 'focus' ); 158 } ); 159 160 jQuery( '#nav-cancel' ).on( 'click', function( e ) { 161 e.preventDefault(); 162 e.stopPropagation(); 163 jQuery( '#mobile-menu' ).animate( { top: '100%', opacity: 0 }
163, 500, function() { jQuery( this ).css( 'top', '-100%' ).hide(); } ); 164 jQuery( 'body' ).removeClass( 'noscroll' ); 165 jQuery( '#nav-toggle' ).trigger( 'focus' ); 166 } ); 167 168 /* Redirect last tab to first input */ 169 lastTab.on( 'keydown', function ( e ) { 170 if ( jQuery( 'body' ).hasClass( 'noscroll' ) ) 171 if ( ( e.which === 9 && ( ! e.shiftKey ) ) ) { 172 e.preventDefault(); 173 firstTab.trigger( 'focus' ); 174 } 175 } ); 176 177 /* Redirect first shift+tab to last input*/ 178 firstTab.on( 'keydown', function ( e ) { 179 if ( jQuery( 'body' ).hasClass( 'noscroll' ) ) 180 if ( ( e.which === 9 && e.shiftKey ) ) { 181 e.preventDefault(); 182 lastTab.trigger( 'focus' ); 183 } 184 } ); 185 186 /* Allow escape key to close menu */ 187 jQuery( 'nav#mobile-menu' ).on( 'keyup', function( e ){ 188 if ( jQuery( 'body' ).hasClass( 'noscroll' ) ) 189 if ( e.keyCode === 27 ) { 190 jQuery( 'body' ).removeClass( 'noscroll' ); 191 lastTab.trigger( 'focus' ); 192 } 193 } ); 194 195 /* Remove animated class from mobile menu */ 196 jQuery( '#mobile-menu .menu-main-search' ).removeClass( 'menu-search-animated' ); 197 198 jQuery( '#mobile-menu > div' ).append( jQuery( '#sheader' ).clone() ); 199 jQuery( '#mobile-menu #sheader' ).attr( 'id', 'smobile' ); 200 201} /* cryoutMobileMenuInit() */ 202 203/* Add fixed mobile menu functionality */ 204function cryoutFixedMobileMenu(){ 205 206 /* Only run if fixed menu is enabled */ 207 if ( cryout_theme_settings.menustyle != 1 ) return; 208 209 var c, currentScrollTop = 0, currentScrollBottom, 210 navbar = jQuery( '#site-header-main-inside' ), 211 body = jQuery( 'body' ); 212 213 jQuery( window ).on( 'scroll', function () { 214 var a = jQuery( window ).scrollTop(); 215 var b = jQuery( document ).height(); 216 var viewport = jQuery( window ).height(); 217 var navbarHeight = navbar.height(); 218 219 currentScrollTop = a; 220 currentScrollBottom = b; 221 222 if ( ( c < currentScrollTop ) && ( a > navbarHeight + navbarHeight ) ) { 223 /* Scrolling down */ 224 body.removeClass( 'mobile-fixed' ); 225 } else if ( ( currentScrollTop > viewport ) && 226 ( currentScrollTop < currentScrollBottom - viewport * 2 ) && 227 ( c > currentScrollTop ) && ( ! ( a <= navbarHeight ) ) 228 ) { 229 /* Scrolling up */ 230 body.addClass( 'mobile-fixed' ); 231 } 232 233 c = currentScrollTop; 234 235 /* Always clear fixed class when returning to the top */ 236 if ( currentScrollTop <= navbarHeight ) { 237 body.removeClass( 'mobile-fixed' ); 238 } 239 240 } ); 241} /* cryoutFixedMobileMenu() */ 242 243/* Add submenus toggles to the primary navigation */ 244function cryoutInitNav( selector ) { 245 246 var container = jQuery( selector ); 247 248 /* Add dropdown toggle that display child menu items. */ 249 container.find( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false"></button>' ); 250 container.find( '.page_item_has_children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false"></button>' ); 251 252 /* Toggle buttons and submenu items with active children menu items. */ 253 container.find( '.current-menu-ancestor > button, .current-page-ancestor > button' ).addClass( 'toggle-on' ); 254 container.find( '.current-menu-ancestor > .sub-menu, .current-page-ancestor > .sub-menu, .current-menu-ancestor .children, .current-page-ancestor .children' ).show( 0 ).addClass( 'toggled-on' ); 255 256 container.find( '.dropdown-toggle' ).on( 'click', function( e ) { 257 var _this = jQuery( this ); 258 e.preventDefault(); 259 _this.toggleClass( 'toggle-on' ); 260 if ( _this.hasClass( 'toggle-on') ) { 261 _this.next( '.children, .sub-menu' ).show( 0 ).addClass( 'toggled-on' ); 262 _this.prev( 'a' ).addClass( 'toggled-on' ); 263 } 264 else { 265 _this.next( '.children, .sub-menu' ).removeClass( 'toggled-on' ); 266 _this.next( '.children, .sub-menu' ).find( '.children, .sub-menu' ).removeClass( 'toggled-on' ); 267 _this.next( '.children, .sub-menu' ).find( 'a' ).removeClass( 'toggled-on' ); 268 _this.next( '.children, .sub-menu' ).find( '.dropdown-toggle' ).removeClass( 'toggled-on' ); 269 _this.prev( 'a' ).removeClass( 'toggled-on' ); 270 271 setTimeout( function() { 272 _this.next( '.children, .sub-menu' ).hide( 0 ); 273 _this.next( '.children, .sub-menu' ).find( '.children, .sub-menu' ).hide( 0 ); 274 }, 600 ); 275 } 276 277 /* _this.parent().find( 'a' ).toggleClass( 'toggled-on' ); */ 278 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 279 } ); 280 281 /* Close mobile menu on click/tap */ 282 jQuery( 'body' ).on( 'click', '#mobile-nav a', function() { 283 jQuery( '#nav-cancel i' ).trigger( 'click' ); 284 } ); 285 286} /* cryoutInitNav() */ 287 288/* LP Boxes Keep aspect ratio*/ 289/* jQuery.fn.keepRatio = function( ratio ) { 290 291 var $this = jQuery( this ); 292 var nh = $this.width() / ratio; 293 $this.css( 'height', nh + 'px' ); 294 295 jQuery( window ).on( 'resize', function() { 296 var nh = $this.width() / ratio; 297 $this.css( 'height', nh + 'px' ); 298 } ); 299 300}; */ /* keepRatio() */ 301 302/* LP Box Mouse direction overlay animation */ 303jQuery.fn.mousedir = function( el ) { 304 if ( ! jQuery( 'body' ).hasClass( 'kahuna-landing-page' ) ) return; 305 306 var $this = jQuery( this ), 307 $el = jQuery( el ), 308 last_position = {}, 309 $output = 'direction-down'; 310 311 jQuery( document ).on( 'mousemove', function ( event ) { 312 if ( typeof( last_position.x ) !== 'undefined' ) { 313 var deltaX = last_position.x - event.offsetX, 314 deltaY = last_position.y - event.offsetY; 315 if ( ( Math.abs( deltaX ) > Math.abs( deltaY ) ) && ( deltaX > 0 ) ) { 316 $output = 'direction-left'; 317 } else if ( ( Math.abs( deltaX ) > Math.abs( deltaY ) ) && ( deltaX < 0 ) ) { 318 $output = 'direction-right'; 319 } else if ( ( Math.abs( deltaY ) > Math.abs( deltaX ) ) && ( deltaY > 0 ) ) { 320 $output = 'direction-up'; 321 } else if ( ( Math.abs( deltaY ) > Math.abs( deltaX ) ) && ( deltaY < 0 ) ) { 322 $output = 'direction-down'; 323 } else { 324 $output = 'direction-down'; 325 } 326 } 327 last_position = { 328 x : event.offsetX, 329 y : event.offsetY 330 }; 331 } ); 332 333 $el.on( 'mouseenter', function() { 334 jQuery( this ).removeClass( 'in-direction-left in-direction-right in-direction-up in-direction-down' + 335 ' out-direction-left out-direction-right out-direction-up out-direction-down' ); 336 jQuery( this ).addClass( 'in-' + $output ); 337 return; 338 } ); 339 340 $el.on( 'mouseleave', function() { 341 jQuery( this ).removeClass( 'in-direction-left in-direction-right in-direction-up in-direction-down ' + 342 ' out-direction-left out-direction-right out-direction-up out-direction-down' ); 343 jQuery( this ).addClass( 'out-' + $output ); 344 return; 345 } ); 346 347}; /* mouseDir() */ 348 349/* Check if element is visible in browser window */ 350function isInViewport( el ) { 351 if ( ! jQuery( el ).length ) return; 352 353 var adminHeight = ( jQuery( '#wpadminbar' ).length ) ? jQuery( '#wpadminbar' ).height() : 0; 354 355 var elementTop = jQuery( el ).offset().top; 356 var elementBottom = elementTop + jQuery( el ).outerHeight(); 357 358 var viewportTop = jQuery( window ).scrollTop(); 359 var viewportBottom = viewportTop + jQuery( window ).height() - adminHeight; 360 361 return ( elementBottom > viewportTop ) && ( elementTop < viewportBottom ); 362} /* isInViewport() */ 363 364/* Animate on scroll */ 365function animateScroll( $articles, $class ) { 366 367 var $articles = jQuery( $articles ); 368 369 $articles.each( function( i, el ) { 370 jQuery( el ).addClass( $class ); 371 } ); 372 373 jQuery( window ).on( 'scroll', function() { 374 $articles.each( function( i, el ) { 375 if ( isInViewport( el ) ) { 376 jQuery( el ).removeClass( $class ); 377 } 378 } ); 379 } ); 380 381 jQuery( window ).trigger( 'scroll' ); 382} /* animateScroll() */ 383 384/* Add Social Icons titles */ 385function cryoutSocialTitles() { 386
387 jQuery( ".socials a" ).each(function() { 388 jQuery( this ).attr( "title", jQuery( this ).children().html() ); 389 jQuery( this ).html( "" ); 390 }); 391 392} /* cryoutSocialTitles() */ 393 394/* Add body classes */ 395function cryoutBodyClasses() { 396 /* Detect and apply custom class for Safari */ 397 if ( navigator.userAgent.indexOf( "Safari" ) != -1 && navigator.userAgent.indexOf( "Chrome" ) == -1) { 398 jQuery( "body" ).addClass( "safari" ); 399 } 400 /* Add body class if masonry is used on page */ 401 if ( jQuery( '#content-masonry' ).length > 0 ) { 402 jQuery( 'body' ).addClass( 'kahuna-with-masonry' ); 403 } 404} /* cryoutBodyClasses() */ 405 406/* Remove all off-canvas states */ 407function cryoutRemoveFocus() { 408 jQuery( 'input, textarea, select, a' ).on( 'focus', function() { 409 if (jQuery( this ).data( 'mousedown' ) || jQuery( this ).data( 'mouseup' ) ) { 410 jQuery( this ).css( 'outline', 'none' ); 411 } 412 } ); 413} /* cryoutRemoveFocus() */ 414 415/* Tabs widget */ 416function cryoutTabsWidget() { 417 var tabsNav = jQuery( '.cryout-wtabs-nav' ), 418 tabsNavLis = tabsNav.children( 'li' ); 419 420 tabsNav.each( function() { 421 var localthis = jQuery( this ); 422 localthis.next().children( '.cryout-wtab' ).stop( true, true ) 423 .children( 'li' ).hide() 424 .parent().siblings( localthis.find( 'a' ).attr( 'href' ) ) 425 .children( 'li' ).show(); 426 localthis.children( 'li' ).first() 427 .addClass( 'active' ).stop( true, true ).show(); 428 } ); 429 430 tabsNavLis.on( 'click', function( e ) { 431 var localthis = jQuery( this ), 432 tabs_duration = 200; 433 434 localthis.siblings().removeClass( 'active' ).end().addClass( 'active' ); 435 localthis.parent().next().children( '.cryout-wtab' ).stop( true, true ) 436 .children( 'li' ).hide() 437 .parent().siblings( localthis.find( 'a' ).attr( 'href' ) ) 438 .children( 'li' ).each( function( index ) { 439 jQuery( this ).fadeIn( tabs_duration * ( index + 1 ) ); 440 } ); 441 e.preventDefault(); 442 } ).children( window.location.hash ? 'a[href="' + window.location.hash + '"]' : 'a:first' ) 443 .trigger( 'click' ); 444 445} /* cryoutTabsWidget() */ 446 447/* Blog Masonry */ 448function cryoutMasonry() { 449 if ( ( cryout_theme_settings.masonry == 1 ) && 450 ( cryout_theme_settings.magazine != 1 ) && 451 ( typeof jQuery.fn.masonry !== 'undefined' ) 452 ) { 453 jQuery( '#content-masonry' ).masonry( { 454 itemSelector: 'article', 455 columnWidth: 'article', 456 percentPosition: true, 457 isRTL: cryout_theme_settings.rtl, 458 } ); 459 } 460} /* cryoutMasonry() */ 461 462/* Jetpack Portfolio Masonry */ 463function cryoutPortfolioMasonry() { 464 if ( ( cryout_theme_settings.masonry == 1 ) && ( typeof jQuery.fn.masonry !== 'undefined' ) ) { 465 jQuery( '#lp-portfolio .jetpack-portfolio-shortcode' ).masonry( { 466 itemSelector: '.portfolio-entry', 467 columnWidth: '.portfolio-entry:not(.hidey)', 468 percentPosition: true, 469 isRTL: cryout_theme_settings.rtl, 470 } ); 471 } 472} /* cryoutPortfolioMasonry() */ 473 474/* Portfolio filtering */ 475function cryoutPortfolioFilter() { 476 jQuery( 'body' ).on( 'click', '#portfolio-filter > a', function( e ) { 477 e.preventDefault(); 478 jQuery( '#portfolio-filter > a' ).removeClass( 'active' ); 479 jQuery( this ).addClass( 'active' ); 480 var filter = jQuery( this ).attr( 'data-slug' ); 481 jQuery( '#portfolio-masonry .portfolio-entry' ).each( function( i, elm ) { 482 if ( filter == 'all' ) { 483 jQuery( elm ).removeClass( 'hidey' ).fadeIn( 'fast' ); 484 } else { 485 if ( ! jQuery( elm ).hasClass( 'type-' + filter ) ) { 486 jQuery( elm ).addClass( 'hidey' ).fadeOut( 'fast' ); 487 } else { 488 jQuery( elm ).removeClass( 'hidey' ).fadeIn( 'fast' ); 489 } 490 } 491 } ).promise().done( function() { 492 cryoutPortfolioMasonry(); 493 } ); 494 return false; 495 } ); 496} /* cryoutPortfolioFilter() */ 497 498/** 499 * Scroll to anchors 500 */ 501function cryoutAutoScroll(document, history, location) { 502 document = window.document; 503 history = window.history; 504 location = window.location; 505 var HISTORY_SUPPORT = !! ( history && history.pushState ); 506 var anchorScrolls = { 507 ANCHOR_REGEX: /^#[^ ]+$/, 508 OFFSET_HEIGHT_PX: jQuery( '.kahuna-fixed-menu #site-header-main' ).height(), 509 510 /* Establish events, and fix initial scroll position if a hash is provided. */ 511 init: function() { 512 this.scrollToCurrent(); 513 jQuery( window ).on( 514 'hashchange', 515 jQuery.proxy( this, 'scrollToCurrent' ) 516 ); 517 jQuery( 'body' ).on( 518 'click', 519 '.main a, nav ul li a, .meta-arrow', 520 jQuery.proxy( this, 'delegateAnchors' ) 521 ); 522 }, 523 524 /* Return the offset amount to deduct from the normal scroll position. 525 Modify as appropriate to allow for dynamic calculations. */ 526 getFixedOffset: function() { 527 return ( this.OFFSET_HEIGHT_PX ) ? this.OFFSET_HEIGHT_PX : 0; 528 }, 529 530 /* If the provided href is an anchor which resolves to an element on the page, scroll to it. */ 531 scrollIfAnchor: function( href, pushToHistory ) { 532 var match, anchorOffset; 533 534 if ( ! this.ANCHOR_REGEX.test( href ) ) { 535 return false;
536 } 537 538 match = document.getElementById(href.slice(1)); 539 540 if ( match && ( ! isInViewport( match ) ) && jQuery( match ).offset().top ) { 541 anchorOffset = jQuery( match ).offset().top - this.getFixedOffset(); 542 jQuery( 'html, body' ).animate( { scrollTop: anchorOffset} ); 543 544 /* Add the state to history as-per normal anchor links */ 545 if ( HISTORY_SUPPORT && pushToHistory ) { 546 history.pushState( {}, document.title, location.pathname + href ); 547 } 548 } 549 550 return !!match; 551 }, 552 553 /* Attempt to scroll to the current location's hash */ 554 scrollToCurrent: function(e) { 555 if (this.scrollIfAnchor(window.location.hash) && e) { 556 e.preventDefault(); 557 } 558 }, 559 560 /* If the click event's target was an anchor, fix the scroll position */ 561 delegateAnchors: function( e ) { 562 var elem = e.target.closest( 'a' ); 563 564 if ( this.scrollIfAnchor( elem.getAttribute( 'href' ), true ) ) { 565 e.preventDefault(); 566 } 567 } 568 }; 569 570 jQuery( document ).ready( jQuery.proxy( anchorScrolls, 'init' ) ); 571} 572 573/* FitVids 1.1*/ 574;(function( $ ){ 575 576 'use strict'; 577 578 $.fn.fitVids = function( options ) { 579 var settings = { 580 customSelector: null, 581 ignore: null 582 }; 583 584 if(!document.getElementById('fit-vids-style')) { 585 /* appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js */ 586 var head = document.head || document.getElementsByTagName('head')[0]; 587 var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}'; 588 var div = document.createElement("div"); 589 div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>'; 590 head.appendChild(div.childNodes[1]); 591 } 592 593 if ( options ) { 594 $.extend( settings, options ); 595 } 596 597 return this.each(function(){ 598 var selectors = [ 599 'iframe[src*="player.vimeo.com"]', 600 'iframe[src*="youtube.com"]', 601 'iframe[src*="youtube-nocookie.com"]', 602 'iframe[src*="kickstarter.com"][src*="video.html"]', 603 'object', 604 'embed' 605 ]; 606 607 if (settings.customSelector) { 608 selectors.push(settings.customSelector); 609 } 610 611 var ignoreList = '.fitvidsignore, .wp-block-embed__wrapper'; 612 613 if(settings.ignore) { 614 ignoreList = ignoreList + ', ' + settings.ignore; 615 } 616 617 var $allVideos = $(this).find(selectors.join(',')); 618 $allVideos = $allVideos.not('object object'); /* SwfObj conflict patch */ 619 $allVideos = $allVideos.not(ignoreList); /* Disable FitVids on this video. */ 620 621 $allVideos.each(function(){ 622 var $this = $(this); 623 if($this.parents(ignoreList).length > 0) { 624 return; /* Disable FitVids on this video. */ 625 } 626 if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } 627 if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width')))) 628 { 629 $this.attr('height', 9); 630 $this.attr('width', 16); 631 } 632 var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(), 633 width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), 634 aspectRatio = height / width; 635 if(!$this.attr('name')){ 636 var videoName = 'fitvid' + $.fn.fitVids._count; 637 $this.attr('name', videoName); 638 $.fn.fitVids._count++; 639 } 640 $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%'); 641 $this.removeAttr('height').removeAttr('width'); 642 } ); 643 } ); 644 }; 645 646 /* Internal counter for unique video names. */ 647 $.fn.fitVids._count = 0; 648 649/* Works with either jQuery or Zepto */ 650})( window.jQuery || window.Zepto ); 651 652/* IE .closest() fix */ 653if ( window.Element && ( ! Element.prototype.closest ) ) { 654 Element.prototype.closest = function( s ) { 655 var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ), 656 i, 657 el = this; 658 do { 659 i = matches.length; 660 while (--i >= 0 && matches.item( i ) !== el) {} 661 } while ( (i < 0) && ( el = el.parentElement ) ); 662 return el; 663 }; 664} 665 666/* FIN */
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.