vendor
7 years ago
admin.js
4 years ago
front.js
4 years ago
index.html
7 years ago
pdf.worker.js
4 years ago
preview.js
4 years ago
settings.js
6 years ago
front.js
47 lines
| 1 | /** |
| 2 | * @package EmbedPress |
| 3 | * @author EmbedPress <help@embedpress.com> |
| 4 | * @copyright Copyright (C) 2018 EmbedPress. All rights reserved. |
| 5 | * @license GPLv2 or later |
| 6 | * @since 1.7.0 |
| 7 | */ |
| 8 | (function ($) { |
| 9 | 'use strict'; |
| 10 | |
| 11 | /** |
| 12 | * |
| 13 | * Make embeds responsive so they don't overflow their container. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Add max-width & max-height to <iframe> elements, depending on their width & height props. |
| 18 | * |
| 19 | * |
| 20 | * @return {void} |
| 21 | */ |
| 22 | function embedPressResponsiveEmbeds() { |
| 23 | var proportion, parentWidth; |
| 24 | |
| 25 | // Loop iframe elements. |
| 26 | document.querySelectorAll( 'iframe' ).forEach( function( iframe ) { |
| 27 | // Only continue if the iframe has a width & height defined. |
| 28 | if ( iframe.width && iframe.height ) { |
| 29 | // Calculate the proportion/ratio based on the width & height. |
| 30 | proportion = parseFloat( iframe.width ) / parseFloat( iframe.height ); |
| 31 | // Get the parent element's width. |
| 32 | parentWidth = parseFloat( window.getComputedStyle( iframe.parentElement, null ).width.replace( 'px', '' ) ); |
| 33 | // Set the max-width & height. |
| 34 | iframe.style.maxWidth = '100%'; |
| 35 | iframe.style.maxHeight = Math.round( parentWidth / proportion ).toString() + 'px'; |
| 36 | } |
| 37 | } ); |
| 38 | } |
| 39 | |
| 40 | // Run on initial load. |
| 41 | embedPressResponsiveEmbeds(); |
| 42 | |
| 43 | // Run on resize. |
| 44 | window.onresize = embedPressResponsiveEmbeds; |
| 45 | |
| 46 | })(jQuery); |
| 47 |