browse-record.js
2.66 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
121
122
/**
* 浏览记录
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/11/28
*/
var $ = require('jquery');
var lazyLoad = require('yoho.lazyload');
var load = require('../plugin/loading');
var dialog = require('./dialog');
var $page = $('.records');
var $loadMore = $('.load-more'),
$more = $loadMore.children('.more'),
$noMore = $loadMore.children('.no-more');
var page = 0;
var end = false,
loading = false;
var winH = $(window).height();
load.init();
function moreRecord(cb) {
var count = $page.children('.browse-record-good').length;
if (loading) {
return;
}
if (page === 1) {
$loadMore.removeClass('hide');
}
loading = true;
$.ajax({
type: 'GET',
url: '/home/recordContent',
data: {
page: page + 1
},
success: function(data) {
if (data === ' ') {
end = true;
$more.addClass('hide');
$noMore.removeClass('hide');
} else {
if (count === 0) {
$page.html(data);
lazyLoad();
} else {
$page.append(data);
lazyLoad($page.find('.browse-record-good:gt(' + (count - 1) + ') .lazy'));
}
window.rePosFooter();
page++;
if (cb) {
cb();
}
}
},
complete: function() {
loading = false;
}
});
}
load.showLoadingMask();
moreRecord(load.hideLoadingMask);
$(window).scroll(function() {
if (end) {
return;
}
if (winH + $(window).scrollTop() > $(document).height() - 0.25 * $page.height()) {
moreRecord();
}
});
$page.on('touchstart', '.del-icon', function() {
var $good = $(this).closest('.browse-record-good'),
skn = $good.data('skn');
dialog.showDialog({
dialogText: '确定删除此条浏览记录吗?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
$.ajax({
type: 'GET',
url: '/home/delRecord',
data: {
skn: skn
},
success: function(data) {
if (data.code === 200) {
dialog.showDialog({
dialogText: '删除浏览记录成功',
autoHide: 2000,
fast: true
});
setTimeout(function() {
window.history.go(0);
}, 1200);
}
}
});
});
});