Merge pull request #4115 from dpalou/MOBILE-4624

MOBILE-4624 format-text: Fix iframes with inline styles
main
Dani Palou 2024-07-08 15:27:47 +02:00 committed by GitHub
commit c05c35ad63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 9 deletions

View File

@ -169,9 +169,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
* Apply CoreExternalContentDirective to a certain element. * Apply CoreExternalContentDirective to a certain element.
* *
* @param element Element to add the attributes to. * @param element Element to add the attributes to.
* @param onlyInlineStyles Whether to only handle inline styles.
* @returns External content instance or undefined if siteId is not provided. * @returns External content instance or undefined if siteId is not provided.
*/ */
protected addExternalContent(element: Element): CoreExternalContentDirective | undefined { protected addExternalContent(element: Element, onlyInlineStyles = false): CoreExternalContentDirective | undefined {
if (!this.siteId) { if (!this.siteId) {
return; return;
} }
@ -185,11 +186,13 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
extContent.url = element.getAttribute('src') ?? element.getAttribute('href') ?? element.getAttribute('xlink:href'); extContent.url = element.getAttribute('src') ?? element.getAttribute('href') ?? element.getAttribute('xlink:href');
extContent.posterUrl = element.getAttribute('poster'); extContent.posterUrl = element.getAttribute('poster');
// Remove the original attributes to avoid performing requests to untreated URLs. if (!onlyInlineStyles) {
element.removeAttribute('src'); // Remove the original attributes to avoid performing requests to untreated URLs.
element.removeAttribute('href'); element.removeAttribute('src');
element.removeAttribute('xlink:href'); element.removeAttribute('href');
element.removeAttribute('poster'); element.removeAttribute('xlink:href');
element.removeAttribute('poster');
}
extContent.ngAfterViewInit(); extContent.ngAfterViewInit();
@ -569,9 +572,9 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
// Handle inline styles. // Handle inline styles.
elementsWithInlineStyles.forEach((el: HTMLElement) => { elementsWithInlineStyles.forEach((el: HTMLElement) => {
// Only add external content for tags that haven't been treated already. // Only add external content for tags that haven't been treated already.
if (el.tagName != 'A' && el.tagName != 'IMG' && el.tagName != 'AUDIO' && el.tagName != 'VIDEO' if (el.tagName !== 'A' && el.tagName !== 'IMG' && el.tagName !== 'AUDIO' && el.tagName !== 'VIDEO'
&& el.tagName != 'SOURCE' && el.tagName != 'TRACK') { && el.tagName !== 'SOURCE' && el.tagName !== 'TRACK' && el.tagName !== 'IMAGE') {
this.addExternalContent(el); this.addExternalContent(el, true);
} }
}); });