1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 07:30:10 +01:00
vichan/js/expand.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

2012-03-31 12:32:09 +02:00
/*
2013-07-03 07:17:56 +02:00
* expand.js
2012-03-31 12:32:09 +02:00
* https://github.com/savetheinternet/Tinyboard/blob/master/js/expand.js
*
* Released under the MIT license
2013-07-31 06:39:00 +02:00
* Copyright (c) 2012-2013 Michael Save <savetheinternet@tinyboard.org>
* Copyright (c) 2013 Czterooki <czterooki1337@gmail.com>
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
2012-03-31 12:32:09 +02:00
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/expand.js';
*
*/
$(document).ready(function(){
if($('span.omitted').length == 0)
return; // nothing to expand
2013-07-27 06:57:12 +02:00
var do_expand = function() {
2012-03-31 12:32:09 +02:00
$(this)
2013-07-03 07:17:56 +02:00
.html($(this).text().replace(_("Click reply to view."), '<a href="javascript:void(0)">'+_("Click to expand")+'</a>.'))
2014-08-10 20:55:37 +02:00
.find('a').click(window.expand_fun = function() {
var thread = $(this).parents('[id^="thread_"]');
2012-03-31 12:32:09 +02:00
var id = thread.attr('id').replace(/^thread_/, '');
$.ajax({
url: thread.find('p.intro a.post_no:first').attr('href'),
2012-03-31 12:32:09 +02:00
context: document.body,
success: function(data) {
var last_expanded = false;
$(data).find('div.post.reply').each(function() {
thread.find('div.hidden').remove();
var post_in_doc = thread.find('#' + $(this).attr('id'));
if(post_in_doc.length == 0) {
2012-03-31 12:32:09 +02: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);
$(document).trigger('new_post', this);
2013-07-31 06:39:00 +02:00
} else {
last_expanded = post_in_doc;
2012-03-31 12:32:09 +02:00
}
});
2014-08-10 20:55:37 +02:00
thread.find("span.omitted").css('display', 'none');
$('<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 12:32:09 +02:00
.click(function() {
thread.find('.expanded').remove();
2014-08-10 20:55:37 +02:00
$(this).parent().find(".omitted:not(.hide-expanded)").css('display', '');
$(this).parent().find(".hide-expanded").remove();
2012-03-31 12:32:09 +02:00
});
}
});
});
2013-07-27 06:57:12 +02:00
}
$('div.post.op span.omitted').each(do_expand);
$(document).on("new_post", function(e, post) {
2013-07-27 06:57:12 +02:00
if (!$(post).hasClass("reply")) {
$(post).find('div.post.op span.omitted').each(do_expand);
}
2012-03-31 12:32:09 +02:00
});
});