1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-01 12:05:37 +02:00
Marc Alexander b90a56a409 [ticket/10954] Join array of class names instead of creating a string
Previously the string for selecting the correct classes was created
directly. Due to that a subsequent comma had to be removed. By joining the
array of class names with a separator this can be omitted.

PHPBB3-10954
2012-12-15 23:23:32 +01:00

204 lines
5.3 KiB
JavaScript

(function($) { // Avoid conflicts with other libraries
"use strict";
// This callback will mark all forum icons read
phpbb.add_ajax_callback('mark_forums_read', function(res) {
var readTitle = res.NO_UNREAD_POSTS;
var unreadTitle = res.UNREAD_POSTS;
$('li.row').find('dl.forum_unread, dl.forum_unread_subforum, dl.forum_unread_locked').each(function() {
var currentObject = $(this);
if (currentObject.hasClass('forum_unread')) {
currentObject.removeClass('forum_unread').addClass('forum_read');
}
else if (currentObject.hasClass('forum_unread_subforum')) {
currentObject.removeClass('forum_unread_subforum').addClass('forum_read_subforum');
}
else {
currentObject.removeClass('forum_unread_locked').addClass('forum_read_locked');
}
currentObject.children('dt[title=' + unreadTitle + ']').attr('title', readTitle);
});
// Update mark forums read links
$('[data-ajax=mark_forums_read]').each(function() {
$(this).attr('href', res.U_MARK_FORUMS);
});
// Hide alert after 3 seconds
setTimeout(function () {
$('#darkenwrapper').trigger('click');
}, 3000);
});
// This callback will mark all topic icons read
phpbb.add_ajax_callback('mark_topics_read', function(res) {
var readTitle = res.NO_UNREAD_POSTS;
var unreadTitle = res.UNREAD_POSTS;
var iconsArray = {
'global_unread': 'global_read',
'announce_unread': 'announce_read',
'sticky_unread': 'sticky_read',
'topic_unread': 'topic_read'
};
var iconsState = ['', '_hot', '_hot_mine', '_locked', '_locked_mine', '_mine'];
var unreadClassSelectors = '';
var classArray = {};
var classNames = [];
$.each(iconsArray, function(unreadClass, readClass) {
$.each(iconsState, function(key, value) {
// Only topics can be hot
if ((value == '_hot' || value == '_hot_mine') && unreadClass != 'topic_unread') {
return true;
}
var currentClass = {};
currentClass[unreadClass + value] = readClass + value;
$.extend(classArray, currentClass);
classNames[classNames.length] = unreadClass;
});
});
unreadClassSelectors = '.' + classNames.join(',.');
$('li.row').find(unreadClassSelectors).each(function() {
var currentObject = $(this);
$.each(classArray, function(unreadClass, readClass) {
if (currentObject.hasClass(unreadClass)) {
currentObject.removeClass(unreadClass).addClass(readClass);
}
});
currentObject.children('dt[title=' + unreadTitle + ']').attr('title', readTitle);
});
// Remove link to first unread post
$('span.icon_topic_newest').each(function() {
$(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.
phpbb.add_ajax_callback('post_delete', function() {
var el = $(this),
post_id;
if (el.attr('data-refresh') === undefined)
{
post_id = el[0].href.split('&p=')[1];
var post = el.parents('#p' + post_id).css('pointer-events', 'none');
if (post.hasClass('bg1') || post.hasClass('bg2'))
{
var posts1 = post.nextAll('.bg1');
post.nextAll('.bg2').removeClass('bg2').addClass('bg1');
posts1.removeClass('bg1').addClass('bg2');
}
post.fadeOut(function() {
$(this).remove();
});
}
});
// This callback removes the approve / disapprove div or link.
phpbb.add_ajax_callback('post_approve', function(res) {
var remove = (res.approved) ? $(this) : $(this).parents('.post');
$(remove).css('pointer-events', 'none').fadeOut(function() {
$(this).remove();
});
});
// This removes the parent row of the link or form that fired the callback.
phpbb.add_ajax_callback('row_delete', function() {
$(this).parents('tr').remove();
});
// This handles friend / foe additions removals.
phpbb.add_ajax_callback('zebra', function(res) {
var zebra;
if (res.success) {
zebra = $('.zebra');
zebra.first().html(res.MESSAGE_TEXT);
zebra.not(':first').html(' ').prev().html(' ');
}
});
$('[data-ajax]').each(function() {
var $this = $(this),
ajax = $this.attr('data-ajax'),
fn;
if (ajax !== 'false')
{
fn = (ajax !== 'true') ? ajax : null;
phpbb.ajaxify({
selector: this,
refresh: $this.attr('data-refresh') !== undefined,
callback: fn
});
}
});
/**
* This simply appends #preview to the action of the
* QR action when you click the Full Editor & Preview button
*/
$('#qr_full_editor').click(function() {
$('#qr_postform').attr('action', function(i, val) {
return val + '#preview';
});
});
/**
* This AJAXifies the quick-mod tools. The reason it cannot be a standard
* callback / data attribute is that it requires filtering - some of the options
* can be ajaxified, while others cannot.
*/
phpbb.ajaxify({
selector: '#quickmodform',
refresh: true,
filter: function (data) {
var action = $('#quick-mod-select').val();
if (action === 'make_normal')
{
return $(this).find('select option[value="make_global"]').length > 0;
}
else if (action === 'lock' || action === 'unlock')
{
return true;
}
if (action === 'delete_topic' || action === 'make_sticky' || action === 'make_announce' || action === 'make_global') {
return true;
}
return false;
}
});
$('#quick-mod-select').change(function () {
$('#quickmodform').submit();
});
})(jQuery); // Avoid conflicts with other libraries