Node.js based forum software built for the modern web
got ajaxify working with threads, some cleanup, fixed anon posting, got rid of a few more global.sockets calls
psychobunnyb2bc967e9b63
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex ac3d7d4db0..9646720521 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -22,8 +22,8 @@ var ajaxify = {};ajaxify.go = function(url, callback) {var url = url.replace(/\/$/, "");- var tpl_url = (url === '') ? 'home' : url;-+ var tpl_url = (url === '') ? 'home' : url.split('/')[0];+if (templates[tpl_url]) {window.history.pushState({}, url, "/" + url);diff --git a/public/src/app.js b/public/src/app.jsindex 20732a2b5a..1061b2d935 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -1,6 +1,8 @@var socket,config,- app = {};+ app = {},++ API_URL = null;// todo: cleanup,etc(function() {@@ -8,6 +10,8 @@ var socket,$.ajax({url: '/config.json?v=' + new Date().getTime(),success: function(data) {+ API_URL = data.api_url;+config = data;socket = io.connect('http://' + config.socket.address + config.socket.port? ':' + config.socket.port : '');diff --git a/public/src/templates.js b/public/src/templates.jsindex fe7036a778..7605f9191a 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -26,7 +26,7 @@ var templates = {};function init() {loadTemplates([- 'header', 'footer', 'register', 'home',+ 'header', 'footer', 'register', 'home', 'topic','login', 'reset', 'reset_code', 'account_settings','emails/reset', 'emails/reset_plaintext']);@@ -116,10 +116,11 @@ function load_template(callback) {rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : '');var url = location.href.replace(rootUrl +'/', '');- if (url == '') url = 'home';- jQuery.get('api/' + url, function(data) {+ url = (url === '') ? 'home' : url;++ jQuery.get(API_URL + url, function(data) {- document.getElementById('content').innerHTML = templates[url].parse(JSON.parse(data));+ document.getElementById('content').innerHTML = templates[url.split('/')[0]].parse(JSON.parse(data));if (callback) callback();});}\ No newline at end of filediff --git a/public/templates/home.tpl b/public/templates/home.tplindex e65f469776..b49f4c2e85 100644--- a/public/templates/home.tpl+++ b/public/templates/home.tpl@@ -1,7 +1,7 @@<button id="new_post" class="btn btn-primary btn-large">New Post</button><ul class="topic-container"><!-- BEGIN topics -->-<a href="topics/{topics.slug}"><li class="topic-row">+<a href="topic/{topics.slug}"><li class="topic-row"><h4>{topics.title}</h4><p>Posted {topics.relativeTime} by user {topics.uid}. {topics.post_count} posts.</p></li></a>diff --git a/src/posts.js b/src/posts.jsindex b3117b3286..07e8fc239a 100644--- a/src/posts.js+++ b/src/posts.js@@ -64,7 +64,7 @@ var RDB = require('./redis.js'),Posts.create(uid, content, function(pid) {RDB.rpush('tid:' + tid + ':posts', pid);- global.socket.emit('event:alert', {+ socket.emit('event:alert', {title: 'Reply Successful',message: 'You have successfully replied. Click here to view your reply.',type: 'notify',@@ -74,8 +74,6 @@ var RDB = require('./redis.js'),};Posts.create = function(uid, content, callback) {- console.log("global uid "+uid);-if (uid === null) return;RDB.incr('global:next_post_id', function(pid) {diff --git a/src/topics.js b/src/topics.jsindex aa41f8684e..15cadbb806 100644--- a/src/topics.js+++ b/src/topics.js@@ -96,7 +96,7 @@ var RDB = require('./redis.js'),Topics.post = function(uid, title, content, category) {if (uid === 0) {- global.socket.emit('event:alert', {+ socket.emit('event:alert', {title: 'Thank you for posting',message: 'Since you are unregistered, your post is awaiting approval. Click here to register now.',type: 'warning',@@ -145,7 +145,7 @@ var RDB = require('./redis.js'),RDB.lpush('uid:' + uid + ':topics', tid);- global.socket.emit('event:alert', {+ socket.emit('event:alert', {title: 'Thank you for posting',message: 'You have successfully posted. Click here to view your post.',type: 'notify',diff --git a/src/webserver.js b/src/webserver.jsindex e895b72200..740d0aefdf 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -69,32 +69,36 @@ var express = require('express'),});- // need a proper way to combine these two routes together- app.get('/topics/:topic_id', function(req, res) {+ 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('/topics/:topic_id/:slug', function(req, res) {- global.modules.topics.generate_topic_body(function(topic_body) {- res.send(templates['header'] + topic_body + templates['footer']);- }, req.params.topic_id)- });+ }, req.params.topic_id);+ }+ app.get('/topic/:topic_id', generate_topic_body);+ app.get('/topic/:topic_id*', generate_topic_body);- app.get('/api/:method', function(req, res) {+ function api_method(req, res) {switch(req.params.method) {case 'home' :global.modules.topics.get(function(data) {res.send(JSON.stringify(data));});break;+ case 'topic' :+ global.modules.posts.get(function(data) {+ res.send(JSON.stringify(data));+ }, req.params.id);+ break;default :res.send('{}');break;}- });+ }+ app.get('/api/:method', api_method);+ app.get('/api/:method/:id', api_method);+ app.get('/api/:method/:id*', api_method);app.get('/login', function(req, res) {res.send(templates['header'] + templates['login'] + templates['footer']);