Skip to content

Commit

Permalink
fixing loading images in iframes when using foreignObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolan committed Nov 17, 2017
1 parent 9445b0b commit 4fdf69d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export class DocumentCloner {
this.documentElement = this.cloneNode(element.ownerDocument.documentElement);
}

inlineAllImages(node: ?HTMLElement) {
if (this.inlineImages && node) {
inlineAllImages(_node: ?HTMLElement) {
if (this.inlineImages && _node) {
const node = _node;
const style = node.style;
Promise.all(
parseBackgroundImage(style.backgroundImage).map(backgroundImage => {
Expand Down Expand Up @@ -76,11 +77,15 @@ export class DocumentCloner {
style.backgroundImage = backgroundImages.join(',');
});

if (node instanceof HTMLImageElement) {
if (node instanceof node.ownerDocument.defaultView.HTMLImageElement) {
this.resourceLoader
.inlineImage(node.src)
.then(img => {
if (img && node instanceof HTMLImageElement && node.parentNode) {
if (
img &&
node instanceof node.ownerDocument.defaultView.HTMLImageElement &&
node.parentNode
) {
const parentNode = node.parentNode;
const clonedChild = copyCSSStyles(node.style, img.cloneNode(false));
parentNode.replaceChild(clonedChild, node);
Expand Down

0 comments on commit 4fdf69d

Please sign in to comment.