mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-07 14:52:36 +02:00
Merge branch 'master' of github.com:psychobunny/node-forum
This commit is contained in:
@@ -169,12 +169,14 @@ footer.footer {
|
||||
margin-top: 15px;
|
||||
border-radius: 0 0 5px 5px;
|
||||
font-size: 10px;
|
||||
line-height: 18px;
|
||||
padding: 5px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
.post-content {
|
||||
min-height: 50px;
|
||||
padding: 2px 5px 0 5px;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.post-block {
|
||||
|
||||
@@ -26,7 +26,6 @@ var ajaxify = {};
|
||||
socket.emit('event:enter_room', 'global');
|
||||
current_room = 'global';
|
||||
}
|
||||
|
||||
|
||||
var url = url.replace(/\/$/, "");
|
||||
var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0];
|
||||
|
||||
@@ -7,7 +7,15 @@ var templates = {};
|
||||
//quick implementation because introducing a lib to handle several async callbacks
|
||||
if (callback == null && ready_callback) ready_callback();
|
||||
else ready_callback = callback;
|
||||
}
|
||||
};
|
||||
|
||||
templates.prepare = function(raw_tpl, data) {
|
||||
var template = {};
|
||||
template.html = raw_tpl;
|
||||
template.parse = parse;
|
||||
template.blocks = {};
|
||||
return template;
|
||||
};
|
||||
|
||||
function loadTemplates(templatesToLoad) {
|
||||
var timestamp = new Date().getTime();
|
||||
@@ -24,9 +32,10 @@ var templates = {};
|
||||
|
||||
template.prototype.parse = parse;
|
||||
template.prototype.html = String(html);
|
||||
|
||||
templates[file] = new template;
|
||||
template.prototype.blocks = {};
|
||||
|
||||
templates[file] = new template;
|
||||
|
||||
loaded--;
|
||||
if (loaded == 0) templates.ready();
|
||||
}).fail(function() {
|
||||
@@ -49,6 +58,8 @@ var templates = {};
|
||||
|
||||
//modified from https://github.com/psychobunny/dcp.templates
|
||||
var parse = function(data) {
|
||||
var self = this;
|
||||
|
||||
function replace(key, value, template) {
|
||||
var searchRegex = new RegExp('{' + key + '}', 'g');
|
||||
return template.replace(searchRegex, value);
|
||||
@@ -62,6 +73,8 @@ var templates = {};
|
||||
data = template.match(regex);
|
||||
if (data == null) return;
|
||||
|
||||
if (block !== undefined) self.blocks[block] = data[0];
|
||||
|
||||
data = data[0]
|
||||
.replace("<!-- BEGIN " + block + " -->", "")
|
||||
.replace("<!-- END " + block + " -->", "");
|
||||
|
||||
@@ -5,22 +5,22 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ul class="post-container container">
|
||||
<ul id="post-container" class="post-container container">
|
||||
<!-- BEGIN posts -->
|
||||
<li class="row">
|
||||
<div class="span1 profile-image-block">
|
||||
<div class="span1 profile-image-block visible-desktop">
|
||||
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>-->
|
||||
<img src="{posts.gravatar}" align="left" />
|
||||
<img src="{posts.gravatar}80" align="left" />
|
||||
<i class="icon-star"></i><span id="user_rep_{posts.uid}">{posts.user_rep}</span>
|
||||
</div>
|
||||
<div class="span11">
|
||||
<div class="post-block">
|
||||
<div id="content_{posts.pid}" class="post-content">{posts.content}</div>
|
||||
<div class="profile-block">
|
||||
posted by <strong>{posts.username}</strong> {posts.relativeTime}
|
||||
<img class="hidden-desktop" src="{posts.gravatar}10" align="left" /> posted by <strong>{posts.username}</strong> {posts.relativeTime}
|
||||
<span class="post-buttons">
|
||||
<div id="quote_{posts.pid}" class="quote"><i class="icon-quote-left"></i></div>
|
||||
<div id="favs_{posts.pid}_{posts.uid}" class="favourite"><span id="post_rep_{posts.pid}">{posts.post_rep}</span><i class="{posts.fav_star_class}"></i></div>
|
||||
<div id="quote_{posts.pid}" class="quote hidden-phone"><i class="icon-quote-left"></i></div>
|
||||
<div id="favs_{posts.pid}_{posts.uid}" class="favourite hidden-phone"><span id="post_rep_{posts.pid}">{posts.post_rep}</span><i class="{posts.fav_star_class}"></i></div>
|
||||
<div class="post_reply">Reply <i class="icon-reply"></i></div>
|
||||
</span>
|
||||
</div>
|
||||
@@ -63,6 +63,12 @@ socket.on('event:rep_down', function(data) {
|
||||
adjust_rep(-1, data.pid, data.uid);
|
||||
});
|
||||
|
||||
socket.on('event:new_post', function(data) {
|
||||
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
|
||||
|
||||
jQuery('<div></div>').appendTo("#post-container").hide().append(html).fadeIn('slow');
|
||||
});
|
||||
|
||||
function adjust_rep(value, pid, uid) {
|
||||
var post_rep = document.getElementById('post_rep_' + pid),
|
||||
user_rep = document.getElementById('user_rep_' + uid);
|
||||
|
||||
29
src/posts.js
29
src/posts.js
@@ -48,7 +48,7 @@ var RDB = require('./redis.js'),
|
||||
post_rep = replies[3];
|
||||
|
||||
user.get_user_postdetails(uid, function(user_details) {
|
||||
user.get_gravatars_by_uids(uid, 80, function(gravatars) {
|
||||
user.get_gravatars_by_uids(uid, '', function(gravatars) {
|
||||
var posts = [];
|
||||
var callbacks = content.length;
|
||||
|
||||
@@ -92,12 +92,38 @@ var RDB = require('./redis.js'),
|
||||
Posts.create(uid, tid, content, function(pid) {
|
||||
RDB.rpush('tid:' + tid + ':posts', pid);
|
||||
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Successful',
|
||||
message: 'You have successfully replied. Click here to view your reply.',
|
||||
type: 'notify',
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
user.get_user_postdetails([uid], function(user_details) {
|
||||
user.get_gravatars_by_uids([uid], 80, function(gravatars) {
|
||||
var timestamp = new Date().getTime();
|
||||
|
||||
socket.broadcast.to('topic_' + tid).emit('event:new_post', {
|
||||
'posts' : [
|
||||
{
|
||||
'pid' : pid,
|
||||
'content' : marked(content || ''),
|
||||
'uid' : uid,
|
||||
'username' : user_details.username[0] || 'anonymous',
|
||||
'user_rep' : user_details.rep[0] || 0,
|
||||
'post_rep' : 0,
|
||||
'gravatar' : gravatars[0],
|
||||
'timestamp' : timestamp,
|
||||
'relativeTime': utils.relativeTime(timestamp),
|
||||
'fav_star_class' :'icon-star-empty'
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@@ -117,7 +143,6 @@ var RDB = require('./redis.js'),
|
||||
|
||||
if (callback) callback(pid);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ passport.deserializeUser(function(uid, done) {
|
||||
res.send(templates['header'] + templates['403'] + templates['footer']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
|
||||
(function() {
|
||||
var routes = ['', 'login', 'register'];
|
||||
@@ -131,17 +133,14 @@ passport.deserializeUser(function(uid, done) {
|
||||
}
|
||||
}());
|
||||
|
||||
|
||||
function generate_topic_body(req, res) {
|
||||
global.modules.topics.generate_topic_body(function(topic_body) {
|
||||
res.send(templates['header'] + topic_body + templates['footer']);
|
||||
}, req.params.topic_id);
|
||||
}
|
||||
app.get('/topic/:topic_id', generate_topic_body);
|
||||
app.get('/topic/:topic_id*', generate_topic_body);
|
||||
// Complex Routes
|
||||
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
||||
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("' + 'topic/' + req.params.topic_id + '");});</script>' + templates['footer']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
||||
function api_method(req, res) {
|
||||
switch(req.params.method) {
|
||||
case 'home' :
|
||||
@@ -173,7 +172,7 @@ passport.deserializeUser(function(uid, done) {
|
||||
case 'topic' :
|
||||
global.modules.posts.get(function(data) {
|
||||
res.send(JSON.stringify(data));
|
||||
}, req.params.id, req.user.uid);
|
||||
}, req.params.id, req.user.uid || 0);
|
||||
break;
|
||||
default :
|
||||
res.send('{}');
|
||||
|
||||
Reference in New Issue
Block a user