[ticket/10954] Change behavior of marking topics/forums

It will now display a popup message for 3 seconds which will confirm the
taken action. The amount of DOM traversals have been significantly reduced
and jQuery.each is now used instead of for loops. Additionally, it is now
possible to click on the mark topics/forums read links without triggering
an AJAX error.

PHPBB3-10954
This commit is contained in:
Marc Alexander 2012-12-14 15:46:45 +01:00
parent 5919407a1d
commit 16c021e986
3 changed files with 79 additions and 40 deletions

View file

@ -63,10 +63,13 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
if ($request->is_ajax()) if ($request->is_ajax())
{ {
// Tell the ajax script what language vars need to be replaced // Tell the ajax script what language vars and URL need to be replaced
$data = array( $data = array(
'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'] 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '',
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
); );
$json_response = new phpbb_json_response(); $json_response = new phpbb_json_response();
$json_response->send($data); $json_response->send($data);
@ -326,10 +329,13 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
if ($request->is_ajax()) if ($request->is_ajax())
{ {
// Tell the ajax script what language vars need to be replaced // Tell the ajax script what language vars and URL need to be replaced
$data = array( $data = array(
'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'] 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '',
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
); );
$json_response = new phpbb_json_response(); $json_response = new phpbb_json_response();
$json_response->send($data); $json_response->send($data);

View file

@ -7,62 +7,92 @@ phpbb.add_ajax_callback('mark_forums_read', function(res) {
var read_title = res.NO_UNREAD_POSTS; var read_title = res.NO_UNREAD_POSTS;
var unread_title = res.UNREAD_POSTS; var unread_title = res.UNREAD_POSTS;
$('li.row dl.forum_unread').each(function(e) { $('li.row').find('dl.forum_unread, dl.forum_unread_subforum, dl.forum_unread_locked').each(function() {
var current_object = $(this); var current_object = $(this);
current_object.removeClass('forum_unread').addClass('forum_read');
if (current_object.hasClass('forum_unread'))
{
current_object.removeClass('forum_unread').addClass('forum_read');
}
else if (current_object.hasClass('forum_unread_subforum'))
{
current_object.removeClass('forum_unread_subforum').addClass('forum_read_subforum');
}
else
{
current_object.removeClass('forum_unread_locked').addClass('forum_read_locked');
}
current_object.children('dt[title=' + unread_title + ']').attr('title', read_title); current_object.children('dt[title=' + unread_title + ']').attr('title', read_title);
}); });
$('li.row dl.forum_unread_subforum').each(function(e) { // Update mark forums read links
var current_object = $(this); $('[data-ajax=mark_forums_read]').each(function() {
current_object.removeClass('forum_unread_subforum').addClass('forum_read_subforum'); $(this).attr('href', res.U_MARK_FORUMS);
current_object.children('dt[title=' + unread_title + ']').attr('title', read_title);
}); });
$('li.row dl.forum_unread_locked').each(function(e) { // Hide alert after 3 seconds
var current_object = $(this); setTimeout(function () {
current_object.removeClass('forum_unread_locked').addClass('forum_read_locked'); $('#darkenwrapper').trigger('click');
current_object.children('dt[title=' + unread_title + ']').attr('title', read_title); }, 3000);
});
}); });
// This callback will mark all topic icons read // This callback will mark all topic icons read
phpbb.add_ajax_callback('mark_topics_read', function(res) { phpbb.add_ajax_callback('mark_topics_read', function(res) {
var i,j;
var read_title = res.NO_UNREAD_POSTS; var read_title = res.NO_UNREAD_POSTS;
var unread_title = res.UNREAD_POSTS; var unread_title = res.UNREAD_POSTS;
var icons_array = [ var icons_array = {
['global_unread', 'global_read'], 'global_unread': 'global_read',
['announce_unread', 'announce_read'], 'announce_unread': 'announce_read',
['sticky_unread', 'sticky_read'], 'sticky_unread': 'sticky_read',
['topic_unread', 'topic_read'] 'topic_unread': 'topic_read'
]; };
var icons_state = ['', '_hot', '_hot_mine', '_locked', '_locked_mine', '_mine']; var icons_state = ['', '_hot', '_hot_mine', '_locked', '_locked_mine', '_mine'];
var unread_class_selectors = '';
var class_array = {};
// Make sure all icons are marked as read $.each(icons_array, function(unread_class, read_class) {
for (i = 0; i < icons_array.length; i++) $.each(icons_state, function(key, value) {
{
for (j = 0; j < icons_state.length; j++)
{
// Only topics can be hot // Only topics can be hot
if ((icons_state[j] == '_hot' || icons_state[j] == '_hot_mine') && icons_array[i][0] != 'topic_unread') if ((value == '_hot' || value == '_hot_mine') && unread_class != 'topic_unread')
{ {
continue; return true;
} }
var current_class = {};
current_class[unread_class + value] = read_class + value;
$.extend(class_array, current_class);
$('li.row dl.' + icons_array[i][0] + icons_state[j]).each(function(e) { unread_class_selectors += '.' + unread_class + value + ',';
var current_object = $(this); });
current_object.removeClass(icons_array[i][0] + icons_state[j]).addClass(icons_array[i][1] + icons_state[j]); });
current_object.children('dt[title=' + unread_title + ']').attr('title', read_title);
}); // Remove trailing comma
} unread_class_selectors = unread_class_selectors.substring(0, unread_class_selectors.length - 1);
}
$('li.row').find(unread_class_selectors).each(function() {
var current_object = $(this);
$.each(class_array, function(unread_class, read_class) {
if (current_object.hasClass(unread_class))
{
current_object.removeClass(unread_class).addClass(read_class);
}
});
current_object.children('dt[title=' + unread_title + ']').attr('title', read_title);
});
// Remove link to first unread post // Remove link to first unread post
$('span.icon_topic_newest').each(function(e) { $('span.icon_topic_newest').each(function() {
$(this).remove(); $(this).remove();
}); });
// Update mark topics read links
$('[data-ajax=mark_topics_read]').each(function() {
$(this).attr('href', res.U_MARK_TOPICS);
});
// Hide alert after 3 seconds
setTimeout(function () {
$('#darkenwrapper').trigger('click');
}, 3000);
}); });
// This callback finds the post from the delete link, and removes it. // This callback finds the post from the delete link, and removes it.

View file

@ -183,10 +183,13 @@ if ($mark_read == 'topics')
if ($request->is_ajax()) if ($request->is_ajax())
{ {
// Tell the ajax script what language vars need to be replaced // Tell the ajax script what language vars and URL need to be replaced
$data = array( $data = array(
'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'] 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics&mark_time=" . time()) : '',
'MESSAGE_TITLE' => $user->lang['INFORMATION'],
'MESSAGE_TEXT' => $user->lang['TOPICS_MARKED']
); );
$json_response = new phpbb_json_response(); $json_response = new phpbb_json_response();
$json_response->send($data); $json_response->send($data);