diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index ac3d7d4db0..ac96a7d6be 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 === '' || 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 8b50d34af6..a45effa90d 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 : ''); @@ -78,14 +82,63 @@ var socket, } } - var post_window = null; - app.open_post_window = function() { + var post_window = null, + submit_post_btn = null, + post_title = null, + reply_title = null, + post_content = null; + + + app.open_post_window = function(post_mode, id, title) { + submit_post_btn = submit_post_btn || document.getElementById('submit_post_btn'); + post_title = post_title || document.getElementById('post_title'); + reply_title = reply_title || document.getElementById('reply_title'); + post_content = post_content || document.getElementById('post_content'); + + post_window = post_window || document.getElementById('post_window'); jQuery(post_window).slideToggle(250); - document.getElementById('post_title').focus(); + + if (post_mode == null || post_mode == 'topic') { + post_title.style.display = "block"; + reply_title.style.display = "none"; + post_title.focus(); + submit_post_btn.onclick = function() { + app.post_topic(); + } + } else { + post_title.style.display = "none"; + reply_title.style.display = "block"; + reply_title.innerHTML = 'You are replying to "' + title + '"'; + post_content.focus(); + submit_post_btn.onclick = function() { + app.post_reply(id) + } + } }; + app.post_reply = function(topic_id) { + var content = document.getElementById('post_content').value; + + if (content.length < 5) { + app.alert({ + title: 'Reply Failure', + message: 'You need to write more dude.', + type: 'error', + timeout: 2000 + }); + + return; + } + + socket.emit('api:posts.reply', { + 'topic_id' : topic_id, + 'content' : content + }); + jQuery(post_window).slideToggle(250); + + }; app.post_topic = function() { var title = document.getElementById('post_title').value, content = document.getElementById('post_content').value; @@ -95,10 +148,7 @@ var socket, title: 'Topic Post Failure', message: 'You need to write more dude.', type: 'error', - timeout: 2000, - clickfn: function() { - ajaxify.go('register'); - } + timeout: 2000 }); return; diff --git a/public/src/templates.js b/public/src/templates.js index fe7036a778..f18b1e50b6 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -1,9 +1,17 @@ var templates = {}; (function() { + var ready_callback; + + templates.ready = function(callback) { + //quick implementation because introducing a lib to handle several async callbacks + if (callback == null) ready_callback(); + else ready_callback = callback; + } function loadTemplates(templatesToLoad) { var timestamp = new Date().getTime(); + var loaded = templatesToLoad.length; for (var t in templatesToLoad) { (function(file) { @@ -18,6 +26,12 @@ var templates = {}; template.prototype.html = String(html); templates[file] = new template; + + loaded--; + if (loaded == 0) templates.ready(); + }).fail(function() { + loaded--; + if (loaded == 0) templates.ready(); }); }(templatesToLoad[t])); } @@ -26,7 +40,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 +130,10 @@ 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) { - - document.getElementById('content').innerHTML = templates[url].parse(JSON.parse(data)); + url = (url === '' || url === '/') ? 'home' : url; + + jQuery.get(API_URL + url, function(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/header.tpl b/public/templates/header.tpl index d18ac06159..a22c9e7e0a 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -90,10 +90,10 @@ border: 1px solid #eee; margin-top: 50px; } - .topic-container li.topic-row:nth-child(odd) { + .topic-container a:nth-child(odd) li.topic-row { background-color:#fdfdfd; } - .topic-container li.topic-row:nth-child(even) { + .topic-container a:nth-child(even) li.topic-row { background-color:#fff; } .topic-container li.topic-row { @@ -108,6 +108,35 @@ background-color: #eee; } + + + .post-container { + list-style-type: none; + padding: 0; + margin: 0; + border: 1px solid #eee; + + } + .post-container li.post-row:nth-child(odd) { + background-color:#fdfdfd; + } + .post-container li.post-row:nth-child(even) { + background-color:#fff; + } + .post-container li.post-row { + cursor: pointer; + border-bottom: 1px solid #eee; + padding: 10px; + } + .post-container li:last-child { + border-bottom: 0; + } + .post-container li.post-row:hover { + background-color: #eee; + } + + + #user_label img { border: 1px solid #999; margin-right: 8px; @@ -117,6 +146,11 @@ font-size: 12px; font-weight: bold; } + #reply_title { + font-size: 17px; + padding-top: 14px; + font-weight: 600; + } @@ -132,7 +166,7 @@ @@ -172,4 +207,5 @@
+
\ 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 @@