2012-03-31 06:32:09 -04:00
|
|
|
/*
|
2013-07-03 01:17:56 -04:00
|
|
|
* expand.js
|
2012-03-31 06:32:09 -04: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 08:27:24 -05:00
|
|
|
* Copyright (c) 2013 Czterooki <czterooki1337@gmail.com>
|
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2012-03-31 06:32:09 -04:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/expand.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
2013-08-11 17:59:17 -04:00
|
|
|
if($('span.omitted').length == 0)
|
|
|
|
return; // nothing to expand
|
2013-07-31 14:54:20 -04:00
|
|
|
|
2013-07-27 00:57:12 -04:00
|
|
|
var do_expand = function() {
|
2012-03-31 06:32:09 -04:00
|
|
|
$(this)
|
2013-07-03 01:17:56 -04:00
|
|
|
.html($(this).text().replace(_("Click reply to view."), '<a href="javascript:void(0)">'+_("Click to expand")+'</a>.'))
|
2012-03-31 06:32:09 -04:00
|
|
|
.find('a').click(function() {
|
|
|
|
var thread = $(this).parent().parent().parent();
|
|
|
|
var id = thread.attr('id').replace(/^thread_/, '');
|
|
|
|
$.ajax({
|
2013-08-05 06:17:01 -04:00
|
|
|
url: thread.find('p.intro a.post_no:first').attr('href'),
|
2012-03-31 06:32:09 -04:00
|
|
|
context: document.body,
|
|
|
|
success: function(data) {
|
|
|
|
var last_expanded = false;
|
|
|
|
$(data).find('div.post.reply').each(function() {
|
2013-12-25 12:12:00 -05:00
|
|
|
thread.find('div.hidden').remove();
|
2013-07-26 22:39:00 -04:00
|
|
|
var post_in_doc = thread.find('#' + $(this).attr('id'));
|
|
|
|
if(post_in_doc.length == 0) {
|
2012-03-31 06:32:09 -04:00
|
|
|
if(last_expanded) {
|
|
|
|
$(this).addClass('expanded').insertAfter(last_expanded).before('<br class="expanded">');
|
|
|
|
} else {
|
|
|
|
$(this).addClass('expanded').insertAfter(thread.find('div.post:first')).after('<br class="expanded">');
|
|
|
|
}
|
|
|
|
last_expanded = $(this);
|
2013-06-15 01:39:39 -04:00
|
|
|
$(document).trigger('new_post', this);
|
2013-07-31 00:39:00 -04:00
|
|
|
} else {
|
2013-07-26 22:39:00 -04:00
|
|
|
last_expanded = post_in_doc;
|
2012-03-31 06:32:09 -04:00
|
|
|
}
|
|
|
|
});
|
2013-07-03 01:17:56 -04:00
|
|
|
$('<span class="omitted"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
|
2012-03-31 06:32:09 -04:00
|
|
|
.insertAfter(thread.find('span.omitted').css('display', 'none'))
|
|
|
|
.click(function() {
|
|
|
|
thread.find('.expanded').remove();
|
|
|
|
$(this).prev().css('display', '');
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-07-27 00:57:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$('div.post.op span.omitted').each(do_expand);
|
|
|
|
|
2014-01-21 13:25:11 -05:00
|
|
|
$(document).on("new_post", function(e, post) {
|
2013-07-27 00:57:12 -04:00
|
|
|
if (!$(post).hasClass("reply")) {
|
|
|
|
$(post).find('div.post.op span.omitted').each(do_expand);
|
|
|
|
}
|
2012-03-31 06:32:09 -04:00
|
|
|
});
|
|
|
|
});
|