collocation-list.js
2.7 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* 星潮教室-星搭配分页加载
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/4/12
*/
var $ = require('jquery'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho.lazyload'),
stopLoading = false;
var page = 1;
$('body').addClass('star-class-body');
function massageAJAX(page) {
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/guang/starclass/ajaxCollocation',
data: {
page: page
},
dataType: 'html',
success: function(data) {
stopLoading = false;
if (data === ' ') {
stopLoading = true;
tip.show('没有更多内容了');
}
$('.collocation-list').append(data);
loading.hideLoadingMask();
lazyLoad($('img.lazy'));
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
function scrollHandler() {
if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
stopLoading = true;
page++;
massageAJAX(page);
}
}
// 分享成功
window.successShare = function() {
$.ajax({
type: 'POST',
url: '/guang/starclass/forward',
success: function(data) {
var code = data.code;
if (code === 200) {
tip.show('分享成功,亲密度+10');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
};
$(window).scroll(function() {
scrollHandler();
});
if ($('.collocation-list').find('li').length === 0) {
massageAJAX(1);
}
// 星搭配收藏请求
$(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/starclass/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');
}
$that.find('.collected-num').html(data.num);
}
if (code === 201) {
window.location = data.data;
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});