vendor
7 years ago
admin.js
4 years ago
front.js
4 years ago
index.html
7 years ago
pdfobject.min.js
4 years ago
preview.js
4 years ago
settings.js
6 years ago
front.js
68 lines
| 1 | /** |
| 2 | * @package EmbedPress |
| 3 | * @author EmbedPress <help@embedpress.com> |
| 4 | * @copyright Copyright (C) 2022 EmbedPress. All rights reserved. |
| 5 | * @license GPLv2 or later |
| 6 | * @since 1.7.0 |
| 7 | */ |
| 8 | (function () { |
| 9 | 'use strict'; |
| 10 | // function equivalent to jquery ready() |
| 11 | function ready(fn) { |
| 12 | if (document.readyState !== 'loading'){ |
| 13 | fn(); |
| 14 | } else { |
| 15 | document.addEventListener('DOMContentLoaded', fn); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | ready(function() { |
| 20 | let option = { |
| 21 | forceObject: true, |
| 22 | }; |
| 23 | let selector = document.querySelectorAll('.embedpress-embed-document-pdf'); |
| 24 | if (selector.length) { |
| 25 | selector.forEach((function(value, index, thisArg) { |
| 26 | let id = value.dataset['emid']; |
| 27 | let src = value.dataset['emsrc']; |
| 28 | PDFObject.embed(src, "."+id, option); |
| 29 | })); |
| 30 | } |
| 31 | }); |
| 32 | |
| 33 | /** |
| 34 | * |
| 35 | * Make embeds responsive so they don't overflow their container. |
| 36 | */ |
| 37 | |
| 38 | /** |
| 39 | * Add max-width & max-height to <iframe> elements, depending on their width & height props. |
| 40 | * |
| 41 | * |
| 42 | * @return {void} |
| 43 | */ |
| 44 | function embedPressResponsiveEmbeds() { |
| 45 | var proportion, parentWidth; |
| 46 | |
| 47 | // Loop iframe elements. |
| 48 | document.querySelectorAll( 'iframe' ).forEach( function( iframe ) { |
| 49 | // Only continue if the iframe has a width & height defined. |
| 50 | if ( iframe.width && iframe.height ) { |
| 51 | // Calculate the proportion/ratio based on the width & height. |
| 52 | proportion = parseFloat( iframe.width ) / parseFloat( iframe.height ); |
| 53 | // Get the parent element's width. |
| 54 | parentWidth = parseFloat( window.getComputedStyle( iframe.parentElement, null ).width.replace( 'px', '' ) ); |
| 55 | // Set the max-width & height. |
| 56 | iframe.style.maxWidth = '100%'; |
| 57 | iframe.style.maxHeight = Math.round( parentWidth / proportion ).toString() + 'px'; |
| 58 | } |
| 59 | } ); |
| 60 | } |
| 61 | |
| 62 | // Run on initial load. |
| 63 | embedPressResponsiveEmbeds(); |
| 64 | |
| 65 | // Run on resize. |
| 66 | window.onresize = embedPressResponsiveEmbeds; |
| 67 | })(); |
| 68 |