Merge pull request #130 from coralproject/bugfix-for-permalink-path

restoring the scroll to comment functionality
This commit is contained in:
Riley Davis
2016-12-08 08:41:21 -10:00
committed by GitHub
2 changed files with 19 additions and 3 deletions
+19 -2
View File
@@ -67,12 +67,29 @@ class CommentStream extends Component {
// Set up messaging between embedded Iframe an parent component
this.pym = new Pym.Child({polling: 100});
const path = /https?\:\/\/([^?#]+)/.exec(this.pym.parentUrl);
const path = this.pym.parentUrl.split('#')[0];
this.props.getStream(path[1] || window.location);
this.props.getStream(path || window.location);
this.path = path;
this.pym.sendMessage('childReady');
this.pym.onMessage('DOMContentLoaded', hash => {
const commentId = hash.replace('#', 'c_');
let count = 0;
const interval = setInterval(() => {
if (document.getElementById(commentId)) {
window.clearInterval(interval);
this.pym.scrollParentToChildEl(commentId);
}
if (++count > 100) { // ~10 seconds
// give up waiting for the comments to load.
// it would be weird for the page to jump after that long.
window.clearInterval(interval);
}
}, 100);
});
}
render () {
@@ -113,7 +113,6 @@ hr {
/* Comment styles */
.comment {
position: relative;
margin-bottom: 10px;
position: relative;
}