ps.js
3.47 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
/**
* plus+star页js
* @author: xuqi(qi.xu@yoho.cn)
* @date;2015/4/16
*/
var $ = require('jquery'),
Mustache = require('mustache'),
ellipsis = require('mlellipsis');
require('lazyload');
/**
* 初始化页面功能
*/
exports.init = function() {
$(function() {
var $intro = $('#intro'),
$infoContent = $('#info-content'),
$loadMore = $('#load-more-info'),
$loadStatus = $loadMore.children('.status'),
$loading = $loadStatus.filter('.loading'),
$noMore = $loadStatus.filter('.no-more'),
loadMoreH = $loadMore.height(),
winH = $(window).height(),
dataEnd = false,
canScroll = true,
tpl;
//获取相关资讯模板
$.get('/ps/readTpl', function(data) {
if (data.success) {
tpl = data.data;
Mustache.parse(tpl); //pre-compile and cache template
}
});
//文字截取
ellipsis.init();
setTimeout(function() {
$intro.mlellipsis(4); //品牌介绍
$('.info-block-content').each(function() { //相关文章
$(this).mlellipsis(2);
});
}, 0);
//lazyload
$('img.lazy').lazyload();
//显示品牌介绍所有文字
function showMoreIntro() {
var intro = $intro.attr('_title');
$intro.text(intro);
$('#more-intro .more').css('visibility', 'hidden');
}
$('#more-intro').delegate('.more', 'touchstart', function(e) {
e.preventDefault();
showMoreIntro();
}).delegate('.more', 'click', function() {
showMoreIntro();
});
//下拉加载更多
$(window).scroll(function() {
var count;
if (!canScroll) {
return;
}
if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
//loadData
if (!dataEnd) {
count = $infoContent.children('.info-block').length;
canScroll = false;
$.ajax({
type: 'GET',
url: '/ps/loadInfo',
data: {
start: count
}
}).then(function(data) {
var html = '',
res,
i;
if (data.success) {
if (data.end) {
dataEnd = true;
$loading.addClass('hide');
$noMore.removeClass('hide');
}
res = data.data;
for (i = 0; i < res.length; i++) {
html += Mustache.render(tpl, res[i]);
}
if (html !== '') {
$infoContent.append(html);
//lazyload 不包含src即未加载的图片
$('img.lazy:not([src])').lazyload({
container: $infoContent
});
}
canScroll = true;
}
});
}
}
});
});
};