fix scroll to parent

This commit is contained in:
igoradamenko
2018-05-12 14:38:26 +03:00
parent 37eaef2c0e
commit 3bd4edbce3
5 changed files with 31 additions and 20 deletions
+1
View File
@@ -0,0 +1 @@
export default msg => window.parent.postMessage(JSON.stringify(msg), '*');
@@ -1,9 +1,9 @@
.comment__link-to-parent {
display: inline-block;
height: 12px;
height: 10px;
width: 16px;
margin-left: 8px;
vertical-align: -2px;
vertical-align: -1px;
background: url('comment__link-to-parent.svg') center no-repeat;
cursor: pointer;
+13 -12
View File
@@ -3,6 +3,7 @@ import { h, Component } from 'preact';
import api from 'common/api';
import { API_BASE, BASE_URL, COMMENT_NODE_CLASSNAME_PREFIX } from 'common/constants';
import { url } from 'common/settings';
import postMessage from 'common/post-message';
import store from 'common/store';
import Input from 'components/input';
@@ -187,8 +188,8 @@ export default class Comment extends Component {
e.preventDefault();
window.location.hash = '';
window.location.hash = `#${COMMENT_NODE_CLASSNAME_PREFIX}${pid}`;
postMessage({ hash: '' });
postMessage({ hash: `#${COMMENT_NODE_CLASSNAME_PREFIX}${pid}` });
}
render(props, { guest, isUserIdVisible, userBlocked, pinned, score, scoreIncreased, scoreDecreased, deleted, isInputVisible }) {
@@ -271,6 +272,16 @@ export default class Comment extends Component {
<a href={`${o.locator.url}#${COMMENT_NODE_CLASSNAME_PREFIX}${o.id}`} className="comment__time">{o.time}</a>
{
mods.level > 0 && (
<a
className="comment__link-to-parent"
href={`${o.locator.url}#${COMMENT_NODE_CLASSNAME_PREFIX}${o.pid}`}
onClick={this.scrollToParent}
/>
)
}
{
isAdmin && userBlocked && (
<span className="comment__status">Blocked</span>
@@ -301,16 +312,6 @@ export default class Comment extends Component {
title={isGuest ? 'Only authorized users are allowed to vote' : (isCurrentUser ? 'You can\'t vote for your own comment' : null)}
>Vote down</span>
</span>
{
mods.level > 0 && (
<a
className="comment__link-to-parent"
href={`${o.locator.url}#${COMMENT_NODE_CLASSNAME_PREFIX}${o.pid}`}
onClick={this.scrollToParent}
/>
)
}
</div>
<div
+9 -3
View File
@@ -49,16 +49,22 @@ function init() {
const iframe = node.getElementsByTagName('iframe')[0];
window.addEventListener('message', updateIframeHeight);
window.addEventListener('message', receiveMessages);
window.addEventListener('hashchange', postHashToIframe);
setTimeout(postHashToIframe, 1000);
function updateIframeHeight(event) {
function receiveMessages(event) {
try {
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
iframe.style.height = `${data.remarkIframeHeight}px`;
if (data.remarkIframeHeight) {
iframe.style.height = `${data.remarkIframeHeight}px`;
}
if (data.hash) {
window.location.hash = data.hash;
}
} catch (e) {}
}
+6 -3
View File
@@ -26,12 +26,15 @@
}
}, 200);
window.addEventListener('message', updateHash);
window.addEventListener('message', receiveMessages);
function updateHash(event) {
function receiveMessages(event) {
try {
const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
location.hash = data.hash;
if (data.hash) {
location.hash = data.hash;
}
} catch (e) {}
}
</script>