Post by Eton Bones on Apr 23, 2020 22:44:22 GMT -8
There's a plugin currently installed on this support forum that creates links in the thread participation dialogue so one can click and get a list of posts made by a particular person within the thread and I thought this was one of the most inventive plugin I'd ever seen. I was however disappointed that it didn't perform this great feature when clicking on thread listings not in a particular board (e.g threads returned from a search, recent forum threads, recent user threads, etc.) so I decided to try my hand at writing one that did.
(function enhance_thread_participants_dialog() {
/**
Description: Linkifies participation counts adjacent to user microprofiles in participation dialogue in order to display all the posts by that particular user made within that thread
**/
pb.data('proboards.thread') && pb.events.on('afterSearch', (function () {
let thread_id = null;
let $participant_dialog = $();
function linkify() {
(thread_id||(thread_id = pb.data('lm_thread_id'))) && $('#ui-dialog-title-thread-participants').html('Participants: ' + pb.item('thread', thread_id).subject.substr(0, 63));
$participant_dialog.find('.list-count:not(.clickable_participants) .microprofile-holder').each(function (j, d) {
const $d = $(d);
const $user_id = $d.find('.user-link, .deleted-micro-profile');
const $user_count = $d.find('.microprofile-count');
$user_id.length && (Number($user_count.html()) || 0) > 0 && (function () {
$user_count.html('<a href="' + pb.item('thread', thread_id).url + '?filters%5B%5D=post_created_by%3Aeq%3A' + ($user_id.hasClass('user-link') ? $user_id.idFromClass('user') : $user_id.find('.avatar-wrapper').idFromClass('avatar')) + '">' + $user_count.html() + '</a>')
})()
}).closest('.list-count').addClass('clickable_participants');
}
function addThreadListener() {
$(function () {
$('.clickable .thread-participants').on('click', function (e, x, d) {
thread_id = $(this).parents('[id^="thread-"]').attr('id').split('thread-')[1];
})
})
}
$(document).on('dialogopen.clickable_participants', "#thread-participants", function (event) {
$participant_dialog = $(event.target);
$participant_dialog.find('.ui-autosearch').on('autosearchaftersearch.clickable_participants', () => {
linkify()
}); linkify();
})
return addThreadListener(), addThreadListener;
})())
})()