1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-27 08:50:59 +01:00
vichan/js/auto-reload.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

/*
* auto-reload.js
2012-03-31 02:13:11 +02:00
* 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
2012-03-15 10:40:52 +01:00
var poll_interval;
var end_of_page = false;
2012-03-15 10:40:52 +01:00
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);
}
});
}
});
2012-03-15 10:40:52 +01:00
clearTimeout(poll_interval);
poll_interval = setTimeout(poll, end_of_page ? 3000 : 10000);
2012-03-15 10:40:52 +01:00
};
$(window).scroll(function() {
if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) {
end_of_page = false;
2012-03-15 10:40:52 +01:00
return;
}
clearTimeout(poll_interval);
poll_interval = setTimeout(poll, 100);
end_of_page = true;
2012-03-15 10:40:52 +01:00
}).trigger('scroll');
poll_interval = setTimeout(poll, 3000);
});