1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-30 18:24:29 +01:00

Merge pull request #166 from joosera/master

Fix js/expand.js
This commit is contained in:
Michael 2014-04-22 08:15:34 +10:00
commit de395fcc36

View File

@ -18,49 +18,50 @@ $(document).ready(function(){
return; // not index return; // not index
$('div.post.op span.omitted').each(function() { $('div.post.op span.omitted').each(function() {
var do_expand = function() { var do_expand = function() {
$(this) $(this)
.html($(this).text().replace(_("Click reply to view."), '<a href="javascript:void(0)">'+_("Click to expand")+'</a>.')) .html($(this).html().replace(_("Click reply to view."), '<a href="javascript:void(0)">'+_("Click to expand")+'</a>.'))
.find('a').click(function() { .find('a').click(function() {
var thread = $(this).parent().parent().parent(); var thread = $(this).parent().parent().parent();
var id = thread.attr('id').replace(/^thread_/, ''); var id = thread.attr('id').replace(/^thread_/, '');
$.ajax({ $.ajax({
url: thread.find('p.intro a.post_no:first').attr('href'), url: thread.find('p.intro a.post_no:first').attr('href'),
context: document.body, context: document.body,
success: function(data) { success: function(data) {
var last_expanded = false; var last_expanded = false;
$(data).find('div.post.reply').each(function() { $(data).find('div.post.reply').each(function() {
thread.find('div.hidden').remove(); thread.find('div.hidden').remove();
var post_in_doc = thread.find('#' + $(this).attr('id')); var post_in_doc = thread.find('#' + $(this).attr('id'));
if(post_in_doc.length == 0) { if(post_in_doc.length == 0) {
if(last_expanded) { if(last_expanded) {
$(this).addClass('expanded').insertAfter(last_expanded).before('<br class="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);
} else { } else {
$(this).addClass('expanded').insertAfter(thread.find('div.post:first')).after('<br class="expanded">'); last_expanded = post_in_doc;
} }
last_expanded = $(this);
$(document).trigger('new_post', this);
} else {
last_expanded = post_in_doc;
}
});
$('<span class="omitted"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
.insertAfter(thread.find('span.omitted').css('display', 'none'))
.click(function() {
thread.find('.expanded').remove();
$(this).prev().css('display', '');
$(this).remove();
}); });
} $('<span class="omitted"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
.insertAfter(thread.find('span.omitted').css('display', 'none'))
.click(function() {
thread.find('.expanded').remove();
$(this).prev().css('display', '');
$(this).remove();
});
}
});
}); });
});
}
$('div.post.op span.omitted').each(do_expand);
$(document).bind("new_post", function(e, post) {
if (!$(post).hasClass("reply")) {
$(post).find('div.post.op span.omitted').each(do_expand);
} }
$('div.post.op span.omitted').each(do_expand);
$(document).bind("new_post", function(e, post) {
if (!$(post).hasClass("reply")) {
$(post).find('div.post.op span.omitted').each(do_expand);
}
});
}); });
}); });