Authored by xuqi

标签页加载更多

... ... @@ -566,6 +566,43 @@ module.exports = function(flag) {
};
//标签页模拟数据
case 'tag':
return {
query: '卫衣',
gender: '1',
contents: [
{
id: 1,
img: 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
alt: '复古风',
title: 'Skin Art Series INN 2015春季新品',
text: '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka Tiger鬼冢' +
'虎也动作频频,于北京时间3.14日在东京发布其与意大利设计师AndreaPompilio合作的' +
'第2波--ONITSUKATIGER X ANDEREAPOMPILIO 2015秋冬新品便是其中之一。Yoho!Boy也' +
'为获取第一手的东宝特地来到东京并抢到了头排的“赏秀位”',
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: 80,
share: false //不显示share标签
},
{
id: 2,
img: 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
alt: '复古风',
title: 'Skin Art Series INN 2015春季新品',
text: '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka Tiger鬼冢' +
'虎也动作频频,于北京时间3.14日在东京发布其与意大利设计师AndreaPompilio合作的' +
'第2波--ONITSUKATIGER X ANDEREAPOMPILIO 2015秋冬新品便是其中之一。Yoho!Boy也' +
'为获取第一手的东宝特地来到东京并抢到了头排的“赏秀位”',
url: '',
publishTime: '2月13日 12:34',
pageView: 3445,
like: 80,
share: false
}
]
};
case 'matchs':
return [
{
id: 1,
... ...
... ... @@ -93,7 +93,7 @@ exports.init = function() {
canScroll = false;
$.ajax({
type: 'GET',
url: '/plusstar/loadinfo',
url: '/plustar/loadinfo',
data: setting
}).then(function(data) {
var html = '',
... ...
... ... @@ -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
... ...
.load-more-info {
width: 100%;
height: 70rem / $pxConvertRem;
line-height: 70rem / $pxConvertRem;
text-align: center;
font-size: 14px;
overflow: hidden;
.loading {
display: inline-block;
vertical-align: top;
.loader-inner {
display: inline-block;
height: 40rem / $pxConvertRem;
width: 40rem / $pxConvertRem;
margin-top: 12rem / $pxConvertRem;
> div {
height: 30rem / $pxConvertRem;
width: 30rem / $pxConvertRem;
border: 2px solid #000;
border-bottom-color: transparent;
}
}
}
}
\ No newline at end of file
... ...
@import "../common/time-view-like-share", "../common/good-info", "../common/loader";
@import "../common/time-view-like-share", "../common/good-info", "../common/loader", "../common/load-more";
.ps-container {
.ps-block {
... ... @@ -172,32 +172,4 @@
}
}
}
}
.load-more-info {
width: 100%;
height: 70rem / $pxConvertRem;
line-height: 70rem / $pxConvertRem;
text-align: center;
font-size: 14px;
overflow: hidden;
.loading {
display: inline-block;
vertical-align: top;
.loader-inner {
display: inline-block;
height: 40rem / $pxConvertRem;
width: 40rem / $pxConvertRem;
margin-top: 12rem / $pxConvertRem;
> div {
height: 30rem / $pxConvertRem;
width: 30rem / $pxConvertRem;
border: 2px solid #000;
border-bottom-color: transparent;
}
}
}
}
\ No newline at end of file
... ...
@import "../common/tag-content";
@import "../common/tag-content", "../common/load-more";
... ...
... ... @@ -8,17 +8,19 @@ var saunter = require('./views/controller/saunter'),
editor = require('./views/controller/editor'),
ps = require('./views/controller/ps'),
template = require('./views/controller/template'),
fav = require('./views/controller/favorite');
fav = require('./views/controller/favorite'),
match = require('./views/controller/match');
module.exports = function(app) {
app.get('/', saunter.show); //着陆页
app.get('/optimize', saunter.optimize); //优化着陆页
app.get('/tag', tag.show); //标签页
app.get('/tag/loadMatchs', tag.loadMatchs); //异步加载搭配内容
app.get('/editor', editor.show); //编辑页
app.get('/ps', ps.show); //plus + star
app.get('/plusstar/loadinfo', ps.loadInfo); //加载相关资讯数据
app.get('/plustar/loadinfo', ps.loadInfo); //加载相关资讯数据
app.get('/tpl', template.show); //模板页
app.get('/activity/classification', template.readClassification); //读取分类数据
... ... @@ -30,4 +32,6 @@ module.exports = function(app) {
app.get('/common/articletpl', ps.readTpl); //获取相关资讯模板
app.get('/common/goodinfo', template.readTpl); //读取模板
app.get('/common/matchtpl', match.readTpl);
};
\ No newline at end of file
... ...
/**
* @desc: 搭配相关控制器
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/5/11
*/
var path = require('path'),
fs = require('fs'),
tplPath = path.normalize(path.join(__dirname, '../partials/common/tag-content.html'));
exports.readTpl = function(req, res) {
fs.readFile(tplPath, 'utf8', function(err, data) {
if (err) {
res.send({success: false});
}
fs.readFile(
path.normalize(path.join(__dirname, '../partials/common/time-view-like-share.html')),
'utf8', function(err, subData) {
if (err) {
res.send({success: false});
}
data = data.replace('{{> common/time_view_like_share}}', subData); //Note: 后端需将partials目录替换为内容
res.send({
success: true,
data: data
});
});
});
};
\ No newline at end of file
... ...
... ... @@ -3,7 +3,8 @@
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/4/9
*/
var data = require('../../public/js/data')('tag');
var data = require('../../public/js/data')('tag'),
matchsData = require('../../public/js/data')('matchs');
exports.show = function(req, res) {
res.render('pages/tag', {
... ... @@ -11,4 +12,15 @@ exports.show = function(req, res) {
layout: '../layouts/layout',
isTag: true
});
};
exports.loadMatchs = function(req, res) {
res.send({
success: true,
data: {
end: false,
infos: matchsData
}
});
};
\ No newline at end of file
... ...
... ... @@ -40,7 +40,7 @@
</div>
<div class="infos ps-block">
<div class="info-title-container">
<h2 class="info-title">相关资讯</div>
<h2 class="info-title">相关资讯</h2>
</div>
<div id="info-content" class="info-content">
{{# info}}
... ... @@ -48,15 +48,7 @@
{{/ info}}
</div>
</div>
<div id="load-more-info" class="load-more-info">
<div class="loading status">
<div class="loader-inner ball-clip-rotate">
<div></div>
</div>
正在加载...
</div>
<span class="no-more status hide">没有更多的资讯</span>
</div>
{{> common/load_more}}
<input id="client-type" type="hidden" value="{{clientType}}">
<input id="gender" type="hidden" value="{{gender}}">
{{/ data}}
... ...
{{# data}}
{{> common/tag_content}}
{{/ data}}
\ No newline at end of file
<div class="tag-container">
{{# data}}
<div id="tag-list">
{{#contents}}
{{> common/tag_content}}
{{/contents}}
</div>
{{> common/load_more}}
<input id="query" type="hidden" value="{{query}}">
<input id="gender" type="hidden" value="{{gender}}">
{{/ data}}
</div>
\ No newline at end of file
... ...
<div id="load-more-info" class="load-more-info">
<div class="loading status">
<div class="loader-inner ball-clip-rotate">
<div></div>
</div>
正在加载...
</div>
<span class="no-more status hide">没有更多啦</span>
</div>
\ No newline at end of file
... ...