diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 5e25ce5c78..060373230f 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -52,7 +52,6 @@ var ajaxify = {}; templates.load_template(function() { exec_body_scripts(content); - ajaxify.enable(); if (callback) { callback(); } @@ -67,21 +66,8 @@ var ajaxify = {}; return false; } - ajaxify.enable = function() { - $('a').unbind('click', ajaxify.onclick).bind('click', ajaxify.onclick); - } - ajaxify.onclick = function(ev) { - if (this.href == window.location.href + "#") return; - var url = this.href.replace(rootUrl +'/', ''); - if (this.target !== '') return; - - if (!ev.ctrlKey && ev.which === 1) { - if (ajaxify.go(url)) { - ev.preventDefault(); - } - } } $('document').ready(function() { @@ -89,7 +75,19 @@ var ajaxify = {}; content = content || document.getElementById('content'); - ajaxify.enable(); + // Enhancing all anchors to ajaxify... + $(document.body).on('click', 'a', function(e) { + if (this.href == window.location.href + "#") return; + var url = this.href.replace(rootUrl +'/', ''); + + if (this.target !== '') return; + + if (!e.ctrlKey && e.which === 1) { + if (ajaxify.go(url)) { + e.preventDefault(); + } + } + }); }); diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 3c24122977..46febe9396 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -25,8 +25,8 @@ adminTools = document.getElementById('thread-tools'); app.enter_room(room); - set_up_posts(); + // Resetting thread state if (thread_state.locked === '1') set_locked_state(true); if (thread_state.deleted === '1') set_delete_state(true); if (thread_state.pinned === '1') set_pinned_state(true); @@ -221,6 +221,46 @@ }); }); + $('.container').on('click', '.post_reply', function() { + if (thread_state.locked !== '1') { + require(['composer'], function(cmp) { + cmp.push(tid); + }); + } + }); + + $('.post-container').on('click', '.quote', function() { + if (thread_state.locked !== '1') { + var pid = $(this).parents('li').attr('data-pid'); + + socket.once('api:posts.getRawPost', function(data) { + + quoted = '> ' + data.post.replace(/\n/g, '\n> ') + '\n\n'; + require(['composer'], function(cmp) { + cmp.push(tid, null, null, quoted); + }); + }); + socket.emit('api:posts.getRawPost', { pid: pid }); + } + }); + + $('.post-container').on('click', '.favourite', function() { + var ids = this.id.replace('favs_', '').split('_'), + pid = ids[0], + uid = ids[1]; + + if (thread_state.locked !== '1') { + var element = $(this).find('i'); + if(element.attr('class') == 'icon-star-empty') { + element.attr('class', 'icon-star'); + socket.emit('api:posts.favourite', {pid: pid, room_id: app.current_room}); + } + else { + element.attr('class', 'icon-star-empty'); + socket.emit('api:posts.unfavourite', {pid: pid, room_id: app.current_room}); + } + } + }); $('.post-container').delegate('.edit', 'click', function(e) { var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1]; @@ -316,7 +356,6 @@ socket.emit('api:post.privileges', data.posts[x].pid); } - set_up_posts(uniqueid); tempContainer.replaceWith(tempContainer.contents()); infiniteLoaderActive = false; @@ -416,53 +455,6 @@ user_rep.html(utotal+ ' '); } - - function set_up_posts(div) { - if (div == null) div = ''; - else div = '#' + div; - - jQuery(div + ' .post_reply').click(function() { - if (thread_state.locked !== '1') { - require(['composer'], function(cmp) { - cmp.push(tid); - }); - } - }); - - jQuery(div + ' .quote').click(function() { - if (thread_state.locked !== '1') { - var pid = $(this).parents('li').attr('data-pid'); - - socket.once('api:posts.getRawPost', function(data) { - - quoted = '> ' + data.post.replace(/\n/g, '\n> ') + '\n\n'; - require(['composer'], function(cmp) { - cmp.push(tid, null, null, quoted); - }); - }); - socket.emit('api:posts.getRawPost', { pid: pid }); - } - }); - - jQuery(div + ' .favourite').click(function() { - var ids = this.id.replace('favs_', '').split('_'), - pid = ids[0], - uid = ids[1]; - - if (thread_state.locked !== '1') { - var element = $(this).find('i'); - if(element.attr('class') == 'icon-star-empty') { - element.attr('class', 'icon-star'); - socket.emit('api:posts.favourite', {pid: pid, room_id: app.current_room}); - } - else { - element.attr('class', 'icon-star-empty'); - socket.emit('api:posts.unfavourite', {pid: pid, room_id: app.current_room}); - } - } - }); - } - function set_locked_state(locked, alert) { var threadReplyBtn = document.getElementById('post_reply'), postReplyBtns = document.querySelectorAll('#post-container .post_reply'), diff --git a/src/webserver.js b/src/webserver.js index a93c793947..37815614ad 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -284,7 +284,7 @@ var express = require('express'), }); break; default : - res.json({}); + res.json(404, { error: 'unrecognized API endpoint' }); break; } } @@ -300,7 +300,7 @@ var express = require('express'), if(data) res.send(data); else - res.send("Category doesn't exist!"); + res.send(404, "Category doesn't exist!"); }); }); @@ -309,7 +309,7 @@ var express = require('express'), if(data) res.send(data); else - res.send("Topic doesn't exist!"); + res.send(404, "Topic doesn't exist!"); }); }); @@ -318,7 +318,7 @@ var express = require('express'), if(data) res.send(data); else - res.send("Post doesn't exist!"); + res.send(404, "Post doesn't exist!"); }); }); @@ -632,4 +632,4 @@ var express = require('express'), }(WebServer)); server.listen(config.port); -global.server = server; \ No newline at end of file +global.server = server;