mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/12034] Move similar code in the two callbacks to separate function.
PHPBB3-12034
This commit is contained in:
parent
0c0375df65
commit
d76ec60ee1
1 changed files with 28 additions and 31 deletions
|
@ -109,22 +109,7 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, update_topic_links) {
|
||||||
// This callback will mark all notifications read
|
// This callback will mark all notifications read
|
||||||
phpbb.addAjaxCallback('notification.mark_all_read', function(res) {
|
phpbb.addAjaxCallback('notification.mark_all_read', function(res) {
|
||||||
if (typeof res.success !== 'undefined') {
|
if (typeof res.success !== 'undefined') {
|
||||||
var unreadRows = $('#notification_list li.bg2');
|
phpbb.markNotifications($('#notification_list li.bg2'), 0);
|
||||||
|
|
||||||
// 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.closeDarkenWrapper(3000);
|
phpbb.closeDarkenWrapper(3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -132,23 +117,35 @@ phpbb.addAjaxCallback('notification.mark_all_read', function(res) {
|
||||||
// This callback will mark a notification read
|
// This callback will mark a notification read
|
||||||
phpbb.addAjaxCallback('notification.mark_read', function(res) {
|
phpbb.addAjaxCallback('notification.mark_read', function(res) {
|
||||||
if (typeof res.success !== 'undefined') {
|
if (typeof res.success !== 'undefined') {
|
||||||
var el = $(this),
|
var unreadCount = Number($('#notification_list_button strong').html()) - 1;
|
||||||
unreadCountEl = $('#notification_list_button strong'),
|
phpbb.markNotifications($(this).parent('li.bg2'), unreadCount);
|
||||||
unreadCount = Number(unreadCountEl.html()),
|
}
|
||||||
link = el.siblings('a');
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
// Remove the unread status.
|
||||||
el.parent('li.bg2').removeClass('bg2');
|
el.removeClass('bg2');
|
||||||
el.remove();
|
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'));
|
link.attr('href', link.attr('data-real-url'));
|
||||||
// Update the unread count
|
});
|
||||||
unreadCountEl.html(--unreadCount);
|
|
||||||
|
// Update the unread count.
|
||||||
|
$('#notification_list_button strong').html(unreadCount);
|
||||||
// Remove the Mark all read link if there are no unread notifications.
|
// Remove the Mark all read link if there are no unread notifications.
|
||||||
if (!unreadCount) {
|
if (!unreadCount) {
|
||||||
$('#mark_all_notifications').remove();
|
$('#mark_all_notifications').remove();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
// This callback finds the post from the delete link, and removes it.
|
// This callback finds the post from the delete link, and removes it.
|
||||||
phpbb.addAjaxCallback('post_delete', function() {
|
phpbb.addAjaxCallback('post_delete', function() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue