mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 18:55:19 -04:00
Wrap markdown rendering in iframe (#837)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
bd31076928
commit
586969f368
45 changed files with 1014 additions and 287 deletions
43
src/components/render-page/iframe-communicator.ts
Normal file
43
src/components/render-page/iframe-communicator.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export abstract class IframeCommunicator<SEND, RECEIVE> {
|
||||
protected otherSide?: Window
|
||||
protected otherOrigin?: string
|
||||
|
||||
constructor () {
|
||||
window.addEventListener("message", this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
public unregisterEventListener (): void {
|
||||
window.removeEventListener("message", this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
public setOtherSide (otherSide: Window, otherOrigin: string): void {
|
||||
this.otherSide = otherSide
|
||||
this.otherOrigin = otherOrigin
|
||||
}
|
||||
|
||||
public unsetOtherSide (): void {
|
||||
this.otherSide = undefined
|
||||
this.otherOrigin = undefined
|
||||
}
|
||||
|
||||
public getOtherSide (): Window | undefined {
|
||||
return this.otherSide
|
||||
}
|
||||
|
||||
protected sendMessageToOtherSide (message: SEND): void {
|
||||
if (this.otherSide === undefined || this.otherOrigin === undefined) {
|
||||
console.error("Can't send message because otherSide is null", message)
|
||||
return
|
||||
}
|
||||
this.otherSide.postMessage(message, this.otherOrigin)
|
||||
}
|
||||
|
||||
protected abstract handleEvent (event: MessageEvent<RECEIVE>): void;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue