From 8957ffabae89f5eab6b46078bfbf7649b18e1f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 24 Aug 2018 13:14:10 +0200 Subject: [PATCH] MOBILE-2566 ux: Check also image size in percentage --- src/app/app.scss | 1 - src/directives/format-text.ts | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/app.scss b/src/app/app.scss index ebe16db2b..739bb6134 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -299,7 +299,6 @@ core-format-text[ng-reflect-single-line="true"] { } img.core-media-adapt-width { - width: 100%; height: auto; } diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index 466654f91..5d5bf1f36 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -117,11 +117,16 @@ export class CoreFormatTextDirective implements OnChanges { protected adaptImage(elWidth: number, img: HTMLElement): void { const imgWidth = this.getElementWidth(img), // Element to wrap the image. - container = document.createElement('span'); + container = document.createElement('span'), + originalWidth = img.attributes.getNamedItem('width'); - const forcedWidth = parseInt(img.attributes.getNamedItem('width').value); - if (!isNaN(forcedWidth) && img.attributes.getNamedItem('width').value.indexOf('%') < 0) { - img.style.width = forcedWidth + 'px'; + const forcedWidth = parseInt(originalWidth && originalWidth.value); + if (!isNaN(forcedWidth)) { + if (originalWidth.value.indexOf('%') < 0) { + img.style.width = forcedWidth + 'px'; + } else { + img.style.width = forcedWidth + '%'; + } } container.classList.add('core-adapted-img-container');