...
|
...
|
@@ -6,6 +6,7 @@ |
|
|
|
|
|
var $ = require('jquery'),
|
|
|
ellipsis = require('mlellipsis'),
|
|
|
Mustache = require('mustache'),
|
|
|
timer = null;
|
|
|
|
|
|
require('lazyload');
|
...
|
...
|
@@ -14,6 +15,7 @@ require('lazyload'); |
|
|
* 初始化页面加载时的文字截取和图片懒加载功能
|
|
|
*/
|
|
|
exports.init = function() {
|
|
|
var tpl;
|
|
|
//相关文章截取文字
|
|
|
ellipsis.init();
|
|
|
|
...
|
...
|
@@ -26,13 +28,27 @@ exports.init = function() { |
|
|
}, 0);
|
|
|
|
|
|
$(function() {
|
|
|
var $tagList = $('#tag-list'),
|
|
|
$loadMore = $('#load-more-info'),
|
|
|
$loadStatus = $loadMore.children('.status'),
|
|
|
$noMore = $loadStatus.filter('.no-more'),
|
|
|
$loading = $loadStatus.filter('.loading'),
|
|
|
winH = $(window).height(),
|
|
|
loadMoreH = $loadMore.height(),
|
|
|
canScroll = true,
|
|
|
dataEnd = false;
|
|
|
|
|
|
//请求相关数据
|
|
|
var page = 1,
|
|
|
query = $('#query').val(),
|
|
|
gender = $('#gender').val();
|
|
|
|
|
|
//定位登录提示相关变量
|
|
|
var $loginTip = $('#login-tip'),
|
|
|
winH,
|
|
|
winW,
|
|
|
tipH,
|
|
|
tipW;
|
|
|
//定位登录提示
|
|
|
winH = $(window).height();
|
|
|
winW = $(window).width();
|
|
|
|
|
|
tipH = $loginTip.height();
|
...
|
...
|
@@ -42,6 +58,13 @@ exports.init = function() { |
|
|
top: (winH - tipH) / 2,
|
|
|
left: (winW - tipW) / 2
|
|
|
});
|
|
|
|
|
|
//读取模板
|
|
|
$.get('/common/matchtpl', function(data) {
|
|
|
tpl = data.data;
|
|
|
Mustache.parse(tpl);
|
|
|
});
|
|
|
|
|
|
//文章点赞
|
|
|
$('#container').delegate('.like-btn', 'touchstart', function(e) {
|
|
|
var $cur = $(e.currentTarget),
|
...
|
...
|
@@ -69,5 +92,58 @@ exports.init = function() { |
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
$(window).scroll(function() {
|
|
|
var setting;
|
|
|
|
|
|
if (!canScroll) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
|
|
|
if (!dataEnd) {
|
|
|
setting = {
|
|
|
page: page++,
|
|
|
query: query,
|
|
|
gender: gender
|
|
|
};
|
|
|
|
|
|
canScroll = false;
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/tag/loadMatchs',
|
|
|
data: setting
|
|
|
}).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 !== '') {
|
|
|
$tagList.append(html);
|
|
|
|
|
|
//lazyload 不包含src即未加载的图片
|
|
|
$('img.lazy').lazyload({
|
|
|
container: $tagList
|
|
|
});
|
|
|
}
|
|
|
canScroll = true;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|