Skip to content

Commit

Permalink
fixes #490 (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesros161 committed Sep 13, 2021
1 parent 7b9ca45 commit ef3ba07
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/assets/js/front-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ var BoldGrid = BoldGrid || {};
this.skipLink();
this.forms();
this.cssVarsPonyfill();
this.responsiveVideos();
},

// Handle responsive video iframe embeds.
responsiveVideos: function() {
$( window ).on( 'resize', function() {
var proportion,
parentWidth;

// Loop iframe elements.
document.querySelectorAll( 'iframe' ).forEach( function( iframe ) {

// Only continue if the iframe has a width & height defined.
if ( iframe.width && iframe.height ) {

// Calculate the proportion/ratio based on the width & height.
proportion = parseFloat( iframe.width ) / parseFloat( iframe.height );

// Get the parent element's width.
parentWidth = parseFloat( window.getComputedStyle( iframe.parentElement, null ).width.replace( 'px', '' ) );

// Set the max-width & height.
iframe.style.maxWidth = '100%';
iframe.style.maxHeight = Math.round( parentWidth / proportion ).toString() + 'px';
}
} );

} );
},

// Observe classList changes on body element.
Expand Down

0 comments on commit ef3ba07

Please sign in to comment.