msg.js
1.5 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
61
62
63
64
var $ = require('yoho.jquery'),
lazyLoad = require('yoho.lazyload');
var prising;
require('yoho.dotdotdot');
//资讯文字截取和lazyload
function dotLazy() {
//文字截取
$('.msg-title, .msg-content .content').dotdotdot({
wrap: 'letter'
});
//Lazyload
lazyLoad($('#msg-list img.lazy'));
}
//资讯点赞
$('.guang-page').on('click', '.like-icon', function() {
var $this = $(this),
msgId = $this.closest('.msg-content').data('id'),
url;
//同一资讯多次点击归一处理
if (prising === msgId) {
return;
}
prising = msgId;
$this.toggleClass('liked');
//点赞或取消点赞
if ($this.hasClass('liked')) {
url = '/guang/info/praise';
} else {
url = '/guang/info/cancelPraise';
}
$.ajax({
type: 'GET',
url: url,
data: {
id: msgId,
time: new Date().getTime()
}
}).then(function(data) {
if (data.code === 200) {
if (data.data * 1 === 0) {
$this.next('b').addClass('num-0').children('.num').html('0'); //隐藏数字显示
} else {
$this.next('b').removeClass('num-0').children('.num').html(data.data);
}
}
prising = false;
});
}).on('mouseenter mouseleave', '.like-icon', function() {
$(this).closest('.like').toggleClass('hover');
});
dotLazy();
exports.dotLazy = dotLazy;