Authored by xuqi

guang home hammer

... ... @@ -49,7 +49,7 @@ info.initInfosEvt($infoList);
focus = $(this).hasClass('focus');
state[type] = {
page: focus ? 1 : 0,
page: focus ? 2 : 1,
gender: gender,
type: type,
end: false
... ... @@ -82,7 +82,7 @@ navHammer.on('tap', function(e) {
curType = $this.data('type');
//当未加载数据时去请求数据
if (state[curType].page === 0) {
if (state[curType].page === 1) {
loadMore($content, state[curType]);
}
... ... @@ -98,6 +98,6 @@ navHammer.on('tap', function(e) {
$(document).scroll(function() {
if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
loadMore($infos.not('hide'), state[curType]);
loadMore($infos.not('.hide'), state[curType]);
}
});
\ No newline at end of file
... ...
... ... @@ -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();
}
... ...
... ... @@ -16,7 +16,7 @@ var $author = $('#author-infos');
var $tag = $('#tag');
var setting = {
page: 1,
page: 2,
end: false
};
... ...