|
|
|
@ -9,7 +9,7 @@ import {
|
|
|
|
|
OnDestroy,
|
|
|
|
|
OnInit,
|
|
|
|
|
Output,
|
|
|
|
|
ViewChild
|
|
|
|
|
ViewChild,
|
|
|
|
|
} from "@angular/core";
|
|
|
|
|
import { SafeResourceUrl } from "@angular/platform-browser";
|
|
|
|
|
|
|
|
|
@ -58,12 +58,21 @@ export class ContentAwareImageComponent implements OnInit, DoCheck, OnDestroy {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkSize(): void {
|
|
|
|
|
if (this.imageElement?.nativeElement && this.imageContainer?.nativeElement) {
|
|
|
|
|
this.adjustSize(this.imageElement.nativeElement, this.imageContainer.nativeElement);
|
|
|
|
|
if (
|
|
|
|
|
this.imageElement?.nativeElement &&
|
|
|
|
|
this.imageContainer?.nativeElement
|
|
|
|
|
) {
|
|
|
|
|
this.adjustSize(
|
|
|
|
|
this.imageElement.nativeElement,
|
|
|
|
|
this.imageContainer.nativeElement,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onImageLoad(image: HTMLImageElement, imageContainer: HTMLDivElement): void {
|
|
|
|
|
public onImageLoad(
|
|
|
|
|
image: HTMLImageElement,
|
|
|
|
|
imageContainer: HTMLDivElement,
|
|
|
|
|
): void {
|
|
|
|
|
this.adjustSize(image, imageContainer);
|
|
|
|
|
this.appLoadEnd.emit();
|
|
|
|
|
}
|
|
|
|
@ -73,18 +82,24 @@ export class ContentAwareImageComponent implements OnInit, DoCheck, OnDestroy {
|
|
|
|
|
* @param {HTMLImageElement} image
|
|
|
|
|
* @param {HTMLDivElement} imageContainer
|
|
|
|
|
*/
|
|
|
|
|
public adjustSize(image: HTMLImageElement, imageContainer: HTMLDivElement): void {
|
|
|
|
|
public adjustSize(
|
|
|
|
|
image: HTMLImageElement,
|
|
|
|
|
imageContainer: HTMLDivElement,
|
|
|
|
|
): void {
|
|
|
|
|
const containerHeight = Math.abs(imageContainer.clientHeight);
|
|
|
|
|
const containerWidth = Math.abs(imageContainer.clientWidth);
|
|
|
|
|
|
|
|
|
|
if (this.previousWidth != containerWidth || this.previousHeight != containerHeight) {
|
|
|
|
|
if (
|
|
|
|
|
this.previousWidth !== containerWidth ||
|
|
|
|
|
this.previousHeight !== containerHeight
|
|
|
|
|
) {
|
|
|
|
|
this.previousHeight = containerHeight;
|
|
|
|
|
this.previousWidth = containerWidth;
|
|
|
|
|
const imageRelativeHeight = image.naturalHeight / containerHeight;
|
|
|
|
|
const imageRelativeWidth = image.naturalWidth / containerWidth;
|
|
|
|
|
const scaleWidth = imageRelativeWidth > imageRelativeHeight;
|
|
|
|
|
|
|
|
|
|
if (scaleWidth != this.scaleWidth) {
|
|
|
|
|
if (scaleWidth !== this.scaleWidth) {
|
|
|
|
|
this.scaleWidth = scaleWidth;
|
|
|
|
|
this.changeDetector.detectChanges();
|
|
|
|
|
}
|
|
|
|
@ -96,6 +111,7 @@ export class ContentAwareImageComponent implements OnInit, DoCheck, OnDestroy {
|
|
|
|
|
|
|
|
|
|
if (this.retryCount < this.maxRetry) {
|
|
|
|
|
this.retryCount++;
|
|
|
|
|
image.src = "";
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
image.src = imageSrc;
|
|
|
|
|
}, this.retryDelay * this.retryCount);
|
|
|
|
|