2012-03-31 21:32:09 +11:00
|
|
|
/*
|
2013-07-03 01:17:56 -04:00
|
|
|
* expand.js
|
2012-03-31 21:32:09 +11:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/expand.js
|
|
|
|
*
|
|
|
|
* Released under the MIT license
|
2013-07-31 00:39:00 -04:00
|
|
|
* Copyright (c) 2012-2013 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 14:27:24 +01:00
|
|
|
* Copyright (c) 2013 Czterooki <czterooki1337@gmail.com>
|
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2012-03-31 21:32:09 +11:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/expand.js';
|
|
|
|
*/
|
|
|
|
|
2024-08-29 17:40:46 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
if ($('span.omitted').length === 0) {
|
|
|
|
// Nothing to expand.
|
|
|
|
return;
|
|
|
|
}
|
2013-07-31 14:54:20 -04:00
|
|
|
|
2024-08-29 17:40:46 +02:00
|
|
|
let doExpand = function() {
|
2012-03-31 21:32:09 +11:00
|
|
|
$(this)
|
2024-08-29 18:02:10 +02:00
|
|
|
.html($(this).text().concat(' <a href="javascript:void(0)">' + _('Click to expand') + '</a>.'))
|
2024-08-29 18:08:00 +02:00
|
|
|
.find('a').click(window.expandFun = function() {
|
2024-08-29 17:40:46 +02:00
|
|
|
let thread = $(this).parents('[id^="thread_"]');
|
2012-03-31 21:32:09 +11:00
|
|
|
$.ajax({
|
2013-08-05 06:17:01 -04:00
|
|
|
url: thread.find('p.intro a.post_no:first').attr('href'),
|
2012-03-31 21:32:09 +11:00
|
|
|
context: document.body,
|
|
|
|
success: function(data) {
|
2024-08-29 17:40:46 +02:00
|
|
|
let lastExpanded = false;
|
2012-03-31 21:32:09 +11:00
|
|
|
$(data).find('div.post.reply').each(function() {
|
2013-12-25 18:12:00 +01:00
|
|
|
thread.find('div.hidden').remove();
|
2024-08-29 17:40:46 +02:00
|
|
|
let postInDoc = thread.find('#' + $(this).attr('id'));
|
|
|
|
if (postInDoc.length === 0) {
|
|
|
|
if (lastExpanded) {
|
|
|
|
$(this).addClass('expanded').insertAfter(lastExpanded).before('<br class="expanded">');
|
2012-03-31 21:32:09 +11:00
|
|
|
} else {
|
2024-08-29 18:02:10 +02:00
|
|
|
let opBr = thread.find('div.post').first().next();
|
|
|
|
$(this).addClass('expanded').insertAfter(opBr).after('<br class="expanded">');
|
2012-03-31 21:32:09 +11:00
|
|
|
}
|
2024-08-29 17:40:46 +02:00
|
|
|
lastExpanded = $(this);
|
2013-06-15 01:39:39 -04:00
|
|
|
$(document).trigger('new_post', this);
|
2013-07-31 00:39:00 -04:00
|
|
|
} else {
|
2024-08-29 17:40:46 +02:00
|
|
|
lastExpanded = postInDoc;
|
2012-03-31 21:32:09 +11:00
|
|
|
}
|
|
|
|
});
|
2024-08-29 17:40:46 +02:00
|
|
|
|
2014-08-10 20:55:37 +02:00
|
|
|
|
2024-09-04 15:13:06 +02:00
|
|
|
thread.find('span.omitted').css('display', 'none');
|
2014-08-10 20:55:37 +02:00
|
|
|
|
|
|
|
$('<span class="omitted hide-expanded"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
|
|
|
|
.insertAfter(thread.find('.op div.body, .op span.omitted').last())
|
2012-03-31 21:32:09 +11:00
|
|
|
.click(function() {
|
|
|
|
thread.find('.expanded').remove();
|
2024-08-29 17:40:46 +02:00
|
|
|
let parent = $(this).parent();
|
2024-09-04 15:13:06 +02:00
|
|
|
parent.find('.omitted:not(.hide-expanded)').css('display', '');
|
|
|
|
parent.find('.hide-expanded').remove();
|
2012-03-31 21:32:09 +11:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-07-27 00:57:12 -04:00
|
|
|
}
|
|
|
|
|
2024-08-29 17:40:46 +02:00
|
|
|
$('div.post.op span.omitted').each(doExpand);
|
2013-07-27 00:57:12 -04:00
|
|
|
|
2024-09-04 15:13:06 +02:00
|
|
|
$(document).on('new_post', function(e, post) {
|
|
|
|
if (!$(post).hasClass('reply')) {
|
2024-08-29 17:40:46 +02:00
|
|
|
$(post).find('div.post.op span.omitted').each(doExpand);
|
2013-07-27 00:57:12 -04:00
|
|
|
}
|
2012-03-31 21:32:09 +11:00
|
|
|
});
|
|
|
|
});
|