Merge pull request #2079 from dpalou/MOBILE-3068

MOBILE-3068 core: Fix img loaded event if no URL
main
Juan Leyva 2019-08-27 14:03:19 +01:00 committed by GitHub
commit 3c4ef6d8ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -152,12 +152,22 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
// Avoid handling data url's. // Avoid handling data url's.
if (url && url.indexOf('data:') === 0) { if (url && url.indexOf('data:') === 0) {
this.invalid = true; this.invalid = true;
this.onLoad.emit();
this.loaded = true;
return; return;
} }
this.handleExternalContent(targetAttr, url, siteId).catch(() => { this.handleExternalContent(targetAttr, url, siteId).catch(() => {
// Ignore errors. // Error handling content. Make sure the loaded event is triggered for images.
if (tagName === 'IMG') {
if (url) {
this.waitForLoad();
} else {
this.onLoad.emit();
this.loaded = true;
}
}
}); });
} }
@ -204,10 +214,6 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges {
this.addSource(url); this.addSource(url);
} }
if (tagName === 'IMG') {
this.waitForLoad();
}
return Promise.reject(null); return Promise.reject(null);
} }

View File

@ -468,7 +468,8 @@ export class CoreFormatTextDirective implements OnChanges {
// Wait for images to load. // Wait for images to load.
let promise: Promise<any> = null; let promise: Promise<any> = null;
if (externalImages.length) { if (externalImages.length) {
promise = Promise.all(externalImages.map((externalImage): any => { // Automatically reject the promise after 5 seconds to prevent blocking the user forever.
promise = this.utils.timeoutPromise(this.utils.allPromises(externalImages.map((externalImage): any => {
if (externalImage.loaded) { if (externalImage.loaded) {
// Image has already been loaded, no need to wait. // Image has already been loaded, no need to wait.
return Promise.resolve(); return Promise.resolve();
@ -480,7 +481,7 @@ export class CoreFormatTextDirective implements OnChanges {
resolve(); resolve();
}); });
}); });
})); })), 5000);
} else { } else {
promise = Promise.resolve(); promise = Promise.resolve();
} }