Merge branch 'master' of github.com:psychobunny/node-forum

v1.18.x
Julian Lam 12 years ago
commit e256ee99f7

@ -205,8 +205,8 @@ footer.footer {
.latest-post { .latest-post {
float: right; float: right;
padding-top: 2px; padding-top: 2px;
margin-right: 30px; margin-right: 0px;
width: 50%; width: 40%;
.pull-right { .pull-right {
width: 100%; width: 100%;

@ -21,12 +21,11 @@ var ajaxify = {};
window.onpopstate = function(event) { window.onpopstate = function(event) {
// "quiet": If set to true, will not call pushState
if (event !== null && event.state && event.state.url !== undefined) ajaxify.go(event.state.url, null, null, true); if (event !== null && event.state && event.state.url !== undefined) ajaxify.go(event.state.url, null, null, true);
}; };
ajaxify.go = function(url, callback, template, quiet) { ajaxify.go = function(url, callback, template, quiet) {
// "quiet": If set to true, will not call pushState
// leave room and join global // leave room and join global
app.enter_room('global'); app.enter_room('global');
@ -61,9 +60,6 @@ var ajaxify = {};
jQuery('#content, #footer').fadeIn(200); jQuery('#content, #footer').fadeIn(200);
}, url, template); }, url, template);
return true;
} else {
document.location.href = url;
return true; return true;
} }
@ -71,26 +67,20 @@ var ajaxify = {};
} }
ajaxify.enable = function() { ajaxify.enable = function() {
$('a').unbind('mouseup', ajaxify.onmouseup).bind('mouseup', ajaxify.onmouseup);
$('a').unbind('click', ajaxify.onclick).bind('click', ajaxify.onclick); $('a').unbind('click', ajaxify.onclick).bind('click', ajaxify.onclick);
} }
ajaxify.onmouseup = function(ev) { ajaxify.onclick = function(ev) {
if (this.href == window.location.href + "#") return; if (this.href == window.location.href + "#") return;
var url = this.href.replace(rootUrl +'/', ''); var url = this.href.replace(rootUrl +'/', '');
if (!ev.ctrlKey && ev.which === 1) { if (!ev.ctrlKey && ev.which === 1) {
if (ajaxify.go(url)) ev.preventDefault(); if (ajaxify.go(url)) {
} else if ((ev.ctrlKey && ev.which === 1) || ev.which === 2) { ev.preventDefault();
window.open(this.href, '_blank'); }
ev.preventDefault();
} }
} }
ajaxify.onclick = function(ev) {
ev.preventDefault();
}
$('document').ready(function() { $('document').ready(function() {
if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers

@ -36,6 +36,7 @@ var socket,
$('#disconnect-modal').show(); $('#disconnect-modal').show();
$('#reload-button').on('click',function(){ $('#reload-button').on('click',function(){
$('#disconnect-modal').hide(); $('#disconnect-modal').hide();
console.log(window.location.href);
window.location.reload(); window.location.reload();
}); });
}); });

