info.js
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* 资讯相关API
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('yoho.zepto'),
ellipsis = require('mlellipsis'),
lazyLoad = require('yoho.lazyload');
var api = require('../api');
ellipsis.init();
/**
* 初始化资讯列表事件绑定
* @params $container 逛资讯列表容器
*/
function initInfosEvt($container) {
$container.delegate('.like-btn', 'touchstart', function(e) {
var $likeBtn = $(e.currentTarget),
$info = $likeBtn.closest('.guang-info');
$.ajax({
type: 'GET',
url: '/guang/info/prise', //TODO:cancelPrise
data: {
id: $info.data('id')
}
}).then(function(data) {
var code = data.code;
if (code === 200) {
$likeBtn.next('.like-count').text(data.data);
} else if (code === 400) {
api.alert('未登录');
}
}, function() {
api.alert('网络断开连接了~');
});
});
}
/**
* 设置指定资讯项的Lazyload和文字截取
* @params $infos 资讯项
*/
function setLazyLoadAndMellipsis($infos) {
lazyLoad($infos.find('img.lazy'));
$infos.each(function() {
var $this = $(this);
$this.find('.info-title')[0].mlellipsis(2);
$this.find('.info-text')[0].mlellipsis(2);
});
}
exports.initInfosEvt = initInfosEvt;
exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis;