Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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