@ -40,6 +40,7 @@ var templates = {};
for (var t in templatesToLoad) { for (var t in templatesToLoad) {
(function(file) { (function(file) {
$.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) { $.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {
var template = function() { var template = function() {
this.toString = function() { this.toString = function() {
return this.html; return this.html;
@ -168,6 +169,12 @@ function load_template(callback, url, template) {
jQuery.get(API_URL + url, function(data) { jQuery.get(API_URL + url, function(data) {
console.log(data);
if(!data) {
window.location.href = '/403';
return;
}
var tpl = templates.get_custom_map(url); var tpl = templates.get_custom_map(url);
if (tpl == false && !templates[url]) { if (tpl == false && !templates[url]) {

@ -7,7 +7,7 @@
<link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen"> <link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="/vendor/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="/vendor/fontawesome/css/font-awesome.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script> <script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/src/app.js"></script> <script type="text/javascript" src="/src/app.js"></script>
<script type="text/javascript" src="/src/templates.js"></script> <script type="text/javascript" src="/src/templates.js"></script>

@ -788,7 +788,7 @@
/* APPLY TO STANDARD DROPDOWN ELEMENTS /* APPLY TO STANDARD DROPDOWN ELEMENTS
* =================================== */ * =================================== */
$(document) $('.dropdown')
.on('click.dropdown.data-api', clearMenus) .on('click.dropdown.data-api', clearMenus)
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('click.dropdown-menu', function (e) { e.stopPropagation() }) .on('click.dropdown-menu', function (e) { e.stopPropagation() })

@ -13,12 +13,16 @@ marked.setOptions({
(function(Posts) { (function(Posts) {
Posts.get = function(callback, tid, current_user, start, end) { Posts.get = function(callback, tid, current_user, start, end) {
if (start == null) start = 0; if (start == null) start = 0;
if (end == null) end = start + 10; if (end == null) end = start + 10;
var post_data, user_data, thread_data, vote_data, viewer_data; var post_data, user_data, thread_data, vote_data, viewer_data;
topics.markAsRead(tid, current_user); getTopicPosts();
getUserReputation();
//compile thread after all data is asynchronously called //compile thread after all data is asynchronously called
function generateThread() { function generateThread() {
@ -71,84 +75,94 @@ marked.setOptions({
}); });
} }
function getTopicPosts() {
// get all data for thread in asynchronous fashion
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
RDB.handle(err);
// get all data for thread in asynchronous fashion if(pids.length === 0 ){
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) { callback(false);
RDB.handle(err); return;
}
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = []; topics.markAsRead(tid, current_user);
for (var i=0, ii=pids.length; i<ii; i++) {
content.push('pid:' + pids[i] + ':content');
uid.push('pid:' + pids[i] + ':uid');
timestamp.push('pid:' + pids[i] + ':timestamp');
post_rep.push('pid:' + pids[i] + ':rep');
editor.push('pid:' + pids[i] + ':editor');
editTime.push('pid:' + pids[i] + ':edited');
deleted.push('pid:' + pids[i] + ':deleted');
pid.push(pids[i]);
}
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) { var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
vote_data = fav_data;
generateThread();
});
RDB.multi() for (var i=0, ii=pids.length; i<ii; i++) {
.mget(content) content.push('pid:' + pids[i] + ':content');
.mget(uid) uid.push('pid:' + pids[i] + ':uid');
.mget(timestamp) timestamp.push('pid:' + pids[i] + ':timestamp');
.mget(post_rep) post_rep.push('pid:' + pids[i] + ':rep');
.get('tid:' + tid + ':title') editor.push('pid:' + pids[i] + ':editor');
.get('tid:' + tid + ':locked') editTime.push('pid:' + pids[i] + ':edited');
.get('tid:' + tid + ':category_name') deleted.push('pid:' + pids[i] + ':deleted');
.get('tid:' + tid + ':category_slug') pid.push(pids[i]);
.get('tid:' + tid + ':deleted') }
.get('tid:' + tid + ':pinned')
.mget(editor)
.mget(editTime)
.mget(deleted)
.exec(function(err, replies) {
post_data = {
pid: pids,
content: replies[0],
uid: replies[1],
timestamp: replies[2],
reputation: replies[3],
editor: replies[10],
editTime: replies[11],
deleted: replies[12]
};
thread_data = { Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
topic_name: replies[4], vote_data = fav_data;
locked: replies[5] || 0, generateThread();
category_name: replies[6], });
category_slug: replies[7],
deleted: replies[8] || 0,
pinned: replies[9] || 0
};
// Add any editors to the user_data object RDB.multi()
for(var x=0,numPosts=replies[10].length;x<numPosts;x++) { .mget(content)
if (replies[10][x] !== null && post_data.uid.indexOf(replies[10][x]) === -1) { .mget(uid)
post_data.uid.push(replies[10][x]); .mget(timestamp)
.mget(post_rep)
.get('tid:' + tid + ':title')
.get('tid:' + tid + ':locked')
.get('tid:' + tid + ':category_name')
.get('tid:' + tid + ':category_slug')
.get('tid:' + tid + ':deleted')
.get('tid:' + tid + ':pinned')
.mget(editor)
.mget(editTime)
.mget(deleted)
.exec(function(err, replies) {
post_data = {
pid: pids,
content: replies[0],
uid: replies[1],
timestamp: replies[2],
reputation: replies[3],
editor: replies[10],
editTime: replies[11],
deleted: replies[12]
};
thread_data = {
topic_name: replies[4],
locked: replies[5] || 0,
category_name: replies[6],
category_slug: replies[7],
deleted: replies[8] || 0,
pinned: replies[9] || 0
};
// Add any editors to the user_data object
for(var x=0,numPosts=replies[10].length;x<numPosts;x++) {
if (replies[10][x] !== null && post_data.uid.indexOf(replies[10][x]) === -1) {
post_data.uid.push(replies[10][x]);
}
} }
}
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){ user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
user_data = user_details; user_data = user_details;
generateThread(); generateThread();
});
}); });
}); });
}); }
user.getUserField(current_user, 'reputation', function(reputation){ function getUserReputation() {
viewer_data = { user.getUserField(current_user, 'reputation', function(reputation){
reputation: reputation viewer_data = {
}; reputation: reputation
generateThread(); };
}); generateThread();
});
}
} }

@ -101,8 +101,6 @@ var user = require('./../user.js'),
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif']; var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
var type = req.files.userPhoto.type; var type = req.files.userPhoto.type;
console.log(req.files.userPhoto);
if(allowedTypes.indexOf(type) === -1) { if(allowedTypes.indexOf(type) === -1) {
res.send({ res.send({
error: 'Allowed image types are png, jpg and gif!' error: 'Allowed image types are png, jpg and gif!'
@ -284,9 +282,9 @@ var user = require('./../user.js'),
user.getUserData(uid, function(data) { user.getUserData(uid, function(data) {
if(data) { if(data) {
console.log(data.joindate);
data.joindate = utils.relativeTime(data.joindate); data.joindate = utils.relativeTime(data.joindate);
console.log(data.joindate);
if(!data.birthday) if(!data.birthday)
data.age = ''; data.age = '';
else else

@ -20,6 +20,12 @@ var RDB = require('./redis.js'),
var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid'; var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';
RDB.smembers(range_var, function(err, tids) { RDB.smembers(range_var, function(err, tids) {
if(tids.length === 0) {
callback(false);
return;
}
var title = [], var title = [],
uid = [], uid = [],
timestamp = [], timestamp = [],

@ -80,7 +80,7 @@ var config = require('../config.js'),
for(var i=0,ii=fields.length; i<ii; ++i) { for(var i=0,ii=fields.length; i<ii; ++i) {
key = fields[i]; key = fields[i];
if(data[key] !== undefined) { if(data[key] !== undefined) {
console.log(data[key]);
User.setUserField(uid, key, data[key]); User.setUserField(uid, key, data[key]);
if(key === 'email') { if(key === 'email') {

@ -154,26 +154,46 @@ var express = require('express'),
break; break;
case 'topic' : case 'topic' :
posts.get(function(data) { posts.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0); }, req.params.id, (req.user) ? req.user.uid : 0);
break; break;
case 'category' : case 'category' :
topics.get(function(data) { topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0); }, req.params.id, (req.user) ? req.user.uid : 0);
break; break;
case 'latest' : case 'latest' :
topics.get(function(data) { topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
case 'popular' : case 'popular' :
topics.get(function(data) { topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
case 'active' : case 'active' :
topics.get(function(data) { topics.get(function(data) {
if(!data) {
res.send(false);
return;
}
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;

Loading…
Cancel
Save