list-common.js
1.8 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
65
66
67
68
69
70
71
72
73
74
75
76
/**
* 星潮教室-列表公共部分
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/7
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip');
require('../common');
// 星搭配收藏请求
$(document).on('click', '.collection', function() {
var $that = $(this),
$icon = $that.find('.collected-ico');
var type;
if ($icon.hasClass('collected')) {
type = 'del';
} else {
type = 'fav';
}
$.ajax({
type: 'POST',
url: '/guang/star/setFavorite',
data: {
articleId: $that.parents('li').attr('articleId'),
type: type
},
success: function(data) {
var code = data.code;
if (code === 200) {
if ($icon.hasClass('collected')) {
$icon.removeClass('collected');
} else {
$icon.addClass('collected');
}
}
if (code === 401) {
if ($('#collocation-link').length <= 0) {
$('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
'<span class="collocation-link"></span></a>');
}
$('.collocation-link').click();
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
// 分享成功
window.successShare = function() {
$.ajax({
type: 'POST',
url: '/guang/starclass/forward',
success: function(data) {
var code = data.code;
if (code === 200 && data.data > 0) {
tip.show('分享成功,亲密度+10');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
};