index.page.js
2.92 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
123
124
125
126
127
128
129
130
131
132
/**
* 逛首页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
require('guang/index.page.css');
let $ = require('yoho-jquery');
let info = require('./info');
let loadMore = info.loadMore;
let $loadMoreInfo = $('#load-more-info');
let $loading = $(''),
$noMore = $('');
let winH = $(window).height();
let $infoList = $('#info-list'),
$infos = $infoList.children('.info-list'),
$nav = $('#guang-nav'),
$curNav = $nav.children('.focus'),
curType = $curNav.data('type');
let getDynamicData = require('./list-dynamic');
let state = {};
require('../common');
if ($loadMoreInfo.length > 0) {
$loading = $loadMoreInfo.children('.loading');
$noMore = $loadMoreInfo.children('.no-more');
}
info.initSwiper(curType);
info.initInfosEvt($infoList);
// 初始化各Nav下资讯加载的状态
(function() {
let gender = $('#gender').val();
$nav.children('.guang-nav-item').each(function() {
let type = $(this).data('type'),
focus = $(this).hasClass('focus');
state[type] = {
page: focus ? 2 : 1,
gender: gender,
type: type,
end: false
};
});
getDynamicData.getDynamicData();
}());
$nav.bind('contextmenu', function() {
return false;
});
$nav.on('touchend touchcancel', function(e) {
let $this = $(e.target).closest('.guang-nav-item'),
$content,
index;
if ($this.hasClass('focus')) {
return;
}
e.preventDefault();
index = $this.index();
$this.addClass('focus');
$curNav.removeClass('focus');
$content = $infos.eq(index);
$curNav = $this;
curType = $this.data('type');
// 当未加载数据时去请求数据
if (state[curType].page === 1) {
// 无数据时隐藏正在加载和没有更多字样
$loading.addClass('hide');
$noMore.addClass('hide');
state[curType].isTab = true;
loadMore($content, state[curType]);
} else {
// 重置当前Tab的load-more
if (state[curType].end) {
$loading.addClass('hide');
$noMore.removeClass('hide');
} else {
$loading.removeClass('hide');
$noMore.addClass('hide');
}
}
$infos.not('.hide').addClass('hide');
$content.removeClass('hide');
if (state[curType].page === 1) {
window.rePosFooter();// 进入空内容时重新定位footer位置
}
});
function scrollHandler() {
let $c = $infos.not('.hide');
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $c.height()) {
loadMore($c, state[curType]);
}
}
// srcoll to load more
$(document).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
$nav.on('touchstart', function(e) {
let target = e.target || e.srcElement;
target.className = 'bytouch ' + target.className;
}).on('touchend touchcancel', function() {
$nav.find('li').removeClass('bytouch');
});