diff options
author | Cesar G <prototech91@gmail.com> | 2013-11-24 09:09:48 -0800 |
---|---|---|
committer | Cesar G <prototech91@gmail.com> | 2013-12-30 11:12:15 -0800 |
commit | d76ec60ee15c1fafbb4212eda77b842e793108d0 (patch) | |
tree | 8ff92f10aed9045cfe21e28992a621ad0da1b3c3 /phpBB/styles | |
parent | 0c0375df6523ed4f3fbf7d53cee49b2caa8b692f (diff) | |
download | forums-d76ec60ee15c1fafbb4212eda77b842e793108d0.tar forums-d76ec60ee15c1fafbb4212eda77b842e793108d0.tar.gz forums-d76ec60ee15c1fafbb4212eda77b842e793108d0.tar.bz2 forums-d76ec60ee15c1fafbb4212eda77b842e793108d0.tar.xz forums-d76ec60ee15c1fafbb4212eda77b842e793108d0.zip |
[ticket/12034] Move similar code in the two callbacks to separate function.
PHPBB3-12034
Diffstat (limited to 'phpBB/styles')
-rw-r--r-- | phpBB/styles/prosilver/template/ajax.js | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index 38f9f80b44..1d70adc48d 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -109,22 +109,7 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, update_topic_links) { // This callback will mark all notifications read phpbb.addAjaxCallback('notification.mark_all_read', function(res) { if (typeof res.success !== 'undefined') { - var unreadRows = $('#notification_list li.bg2'); - - // Remove the unread status. - unreadRows.removeClass('bg2'); - unreadRows.find('a.mark_read').remove(); - - // Update the notification link to the real URL. - unreadRows.each(function() { - var link = $(this).find('a'); - link.attr('href', link.attr('data-real-url')); - }); - // Set the unread count to 0. - $('#notification_list_button strong').html(0); - // Remove the Mark all read link - $('#mark_all_notifications').remove(); - + phpbb.markNotifications($('#notification_list li.bg2'), 0); phpbb.closeDarkenWrapper(3000); } }); @@ -132,24 +117,36 @@ phpbb.addAjaxCallback('notification.mark_all_read', function(res) { // This callback will mark a notification read phpbb.addAjaxCallback('notification.mark_read', function(res) { if (typeof res.success !== 'undefined') { - var el = $(this), - unreadCountEl = $('#notification_list_button strong'), - unreadCount = Number(unreadCountEl.html()), - link = el.siblings('a'); - - // Remove the unread status. - el.parent('li.bg2').removeClass('bg2'); - el.remove(); - link.attr('href', link.attr('data-real-url')); - // Update the unread count - unreadCountEl.html(--unreadCount); - // Remove the Mark all read link if there are no unread notifications. - if (!unreadCount) { - $('#mark_all_notifications').remove(); - } + var unreadCount = Number($('#notification_list_button strong').html()) - 1; + phpbb.markNotifications($(this).parent('li.bg2'), unreadCount); } }); +/** + * Mark notification popup rows as read. + * + * @param {jQuery} el jQuery object(s) to mark read. + * @param {int} unreadCount The new unread notifications count. + */ +phpbb.markNotifications = function(el, unreadCount) { + // Remove the unread status. + el.removeClass('bg2'); + el.find('a.mark_read').remove(); + + // Update the notification link to the real URL. + el.each(function() { + var link = $(this).find('a'); + link.attr('href', link.attr('data-real-url')); + }); + + // Update the unread count. + $('#notification_list_button strong').html(unreadCount); + // Remove the Mark all read link if there are no unread notifications. + if (!unreadCount) { + $('#mark_all_notifications').remove(); + } +}; + // This callback finds the post from the delete link, and removes it. phpbb.addAjaxCallback('post_delete', function() { var el = $(this), |