From 2a3b380686a06ac1adadcc8b2d9d8cbbc7950178 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Thu, 6 Sep 2018 09:06:42 +0500 Subject: [PATCH] UserInfo close by Esc fix --- web/app/components/user-info/user-info.jsx | 14 ++++++++++++++ web/app/embed.js | 3 --- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/web/app/components/user-info/user-info.jsx b/web/app/components/user-info/user-info.jsx index 0ddfbd6e..d31833ec 100644 --- a/web/app/components/user-info/user-info.jsx +++ b/web/app/components/user-info/user-info.jsx @@ -24,6 +24,20 @@ class UserInfo extends Component { .getUserComments({ user: id, limit: 10 }) .then(({ comments = [] }) => this.setState({ comments })) .finally(() => this.setState({ isLoading: false })); + + document.addEventListener('keydown', this.globalOnKeyDown); + } + + componentWillUnmount() { + document.removeEventListener('keydown', this.globalOnKeyDown); + } + + globalOnKeyDown(e) { + // ESCAPE key pressed + if (e.keyCode == 27) { + const data = JSON.stringify({ isUserInfoShown: false }); + window.parent.postMessage(data, '*'); + } } render(props, { comments, isLoading }) { diff --git a/web/app/embed.js b/web/app/embed.js index b801dcc0..9c6b9997 100644 --- a/web/app/embed.js +++ b/web/app/embed.js @@ -151,9 +151,6 @@ function init() { horizontalscrolling="no" />`; this.iframe = this.node.querySelector('iframe'); - this.iframe.onload = () => { - this.iframe.contentDocument.addEventListener('keydown', this.onKeyDown); - }; this.node.appendChild(this.closeEl); document.body.appendChild(this.style); document.body.appendChild(this.back);