From 2fee1a3aa097f70030027cace34ed28eb432a707 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 27 Oct 2018 22:53:22 +0800 Subject: [PATCH] fix(#8): avoid nesting comment missing parent --- src/disqus.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/disqus.js b/src/disqus.js index 2c77861..2c534f5 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -236,7 +236,8 @@ function DisqusJS(config) { id: resp.id, title: resp.title, isClosed: resp.isClosed, - length: resp.posts + length: resp.posts, + comment: [] }; // 填充站点名称和评论数目 @@ -304,8 +305,11 @@ function DisqusJS(config) { if (res.code === 0 && res.response.length > 0) { // 解禁 加载更多评论 $loadMoreBtn.classList.remove('dsqjs-disabled'); - // 已获得评论列表,进行渲染 - renderComment(res.response) + + // 将获得的评论数据和当前页面已有的评论数据合并 + disqusjs.page.comment = disqusjs.page.comment.concat(res.response); + // 用当前页面的所有评论数据进行渲染 + renderComment(disqusjs.page.comment) if (res.cursor.hasNext) { @@ -533,8 +537,8 @@ function DisqusJS(config) { // 增加提示信息 d.getElementById('dsqjs-msg').innerHTML = '你可能无法访问 Disqus,已启用评论基础模式。如需完整体验请针对 disq.us | disquscdn.com | disqus.com 启用代理并 尝试完整 Disqus 模式 | 强制完整 Disqus 模式。' - // 使用 append,当有评论翻页的时候可以无限在尾部添加 - d.getElementById('dsqjs-post-container').insertAdjacentHTML('beforeend', html); + d.getElementById('dsqjs-post-container').innerHTML = html; + d.getElementById('dsqjs-reload-disqus').addEventListener('click', checkDisqus); d.getElementById('dsqjs-force-disqus').addEventListener('click', forceDisqus); }