...
|
...
|
@@ -5,6 +5,7 @@ |
|
|
*/
|
|
|
|
|
|
var $ = require('jquery'),
|
|
|
Hammer = require('hammer'),
|
|
|
ellipsis = require('mlellipsis'),
|
|
|
lazyLoad = require('yoho.lazyload');
|
|
|
|
...
|
...
|
@@ -46,36 +47,43 @@ function setLazyLoadAndMellipsis($infos) { |
|
|
* @params $container 逛资讯列表容器
|
|
|
*/
|
|
|
function initInfosEvt($container) {
|
|
|
$container.delegate('.like-btn', 'tap', function(e) {
|
|
|
var $likeBtn = $(e.currentTarget),
|
|
|
$info = $likeBtn.closest('.guang-info'),
|
|
|
opt = 'ok';
|
|
|
|
|
|
if ($likeBtn.hasClass('like')) {
|
|
|
opt = 'cancel';
|
|
|
}
|
|
|
var cHammer = new Hammer($container[0]);
|
|
|
|
|
|
cHammer.on('tap', function(e) {
|
|
|
var $this = $(e.target),
|
|
|
opt = 'ok',
|
|
|
$likeBtn,
|
|
|
$info;
|
|
|
|
|
|
$likeBtn = $this.closest('.like-btn');
|
|
|
if ($likeBtn.length > 0) {
|
|
|
if ($likeBtn.hasClass('like')) {
|
|
|
opt = 'cancel';
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/guang/opt/praiseArticle',
|
|
|
data: {
|
|
|
id: $info.data('id'),
|
|
|
opt: opt
|
|
|
},
|
|
|
success: function(data) {
|
|
|
var code = data.code;
|
|
|
|
|
|
if (code === 200) {
|
|
|
$likeBtn.next('.like-count').text(data.data);
|
|
|
|
|
|
//切换点赞状态
|
|
|
$likeBtn.toggleClass('like');
|
|
|
$info = $this.closest('.guang-info');
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/guang/opt/praiseArticle',
|
|
|
data: {
|
|
|
id: $info.data('id'),
|
|
|
opt: opt
|
|
|
},
|
|
|
success: function(data) {
|
|
|
var code = data.code;
|
|
|
|
|
|
if (code === 200) {
|
|
|
$likeBtn.next('.like-count').text(data.data);
|
|
|
|
|
|
//切换点赞状态
|
|
|
$likeBtn.toggleClass('like');
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
setLazyLoadAndMellipsis($container.find('.guang-info'));
|
...
|
...
|
@@ -85,6 +93,8 @@ function initInfosEvt($container) { |
|
|
* 资讯LoadMore
|
|
|
*/
|
|
|
function loadMore($container, opt) {
|
|
|
var num;
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -93,18 +103,21 @@ function loadMore($container, opt) { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (opt.page === 0) {
|
|
|
if (opt.page === 1) {
|
|
|
|
|
|
//显示loading
|
|
|
loading.showLoadingMask();
|
|
|
}
|
|
|
|
|
|
num = $container.find('.guang-info').length;
|
|
|
searching = true;
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: ' /guang/index/page',
|
|
|
data: opt,
|
|
|
success: function(data) {
|
|
|
var $newItems;
|
|
|
|
|
|
if (data === ' ') {
|
|
|
opt.end = true;
|
|
|
searching = false;
|
...
|
...
|
@@ -117,9 +130,15 @@ function loadMore($container, opt) { |
|
|
}
|
|
|
$container.append(data);
|
|
|
|
|
|
setLazyLoadAndMellipsis($container.find('.guang-info'));
|
|
|
if (num > 0) {
|
|
|
$newItems = $container.find('.guang-info:gt(' + (num - 1) + ')');
|
|
|
} else {
|
|
|
$newItems = $container.find('.guang-info');
|
|
|
}
|
|
|
|
|
|
setLazyLoadAndMellipsis($newItems);
|
|
|
|
|
|
if (opt.page === 0) {
|
|
|
if (opt.page === 1) {
|
|
|
loading.hideLoadingMask();
|
|
|
}
|
|
|
|
...
|
...
|
|