/****************************************************************
* Топиклист с управлением подписками
* © ForumD.ru, Герда
* 14.10.2020
****************************************************************/
$('.forum tr').each(function() {
if ($(this).hasClass('poll')) {
$(this).find('.icon').prepend('
');
}
else if ($(this).hasClass('isticky')) {
$(this).find('.icon').prepend('sticky_note_2
');
}
else if ($(this).hasClass('iclosed')) {
$(this).find('.icon').prepend('lock
');
}
else $(this).find('.icon').prepend('chat
');
});
$('.forum tr').append('Просмотры: Ответы: Ответы: Последнее сообщение: | ');
$('.forum tr .tcl .stickytext').each(function() {var move = $(this).parents('tr').find('.topicinfo .typecell');$(this).appendTo(move);});
$('.stickytext').each(function() {$(this).after('
');});
$('.forum tr .tcl .closedatafield').each(function() {var move = $(this).parents('tr').find('.topicinfo .typecell');$(this).appendTo(move);});
$('.closedatafield').each(function() {$(this).after('
');});
$('.forum tr .tcl .polltext').each(function() {var move = $(this).parents('tr').find('.topicinfo .typecell');$(this).appendTo(move);});
$('.polltext').each(function() {$(this).after('
');});
$('.forum tr .tc3').each(function() {var move = $(this).parents('tr').find('.topicinfo .statcell .view');$(this).contents().appendTo(move);});
$('.forum tr .tc2').each(function() {var move = $(this).parents('tr').find('.topicinfo .statcell .posts');$(this).contents().appendTo(move);});
$('.forum tr .tcr').each(function() {var move = $(this).parents('tr').find('.topicinfo .lastcell .lastp');$(this).contents().appendTo(move);});
$('.forum tr .tcl .newtext').each(function() {var move = $(this).parents('tr').find('.topicinfo .lastcell2');$(this).appendTo(move);});
$('.forum .newtext a').addClass('tip');
$('.newtext').each(function() {$(this).prepend('Перейти к непрочитанным:');});
if(GroupID == "3") {$('.forum tr').each(function() {$(this).find('.topicinfo .typecell').append('регистрация');});}
let cells = {};
let ids = [];
$('.forum table td.topicinfo').parent('tr').each(function() {
var id = $(this).find('.tcl a:first').attr('href');
if (!id) return true;
id = id.split('id=')[1];
cells[id] = $(this).find('.statcell');
ids.push(id);
});
if (ids.length) {
let count = {};
$.getJSON('/api.php?method=board.getSubscriptions&group_by=topic_id&topic_id=' + ids.join(','), function(data) {
for (let i in data.response) {
count[data.response[i].topic_id] = data.response[i].c;
}
for (let i in cells) {
let num = typeof count[i] != 'undefined' ? count[i] : 0;
cells[i].prepend('Подписки: ' + num + '');
}
});
}
if (GroupID != 3 && $('.forum').length)(function() {
var linkText = ['подписаться', 'отписаться'];
var linkData = ['subscribe', 'unsubscribe'];
var arrTopics = [];
var tstReady = false;
FORUM.subscribe = function(sel) {
sel = $(sel);
$.get(sel.attr('data'), function(data) {
if ($(data).find('#pun-message').length) return;
var sub = !sel.hasClass('un');
sel.toggleClass('un').html('' + linkText[+sub] + '').attr('data', function() {
return $(this).attr('data').replace(linkData[+!sub], linkData[+sub]);
}).attr('title', linkText[+sub]);
});
};
function tstSubsList() {
if (!tstReady) {
$().pun_mainReady(tstSubsList);
return;
}
$('.forum table:last .hasicon tr').map(function() {
var id = $(this).find('.tcl a:first').attr('href');
if (!id) return;
id = id.split('id=')[1], tst = $.inArray(id, arrTopics) != -1, un = (tst ? 'un' : '');
var a = '';
$(this).find('.topicinfo .typecell').append($(a).attr('title', linkText[+tst]).html('' + linkText[+tst] + ''));
});
};
function getSubscriptions(data) {
$(data).find('.hasicon tr').each(function() {
arrTopics.push($(this).find('.tcl a:first').attr('href').split('id=')[1]);
});
if ($(data).find('.pagelink:first a.next').length)
$.get($(data).find('.pagelink:first a.next').attr('href'), getSubscriptions);
else tstSubsList()
};
$.get('/search.php?action=show_subscriptions', getSubscriptions);
$().pun_mainReady(function() {
tstReady = true;
});
})();