Skip to content

Commit 6291d54

Browse files
committed
fix embed loading in editor (#4887)
* fix embed loading in editor render embed inside iframe SDAAP-128
1 parent 53f5f4c commit 6291d54

2 files changed

Lines changed: 15 additions & 35 deletions

File tree

scripts/core/editor3/components/embeds/EmbedBlock.tsx

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,6 @@ export class EmbedBlockComponent extends React.Component<IProps> {
4949
this.onChangeDescription = this.onChangeDescription.bind(this);
5050
}
5151

52-
/**
53-
* @name EmbedBlockComponent#runScripts
54-
* @param {string} html
55-
* @description Runs and imports all the scripts in the given HTML.
56-
*/
57-
runScripts(html) {
58-
const tree = $('<div />').html(html);
59-
60-
tree.find('script').each((i, s) => {
61-
if (s.hasAttribute('src')) {
62-
let url = s.getAttribute('src');
63-
const async = s.hasAttribute('async');
64-
65-
if (url.startsWith('http')) {
66-
url = url.substring(url.indexOf(':') + 1);
67-
}
68-
69-
return $.ajax({url: url, async: async, dataType: 'script'});
70-
}
71-
72-
try {
73-
// eslint-disable-next-line no-eval
74-
eval(s.innerHTML);
75-
} catch (e) {
76-
/* carry on */
77-
}
78-
});
79-
}
80-
8152
getEntityKey() {
8253
const {block} = this.props;
8354

@@ -159,10 +130,6 @@ export class EmbedBlockComponent extends React.Component<IProps> {
159130
const isQumu = isQumuWidget(html);
160131
const {readOnly} = this.props;
161132

162-
if (isQumu !== true) {
163-
this.runScripts(html);
164-
}
165-
166133
const setLocked = () => {
167134
this.props.dispatch(actions.setLocked(true));
168135
};
@@ -187,7 +154,20 @@ export class EmbedBlockComponent extends React.Component<IProps> {
187154
{
188155
isQumu
189156
? <QumuWidget html={html} />
190-
: <div className="embed-block__wrapper" dangerouslySetInnerHTML={{__html: html}} />
157+
: (
158+
<div className="embed-block__wrapper">
159+
<iframe
160+
srcDoc={html}
161+
style={{border: 0}}
162+
onLoad={(event) => {
163+
const iframe = event.currentTarget;
164+
165+
// set the height of the iframe to the content height
166+
iframe.height = iframe.contentWindow.document.body.scrollHeight + 'px';
167+
}}
168+
/>
169+
</div>
170+
)
191171
}
192172

193173
<Textarea

scripts/core/editor3/components/tests/embeds.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('editor3.components.embed-block', () => {
2121
);
2222

2323
expect(wrapper.find('.embed-block__wrapper').html())
24-
.toBe('<div class="embed-block__wrapper"><h1>Embed Title</h1></div>');
24+
.toContain('<h1>Embed Title</h1>');
2525
});
2626
});
2727

0 commit comments

Comments
 (0)