|
|
@ -5,7 +5,7 @@ |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, forwardRef, Input, OnChanges, OnInit, Renderer2, SimpleChanges, ViewChild } from '@angular/core'; |
|
|
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, forwardRef, Input, OnChanges, Renderer2, SimpleChanges, ViewChild } from '@angular/core'; |
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
|
|
|
|
|
|
import { StatefulControlComponent, Types } from '@app/framework/internal'; |
|
|
import { StatefulControlComponent, Types } from '@app/framework/internal'; |
|
|
@ -21,7 +21,7 @@ export const SQX_IFRAME_EDITOR_CONTROL_VALUE_ACCESSOR: any = { |
|
|
providers: [SQX_IFRAME_EDITOR_CONTROL_VALUE_ACCESSOR], |
|
|
providers: [SQX_IFRAME_EDITOR_CONTROL_VALUE_ACCESSOR], |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
}) |
|
|
}) |
|
|
export class IFrameEditorComponent extends StatefulControlComponent<any, any> implements OnChanges, OnInit { |
|
|
export class IFrameEditorComponent extends StatefulControlComponent<any, any> implements OnChanges, AfterViewInit { |
|
|
private value: any; |
|
|
private value: any; |
|
|
private isDisabled = false; |
|
|
private isDisabled = false; |
|
|
private isInitialized = false; |
|
|
private isInitialized = false; |
|
|
@ -45,16 +45,24 @@ export class IFrameEditorComponent extends StatefulControlComponent<any, any> im |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnChanges(changes: SimpleChanges) { |
|
|
public ngOnChanges(changes: SimpleChanges) { |
|
|
if (changes['url']) { |
|
|
if (this.iframe) { |
|
|
this.iframe.nativeElement.src = this.url; |
|
|
if (changes['url']) { |
|
|
|
|
|
this.setupUrl(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (changes['formValue'] && this.formValue) { |
|
|
|
|
|
this.sendFormValue(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (changes['formValue'] && this.formValue) { |
|
|
private setupUrl() { |
|
|
this.sendFormValue(); |
|
|
this.iframe.nativeElement.src = this.url; |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit(): void { |
|
|
public ngAfterViewInit() { |
|
|
|
|
|
this.setupUrl(); |
|
|
|
|
|
|
|
|
this.own( |
|
|
this.own( |
|
|
this.renderer.listen('window', 'message', (event: MessageEvent) => { |
|
|
this.renderer.listen('window', 'message', (event: MessageEvent) => { |
|
|
if (event.source === this.iframe.nativeElement.contentWindow) { |
|
|
if (event.source === this.iframe.nativeElement.contentWindow) { |
|
|
@ -111,6 +119,10 @@ export class IFrameEditorComponent extends StatefulControlComponent<any, any> im |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private sendMessage(type: string, payload: any) { |
|
|
private sendMessage(type: string, payload: any) { |
|
|
|
|
|
if (!this.iframe) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const iframe = this.iframe.nativeElement; |
|
|
const iframe = this.iframe.nativeElement; |
|
|
|
|
|
|
|
|
if (this.isInitialized && iframe.contentWindow && Types.isFunction(iframe.contentWindow.postMessage)) { |
|
|
if (this.isInitialized && iframe.contentWindow && Types.isFunction(iframe.contentWindow.postMessage)) { |
|
|
|