forked from livebook-dev/livebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopout_window.js
More file actions
45 lines (43 loc) · 1.29 KB
/
Copy pathpopout_window.js
File metadata and controls
45 lines (43 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* A hook for popped out windows.
*/
const PopoutWindow = {
mounted() {
this.props = this.getProps();
console.log("PopoutWindow mounted");
const self = this;
this.handleBeforeUnloadEvent = this.handleBeforeUnloadEvent.bind(this);
window.addEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.getElement("canvas-close-button").addEventListener("click", (event) =>
this.handleCanvasCloseClick()
);
this.getElement("canvas-popin-button").addEventListener("click", (event) =>
this.handleCanvasPopinClick()
);
},
updated() {
this.props = this.getProps();
console.log("PopoutWindow updated");
},
getProps() {
return {};
},
handleBeforeUnloadEvent(event) {
this.sendToParent("canvas_popin_clicked");
},
handleCanvasCloseClick() {
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.sendToParent("canvas_close_clicked");
},
handleCanvasPopinClick() {
window.removeEventListener("beforeunload", this.handleBeforeUnloadEvent);
this.sendToParent("canvas_popin_clicked");
},
getElement(name) {
return document.querySelector(`[data-el-${name}]`);
},
sendToParent(message) {
window.opener.postMessage(message, window.location.origin);
},
};
export default PopoutWindow;