Skip to content

Commit 607b694

Browse files
committed
Cosmetic iframe fix
1 parent 7fa2566 commit 607b694

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '9bd31969b6768df1d3e1');
1+
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '30ac48e186677e945e9b');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/events/optionsChanged.js

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
import { getBlockId, getEmbedIframe, getBlockIframe, getBlockWindow } from '../utils';
1+
import { getBlockId, getEmbedIframe, getBlockIframe, getBlockWindow, getEditorDocument } from '../utils';
22
import { dispatch } from '@wordpress/data';
33

4-
function loadIframelyEmbedJs(window) {
5-
console.log('embed.js loaded?');
6-
if (window.iframely) {
7-
console.log('yep');
8-
return;
9-
}
10-
console.log('nope, loading');
11-
12-
let script = window.document.createElement('script');
13-
script.type = 'text/javascript';
14-
script.async = true;
15-
script.src = ('https:' === document.location.protocol ? 'https:' : 'http:') + '//if-cdn.com/embed.js';
16-
window.document.head.appendChild(script);
17-
18-
/*
19-
let style = window.document.createElement('style');
20-
style.textContent = `.iframely-responsive {
4+
function maybeFixIframe(window) {
5+
setTimeout(() => {
6+
if (window.document.getElementById('iframely-styles')) {
7+
return;
8+
}
9+
let style = window.document.createElement('style');
10+
style.textContent = `.iframely-responsive {
2111
top: 0;
2212
left: 0;
2313
width: 100%;
2414
height: 0;
2515
position: relative;
2616
padding-bottom: 56.25%;
2717
box-sizing: border-box;
28-
}
29-
.iframely-responsive > * {
18+
}
19+
.iframely-responsive > * {
3020
top: 0;
3121
left: 0;
3222
width: 100%;
3323
height: 100%;
3424
position: absolute;
3525
border: 0;
3626
box-sizing: border-box;
37-
}`;
38-
window.document.head.appendChild(style);
39-
*/
27+
}`;
28+
window.document.head.appendChild(style);
29+
}, 50);
4030
}
4131

4232
export function optionsChanged(id, formContainer, query) {
@@ -50,7 +40,7 @@ export function optionsChanged(id, formContainer, query) {
5040
return;
5141
}
5242

53-
// wipe out old query completely
43+
// wipe out the old query completely
5444
if (data.data.query && data.data.query.length > 0) {
5545
data.data.query.forEach(function (key) {
5646
if (src.indexOf(key) > -1) {
@@ -59,13 +49,12 @@ export function optionsChanged(id, formContainer, query) {
5949
});
6050
}
6151

62-
// and add entire new query instead
52+
// and add an entire new query instead
6353
Object.keys(query).forEach(function (key) {
6454
src += (src.indexOf('?') > -1 ? '&' : '?') + key + '=' + query[key];
6555
});
6656

67-
// load embed.js if it was missing to catch changing sizes
68-
loadIframelyEmbedJs(getBlockWindow(blockId));
57+
maybeFixIframe(getBlockWindow(getBlockId()));
6958

7059
embedIframe.src = src;
7160

0 commit comments

Comments
 (0)