From b2bc967e9b63508590ab490717469841481e6d5a Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 1 May 2013 21:26:47 +0000 Subject: [PATCH] got ajaxify working with threads, some cleanup, fixed anon posting, got rid of a few more global.sockets calls --- public/src/ajaxify.js | 4 ++-- public/src/app.js | 6 +++++- public/src/templates.js | 9 +++++---- public/templates/home.tpl | 2 +- src/posts.js | 4 +--- src/topics.js | 4 ++-- src/webserver.js | 26 +++++++++++++++----------- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 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.js index 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.js index 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 file diff --git a/public/templates/home.tpl b/public/templates/home.tpl index e65f469776..b49f4c2e85 100644 --- a/public/templates/home.tpl +++ b/public/templates/home.tpl @@ -1,7 +1,7 @@