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 {
float: right;
padding-top: 2px;
margin-right: 30px;
width: 50%;
margin-right: 0px;
width: 40%;
.pull-right {
width: 100%;

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

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

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

@ -7,7 +7,7 @@
<link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<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="/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="/src/app.js"></script>
<script type="text/javascript" src="/src/templates.js"></script>

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

@ -13,12 +13,16 @@ marked.setOptions({
(function(Posts) {
Posts.get = function(callback, tid, current_user, start, end) {
if (start == null) start = 0;
if (end == null) end = start + 10;
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
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);
if(pids.length === 0 ){
callback(false);
return;
}
topics.markAsRead(tid, current_user);
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
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]);
}
// get all data for thread in asynchronous fashion
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
RDB.handle(err);
var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];
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) {
vote_data = fav_data;
generateThread();
});
RDB.multi()
.mget(content)
.mget(uid)
.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
};
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
vote_data = fav_data;
generateThread();
});
// 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]);
RDB.multi()
.mget(content)
.mget(uid)
.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_data = user_details;
generateThread();
user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details){
user_data = user_details;
generateThread();
});
});
});
});
});
}
user.getUserField(current_user, 'reputation', function(reputation){
viewer_data = {
reputation: reputation
};
generateThread();
});
function getUserReputation() {
user.getUserField(current_user, 'reputation', function(reputation){
viewer_data = {
reputation: reputation
};
generateThread();
});
}
}

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

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

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

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

Loading…
Cancel
Save