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);