1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 07:30:10 +01:00
vichan/js/auto-reload.js
undido 41ee55a1b2 Update auto-reload.js
check if viewing a thread or viewing a board page when updating a thread so new posts do not appear at bottom of page while viewing threads list not sure if this was because of an outdated template but I thought I should point out this as it may affect html templates no matter the code as the banner code is the only code that checks where the user currently is.
2013-03-20 00:56:59 -03:00

55 lines
1.3 KiB
JavaScript

/*
* auto-reload.js
* https://github.com/savetheinternet/Tinyboard/blob/master/js/auto-reload.js
*
* Brings AJAX to Tinyboard.
*
* Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/auto-reload.js';
*
*/
$(document).ready(function(){
if($('div.banner').length == 0)
return; // not index
if($(".post.op").size() != 1)
return; //not thread page
var poll_interval;
var poll = function() {
$.ajax({
url: document.location,
success: function(data) {
$(data).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
$(document).trigger('new_post', this);
}
});
}
});
poll_interval = setTimeout(poll, 5000);
};
$(window).scroll(function() {
if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) {
clearTimeout(poll_interval);
poll_interval = false;
return;
}
if(poll_interval === false) {
poll_interval = setTimeout(poll, 1500);
}
}).trigger('scroll');
});