From cb6f587f24aa530ee1e79d9c0ecb3201a9c3d667 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 23 Aug 2013 13:45:57 -0400 Subject: [PATCH] closes #197 --- public/src/ajaxify.js | 25 +++++++++++---------- public/src/app.js | 13 +++++------ public/src/forum/topic.js | 46 ++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 10f40b40f9..a18fe6abce 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -2,7 +2,7 @@ var ajaxify = {}; (function($) { - + var location = document.location || window.location, rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''), content = null; @@ -39,14 +39,14 @@ var ajaxify = {}; } var tpl_url = templates.get_custom_map(url.split('?')[0]); - + if (tpl_url == false && !templates[url]) { if(url === '' || url === '/') { tpl_url = 'home'; } else { tpl_url = url.split('/')[0].split('?')[0]; } - + } else if (templates[url]) { tpl_url = url; } @@ -67,9 +67,9 @@ var ajaxify = {}; if (callback) { callback(); } - + app.process_page(); - + jQuery('#content, #footer').stop(true, true).fadeIn(200, function() { if(window.location.hash) hash = window.location.hash; @@ -94,12 +94,15 @@ var ajaxify = {}; // Enhancing all anchors to ajaxify... $(document.body).on('click', 'a', function(e) { - if (this.href == window.location.href + "#") return; - if(this.href.slice(-1) === "#") return; - + + function hrefEmpty(href) { + return href == 'javascript:;' || href == window.location.href + "#" || href.slice(-1) === "#"; + } + + if(hrefEmpty(this.href)) return; var url = this.href.replace(rootUrl +'/', ''); - + if (this.target !== '') return; if (!e.ctrlKey && e.which === 1) { @@ -126,7 +129,7 @@ var ajaxify = {}; script.type = "text/javascript"; try { - script.appendChild(document.createTextNode(data)); + script.appendChild(document.createTextNode(data)); } catch(e) { script.text = data; } @@ -162,5 +165,5 @@ var ajaxify = {}; evalScript(scripts[i]); } }; - + }(jQuery)); \ No newline at end of file diff --git a/public/src/app.js b/public/src/app.js index 878e569800..27b8bc50a7 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -218,7 +218,6 @@ var socket, app.current_room = null; app.enter_room = function(room) { - if(socket) { if (app.current_room === room) return; @@ -334,7 +333,7 @@ var socket, if(data.posts.length) { app.createNewPosts(data); } - + if(callback) callback(data.posts); }); @@ -356,20 +355,20 @@ var socket, } if(!scrollTo.length && tid) { - + var intervalID = setInterval(function() { app.loadMorePosts(tid, function(posts) { scrollTo = $('#post_anchor_' + pid); - + if(tid && scrollTo.length) { - animateScroll(); + animateScroll(); } - + if(!posts.length || scrollTo.length) clearInterval(intervalID); }); }, 100); - + } else if(tid) { animateScroll(); } diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 41f6f4d7ad..c2a0a30479 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -9,12 +9,12 @@ pinned: templates.get('pinned') }, topic_name = templates.get('topic_name'); - + jQuery('document').ready(function() { app.addCommasToNumbers(); - + var room = 'topic_' + tid, adminTools = document.getElementById('thread-tools'); @@ -26,17 +26,12 @@ if (thread_state.pinned === '1') set_pinned_state(true); if (expose_tools === '1') { - var deleteThreadEl = document.getElementById('delete_thread'), - lockThreadEl = document.getElementById('lock_thread'), - pinThreadEl = document.getElementById('pin_thread'), - moveThreadEl = document.getElementById('move_thread'), - moveThreadModal = $('#move_thread_modal'); + var moveThreadModal = $('#move_thread_modal'); adminTools.style.visibility = 'inherit'; // Add events to the thread tools - deleteThreadEl.addEventListener('click', function(e) { - e.preventDefault(); + $('#delete_thread').on('click', function(e) { if (thread_state.deleted !== '1') { bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) { if (confirm) socket.emit('api:topic.delete', { tid: tid }); @@ -46,30 +41,31 @@ if (confirm) socket.emit('api:topic.restore', { tid: tid }); }); } - }, false); + return false; + }); - lockThreadEl.addEventListener('click', function(e) { - e.preventDefault(); + $('#lock_thread').on('click', function(e) { if (thread_state.locked !== '1') { socket.emit('api:topic.lock', { tid: tid }); } else { socket.emit('api:topic.unlock', { tid: tid }); } - }, false); + return false; + }); - pinThreadEl.addEventListener('click', function(e) { - e.preventDefault(); + $('#pin_thread').on('click', function(e) { if (thread_state.pinned !== '1') { socket.emit('api:topic.pin', { tid: tid }); } else { socket.emit('api:topic.unpin', { tid: tid }); } - }, false); + return false; + }); - moveThreadEl.addEventListener('click', function(e) { - e.preventDefault(); + $('#move_thread').on('click', function(e) { moveThreadModal.modal('show'); - }, false); + return false; + }); moveThreadModal.on('shown', function() { var loadingEl = document.getElementById('categories-loading'); @@ -195,7 +191,7 @@ }); } }); - + socket.emit('api:topic.followCheck', tid); if(followEl[0]) { followEl[0].addEventListener('click', function() { @@ -284,7 +280,7 @@ socket.emit('api:posts.delete', { pid: pid }) : socket.emit('api:posts.restore', { pid: pid }); } - }); + }); $('.post-container').delegate('.chat', 'click', function(e) { @@ -296,7 +292,7 @@ chatModal.show(); chat.bringModalToTop(chatModal); }); - + }); ajaxify.register_events([ @@ -372,7 +368,7 @@ var editedPostEl = document.getElementById('content_' + data.pid); var editedPostTitle = $('#topic_title_'+data.pid); - + if(editedPostTitle.length > 0) { editedPostTitle.fadeOut(250, function() { editedPostTitle.html(data.title); @@ -402,7 +398,7 @@ if (favEl) { favEl.className = 'icon-star-empty'; $(favEl).parent().removeClass('btn-warning'); - } + } } }); @@ -595,7 +591,7 @@ var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')), editEl = postEl.find('.edit'), deleteEl = postEl.find('.delete'); - + if (state) { editEl.removeClass('none'); deleteEl.removeClass('none');