Authored by 刘传洋

guagn comment pjax

@@ -12,6 +12,7 @@ const guangModel = require('../models/index'); @@ -12,6 +12,7 @@ const guangModel = require('../models/index');
12 const headerModel = require('../../../doraemon/models/header'); 12 const headerModel = require('../../../doraemon/models/header');
13 const ghelper = require('../models/guang-helper'); 13 const ghelper = require('../models/guang-helper');
14 const querystring = require('querystring'); 14 const querystring = require('querystring');
  15 +const helpers = global.yoho.helpers;
15 16
16 /** 17 /**
17 * 首页文章列表 类型列表 18 * 首页文章列表 类型列表
@@ -205,6 +206,7 @@ exports.detail = (req, res, next) => { @@ -205,6 +206,7 @@ exports.detail = (req, res, next) => {
205 if (pjax) { 206 if (pjax) {
206 guangModel.getArticleComments(id, page, pageSize).then(ret => { 207 guangModel.getArticleComments(id, page, pageSize).then(ret => {
207 208
  209 + res.set('Cache-Control', 'no-cache');
208 res.render('guang/detail-comment', { 210 res.render('guang/detail-comment', {
209 layout: false, 211 layout: false,
210 comment: ret 212 comment: ret
@@ -288,7 +290,11 @@ exports.detail = (req, res, next) => { @@ -288,7 +290,11 @@ exports.detail = (req, res, next) => {
288 shareImg: info.shareImg, 290 shareImg: info.shareImg,
289 sharedTitle: info.title, 291 sharedTitle: info.title,
290 shareDesc: info.desc, 292 shareDesc: info.desc,
291 - weixinUrl: info.weixinUrl 293 + weixinUrl: info.weixinUrl,
  294 + commentFirstPageUrl: helpers.urlFormat('/info/index', {
  295 + id: id,
  296 + pageSize: 10
  297 + }, 'guang')
292 } 298 }
293 }, { 299 }, {
294 title: `${info.title} | YOHO!BUY有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证`, 300 title: `${info.title} | YOHO!BUY有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证`,
@@ -142,6 +142,7 @@ @@ -142,6 +142,7 @@
142 <div id="pjax-container" class="comments-wrap"> 142 <div id="pjax-container" class="comments-wrap">
143 {{> comment}} 143 {{> comment}}
144 </div> 144 </div>
  145 + <a href="{{commentFirstPageUrl}}" data-role="comment-first-url" class="hide"></a>
145 </div> 146 </div>
146 {{/unless}} 147 {{/unless}}
147 </div> 148 </div>
@@ -17,7 +17,7 @@ const cachePage = { @@ -17,7 +17,7 @@ const cachePage = {
17 17
18 // 逛 18 // 逛
19 '/guang/': 1 * MINUTE, 19 '/guang/': 1 * MINUTE,
20 - '/guang/info/index': 10 * MINUTE, 20 + //'/guang/info/index': 10 * MINUTE,
21 '/guang/detail/:id': 10 * MINUTE, 21 '/guang/detail/:id': 10 * MINUTE,
22 '/guang/Index/editor': 1 * MINUTE, 22 '/guang/Index/editor': 1 * MINUTE,
23 '/guang/tags/index': 1 * MINUTE, 23 '/guang/tags/index': 1 * MINUTE,
@@ -15,7 +15,8 @@ var $commentList = $commentArea.find('.comments-wrap'), @@ -15,7 +15,8 @@ var $commentList = $commentArea.find('.comments-wrap'),
15 locating = false, // 评论页面正在跳转 15 locating = false, // 评论页面正在跳转
16 $commentBtn = $('#comment-btn'), 16 $commentBtn = $('#comment-btn'),
17 MAX_COMMENTS_WORDS = 100, 17 MAX_COMMENTS_WORDS = 100,
18 - $wordCountTip = $('#word-count-tip'); 18 + $wordCountTip = $('#word-count-tip'),
  19 + commentLoaded = false;
19 20
20 require('../common'); 21 require('../common');
21 require('./right-side'); 22 require('./right-side');
@@ -213,10 +214,21 @@ $commentBtn.click(function(e) { @@ -213,10 +214,21 @@ $commentBtn.click(function(e) {
213 214
214 215
215 // comment pager pjax 216 // comment pager pjax
216 -$(document).pjax('.comment-pager a', '#pjax-container', { 217 +$(document).pjax('.comment-pager a, [data-role="comment-first-url"]', '#pjax-container', {
217 timeout: 5000 218 timeout: 5000
218 }); 219 });
219 220
  221 +if($('#comment-area').length) {
  222 +
  223 + $(document).on('scroll', function(){
  224 + if(!commentLoaded && ($(document).scrollTop() + $(window).height()) > $('#comment-area').offset().top) {
  225 + commentLoaded = true;
  226 + $('[data-role="comment-first-url"]').click();
  227 + }
  228 + });
  229 +}
  230 +
  231 +
220 // 分页后移动到评论框的位置 232 // 分页后移动到评论框的位置
221 $(document).on('pjax:end', function() { 233 $(document).on('pjax:end', function() {
222 showComment(); 234 showComment();