From 9d5f6364ade6dc0082765e79487988b58c6a4394 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 16 May 2013 11:53:27 -0400 Subject: [PATCH 1/5] removed console.logs --- public/src/app.js | 1 + src/routes/user.js | 6 ++---- src/user.js | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index a82c730ee2..b8d2afd710 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -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(); }); }); diff --git a/src/routes/user.js b/src/routes/user.js index caff2c837d..6e74a88653 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -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 diff --git a/src/user.js b/src/user.js index e378f40bb4..6cc5a39dbc 100644 --- a/src/user.js +++ b/src/user.js @@ -80,7 +80,7 @@ var config = require('../config.js'), for(var i=0,ii=fields.length; i Date: Thu, 16 May 2013 12:13:39 -0400 Subject: [PATCH 2/5] fix crash when you go to /topics/nonexistant --- public/src/templates.js | 7 +++++++ src/posts.js | 6 ++++++ src/topics.js | 6 ++++++ src/webserver.js | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/public/src/templates.js b/public/src/templates.js index 3c0f40531d..c2b75a4779 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -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]) { diff --git a/src/posts.js b/src/posts.js index 42a98c83e8..9b56403f68 100644 --- a/src/posts.js +++ b/src/posts.js @@ -12,6 +12,7 @@ marked.setOptions({ (function(Posts) { Posts.get = function(callback, tid, current_user, start, end) { + if (start == null) start = 0; if (end == null) end = start + 10; @@ -74,6 +75,11 @@ marked.setOptions({ // 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; + } var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = []; diff --git a/src/topics.js b/src/topics.js index ead41792d1..0e2efd92d5 100644 --- a/src/topics.js +++ b/src/topics.js @@ -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 = [], diff --git a/src/webserver.js b/src/webserver.js index 3de6acdc98..4202bfb575 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -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; From 96df6abe85d720ef978ff3eeb9ba64301af6cab7 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 16 May 2013 12:21:13 -0400 Subject: [PATCH 3/5] broken posts --- src/posts.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/posts.js b/src/posts.js index 9b56403f68..2c74859dcb 100644 --- a/src/posts.js +++ b/src/posts.js @@ -75,12 +75,7 @@ marked.setOptions({ // 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; - } - + var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = []; for (var i=0, ii=pids.length; i Date: Thu, 16 May 2013 12:27:50 -0400 Subject: [PATCH 4/5] fixed an issue in bootstrap.js causing ctrl-click to not work. removed ctrl-click / middle click simulation code in ajaxify. am currently using unminified bootstrap TODO minifiy fixed version; --- public/css/style.less | 4 ++-- public/src/ajaxify.js | 20 +++++--------------- public/templates/header.tpl | 2 +- public/vendor/bootstrap/js/bootstrap.js | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/public/css/style.less b/public/css/style.less index 9de2532e5e..4f2c7f3125 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -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%; diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 2361b0c0bd..94074c825f 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -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 diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 252611a734..cf4984bdbf 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -7,7 +7,7 @@ - + diff --git a/public/vendor/bootstrap/js/bootstrap.js b/public/vendor/bootstrap/js/bootstrap.js index c298ee42e3..f6a61079df 100644 --- a/public/vendor/bootstrap/js/bootstrap.js +++ b/public/vendor/bootstrap/js/bootstrap.js @@ -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() }) From 4cf0af055688388345712c9282d9870bc83e392d Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 16 May 2013 12:47:21 -0400 Subject: [PATCH 5/5] fixed topics --- src/posts.js | 159 ++++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 73 deletions(-) diff --git a/src/posts.js b/src/posts.js index 2c74859dcb..403461a56e 100644 --- a/src/posts.js +++ b/src/posts.js @@ -18,7 +18,10 @@ marked.setOptions({ 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 +74,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