From d8c9ec0d406147b4ac9631fcc7687073ee71ea8e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 22 Feb 2015 21:10:06 -0500 Subject: [PATCH] on click, topics are marked read from the unread page. Also fixed an issue where isPopState kept getting set to true, causing issues --- public/src/ajaxify.js | 1 + public/src/client/unread.js | 27 ++++++++++++++++++++------- public/src/modules/ajaxifyCache.js | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 8ba7fef1a6..7f99f3d2be 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -63,6 +63,7 @@ $(document).ready(function() { if (cache.get(url)) { return true; } else { cache.url = ajaxify.currentPage; + ajaxify.isPopState = false; } $(window).off('scroll'); diff --git a/public/src/client/unread.js b/public/src/client/unread.js index 994d4e1ddb..8a6df4f9cd 100644 --- a/public/src/client/unread.js +++ b/public/src/client/unread.js @@ -12,6 +12,8 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'], }); Unread.init = function() { + var topicsContainer = $('#topics-container'); + app.enterRoom('recent_posts'); $('#new-topics-alert').on('click', function() { @@ -42,7 +44,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'], app.alertSuccess('[[unread:topics_marked_as_read.success]]'); - $('#topics-container').empty(); + topicsContainer.empty(); $('#category-no-topics').removeClass('hidden'); $('.markread').addClass('hidden'); }); @@ -68,11 +70,22 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'], }); }); + topicsContainer.on('click', '.topic-title, .replies a', function(e) { + var tid = $(e.target).parents('[data-tid]').attr('data-tid'); + socket.emit('topics.markAsRead', [tid], function(err) { + if(err) { + return app.alertError(err.message); + } + + doneRemovingTids([tid]); + }); + }); + socket.emit('categories.get', onCategoriesLoaded); topicSelect.init(); - if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) { + if ($("body").height() <= $(window).height() && topicsContainer.children().length >= 20) { $('#load-more-btn').show(); } @@ -83,16 +96,16 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'], infinitescroll.init(loadMoreTopics); function loadMoreTopics(direction) { - if(direction < 0 || !$('#topics-container').length) { + if(direction < 0 || !topicsContainer.length) { return; } infinitescroll.loadMore('topics.loadMoreUnreadTopics', { - after: $('#topics-container').attr('data-nextstart') + after: topicsContainer.attr('data-nextstart') }, function(data, done) { if (data.topics && data.topics.length) { recent.onTopicsLoaded('unread', data.topics, true, done); - $('#topics-container').attr('data-nextstart', data.nextStart); + topicsContainer.attr('data-nextstart', data.nextStart); } else { done(); $('#load-more-btn').hide(); @@ -101,10 +114,10 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'], } }; - function doneRemovingTids(tids) { + function doneRemovingTids(tids, quiet) { removeTids(tids); - app.alertSuccess('[[unread:topics_marked_as_read.success]]'); + if (!quiet) { app.alertSuccess('[[unread:topics_marked_as_read.success]]'); } if (!$('#topics-container').children().length) { $('#category-no-topics').removeClass('hidden'); diff --git a/public/src/modules/ajaxifyCache.js b/public/src/modules/ajaxifyCache.js index eaa682b0da..1e5c63fa5c 100644 --- a/public/src/modules/ajaxifyCache.js +++ b/public/src/modules/ajaxifyCache.js @@ -15,11 +15,11 @@ define('ajaxifyCache', function() { Cache.get = function(url) { if (url === Cache.url && ajaxify.isPopState) { // Swap DOM elements - setTimeout(function() { + // setTimeout(function() { Cache.tempDOM = $('#content > *').detach(); $('#content').append(Cache.DOM); Cache.DOM = Cache.tempDOM; - }, 100); // 100ms for realism! :sunglasses: + // }, 100); // 100ms for realism! :sunglasses: // Set the values that normally get set on ajaxify Cache.url = ajaxify.currentPage;