Skip to content

Commit

Permalink
[Fix] Test ajax with the site.
Browse files Browse the repository at this point in the history
  • Loading branch information
yfwz100 committed Mar 30, 2013
1 parent 3d0bbe2 commit 103b4a7
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 51 deletions.
2 changes: 1 addition & 1 deletion public/javascripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2022,4 +2022,4 @@
})


}(window.jQuery);
}(window.jQuery);
19 changes: 19 additions & 0 deletions public/stylesheets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,22 @@
}
}
}

.popup {
overflow: hidden;

.date {
padding: 10px;
font-size: 2em;
background-color: #049cdb;
color: #efefef;
}

.text {
padding: 10px;
}

.no-result {
padding: 10px;
}
}
16 changes: 11 additions & 5 deletions routes/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ exports.catalog = function catalog(req, res) {
}
}, function (err, results) {
if (!err) {
res.render('catalog', {
title: results.catalog.name,
description: results.catalog.description,
posts: results.posts
});
if (! req.xhr) {
res.render('catalog', {
title: results.catalog.name,
description: results.catalog.description,
posts: results.posts
});
} else {
res.render('catalog-ajax', {
posts: results.posts
});
}
} else {
common.error(res, err, '/');
}
Expand Down
3 changes: 2 additions & 1 deletion routes/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var model = require('../my/model')
, common = require('../my/view/common');

exports.index = function index(req, res) {
model.Picture.list(3, function(err, slides) {
model.Picture.find({'tag':{ $in: ['home']}}).limit(3)
.exec(function(err, slides) {
if (err) {
common.error(res, err, '/');
} else {
Expand Down
8 changes: 6 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ module.exports = {
post: feedback.submit
},

'admin/*': {
'admin(*)': {
all: user.checkLogin,
},
'admin': require('./admin/')
'admin': require('./admin/'),

'setup': {
all: require('./setup')
}
};

66 changes: 66 additions & 0 deletions routes/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

/**
* The initialization module for Neuola.
*
*/

var model = require('../my/model')
, async = require('async')
;

module.exports = function (req, res) {
model.User.find({role:0}).count(function (err, count) {
if (count == 0) {
function catalog(meta) {
var c = new model.Catalog(meta);
return function (callback) {
c.save(callback);
};
}
var tasks = {
admin: function (callback) {
var admin = new model.User({
name: 'admin',
password: 'admin',
role: 0,
description: '高级管理员',
verified: true
});
admin.save(function (err) {
if (err) {
res.render('res');
}
});
},
catalogExplore: catalog({
name: '精选',
description: '发现这个世界的故事。',
id: 'explore'
}),
catalogActivities: catalog({
name: '活动',
description: '正在进行的活动。',
id: 'news'
})
};
async.parallel(tasks, function (err, result) {
if (err) {
res.render('error', {
message: '初始化错误!',
link: '/'
});
} else {
res.render('info', {
message: '初始化成功!',
link: '/'
});
}
});
} else {
res.render('error', {
message: 'Nothing',
link: '/'
});
}
});
};
2 changes: 1 addition & 1 deletion routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.login = function login(req, res) {
if (user && ! user.verified) {
message = '用户尚未激活。';
}
common.error(res, message, '/user/register');
common.error(res, message, '/user/login');
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion views/admin/picture-edit.jade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.main-stage-inner
form(
action='#{actionUrl}'
action=_('#{actionUrl}')
method='POST'
enctype='multipart/form-data'
).form-horizontal
Expand Down
6 changes: 6 additions & 0 deletions views/catalog-ajax.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if posts.length > 0
.date #{posts[0].date.getMonth()}#{posts[0].date.getDate()}
.text 「文章」
a(href=_('/article/'+posts[0].url)) #{posts[0].title}
else
.no-result 还没有文章哦~
46 changes: 41 additions & 5 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,58 @@ block append head
height: $logo.height()
});

$('<div id="overlay"></div>').css({
$('<div></div>').css({
position: 'absolute',
left: $cover.css('left'),
top: $cover.css('top'),
backgroundColor: 'white',
opacity: '0.4',
opacity: '0.6',
width: '50%',
height: $cover.height() + 'px',
zIndex: 9,
borderRadius: '0 10px 10px 0'
}).appendTo($('.logo'));
borderRadius: '0 10px 10px 0',
boxShadow: '0 0 10px #ccc'
}).appendTo($('.overlay').parent());

var $box = $('<div class="popup">abc</div>').css({
position: 'absolute',
left: 100, top: 100,
zIndex: 20,
width: '250px', backgroundColor: 'white',
borderRadius: '0.3em',
boxShadow: '0 0 0.5em #ccc',
display: 'none'
}).appendTo(document.body).mouseover(function (event) {
clearTimeout($box.data('popover-timer'));
}).mouseleave(function (event) {
$box.fadeOut();
});

$('.navbar a.catalog').mouseover(function (event) {
var $this = $(this);
clearTimeout($box.data('popover-timer'));

$.get($this.attr('href')).success(function (data) {
$box.html(data);
});

var offset = $this.offset();
$box.clearQueue().animate({
top: offset.top + $this.outerHeight()+5,
left: offset.left-$box.width()/2+$this.outerWidth()/2
}).fadeIn();
}).mouseleave(function (event) {
var $this = $(this);
$box.data('popover-timer', setTimeout(function () {
$box.hide();
}, 1000));
});

});

block main-stage
.logo
#cover
#cover.overlay
h1 东大在线
form(action=_('/articles/'), method='GET')
.input-append
Expand Down
29 changes: 0 additions & 29 deletions views/no-interest.jade

This file was deleted.

12 changes: 6 additions & 6 deletions views/site.jade
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ block content
block navbar
li
a(href=_("/")) 主页
li
a(href=_("/catalog/explore")) 精选
li
a(href=_("/catalog/news")) 活动
a(href=_("/catalog/explore")).catalog 精选
li
a(href=_("/catalog/news")).catalog 活动
li
a(href=_("/about")) 关于

if session.user
a(href=_('/user/logout')).btn.pull-right 退出
if session.user
a(href=_('/user/logout')).btn.pull-right 退出

.main-stage.container
block main-stage

footer#footer.container
p.pull-right: a(href='http://github.com/yfwz100/neuola') 项目主页
p.pull-right: a(href='http://gitorious.org/neuola/node-site') 项目主页
p Neuola &copy; 东大在线

0 comments on commit 103b4a7

Please sign in to comment.