2017-12-19 13:53:46 +01:00
|
|
|
import {Component, ElementRef, Input} from '@angular/core';
|
|
|
|
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';
|
|
|
|
//Usage :: <i-frame [url]="url" width="30%" height="250"></i-frame>`
|
|
|
|
@Component({
|
|
|
|
selector: 'i-frame',
|
|
|
|
template: `
|
2021-09-08 14:21:30 +02:00
|
|
|
<div *ngIf="!style" class=" uk-height-large" [class.iframeContainer]="addClass">
|
2020-09-15 15:53:18 +02:00
|
|
|
<iframe allowtransparency="true" [src]="safeUrl"></iframe>
|
2020-05-05 12:37:36 +02:00
|
|
|
</div>
|
2021-09-08 14:21:30 +02:00
|
|
|
<div *ngIf="style" [class.iframeContainer]="addClass" [ngStyle]="style">
|
2020-05-05 12:37:36 +02:00
|
|
|
<iframe [src]="safeUrl"></iframe>
|
2019-09-10 13:47:22 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class IFrameComponent {
|
|
|
|
public safeUrl: SafeResourceUrl;
|
|
|
|
@Input() url ;
|
2020-05-05 12:37:36 +02:00
|
|
|
@Input() width: number;
|
|
|
|
@Input() height: number;
|
2020-09-15 15:53:18 +02:00
|
|
|
@Input() unit: string = 'px';
|
2021-09-08 14:21:30 +02:00
|
|
|
@Input() addClass: boolean= true;
|
2020-05-05 12:37:36 +02:00
|
|
|
public style: any;
|
2021-09-08 14:21:30 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
constructor(private sanitizer: DomSanitizer) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
|
2020-09-15 15:53:18 +02:00
|
|
|
let width = 'width.' + this.unit;
|
|
|
|
let height = 'height.' + this.unit;
|
2020-05-05 12:37:36 +02:00
|
|
|
if(this.width && this.height) {
|
2020-09-15 15:53:18 +02:00
|
|
|
this.style = {};
|
|
|
|
this.style[width] = this.width;
|
|
|
|
this.style[height] = this.height;
|
2020-06-10 13:05:59 +02:00
|
|
|
} else if(this.height) {
|
2020-09-15 15:53:18 +02:00
|
|
|
this.style = {};
|
|
|
|
this.style[height] = this.height;
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|