got ajaxify working with threads, some cleanup, fixed anon posting, got rid of a few more global.sockets calls

v1.18.x
psychobunny 12 years ago
parent 6471109a25
commit b2bc967e9b

@ -22,7 +22,7 @@ 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);

@ -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 : '');

@ -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;
document.getElementById('content').innerHTML = templates[url].parse(JSON.parse(data));
jQuery.get(API_URL + url, function(data) {
document.getElementById('content').innerHTML = templates[url.split('/')[0]].parse(JSON.parse(data));
if (callback) callback();
});
}

@ -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>

@ -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) {

@ -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',

@ -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']);

Loading…
Cancel
Save