2012-03-14 23:44:15 -04:00
|
|
|
/*
|
|
|
|
* auto-reload.js
|
|
|
|
* https://github.com/savetheinternet/Tinyboard-Tools/blob/master/js/auto-reload.js
|
|
|
|
*
|
|
|
|
* Brings AJAX to Tinyboard.
|
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
|
|
|
*
|
|
|
|
* Usage:
|
2012-03-15 01:19:26 -04:00
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/auto-reload.js';
|
2012-03-14 23:44:15 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
if($('div.banner').length == 0)
|
|
|
|
return; // not index
|
|
|
|
|
2012-03-15 05:40:52 -04:00
|
|
|
var poll_interval;
|
|
|
|
|
|
|
|
var poll = function() {
|
2012-03-14 23:44:15 -04:00
|
|
|
$.ajax({
|
|
|
|
url: document.location,
|
|
|
|
success: function(data) {
|
|
|
|
$(data).find('div.post.reply').each(function() {
|
|
|
|
var id = $(this).attr('id');
|
|
|
|
if($('#' + id).length == 0) {
|
2012-03-15 18:08:03 -04:00
|
|
|
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
|
2012-03-18 08:55:01 -04:00
|
|
|
$(document).trigger('new_post', this);
|
2012-03-14 23:44:15 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-03-15 05:40:52 -04:00
|
|
|
|
2012-03-18 08:57:38 -04:00
|
|
|
poll_interval = setTimeout(poll, 5000);
|
2012-03-15 05:40:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
$(window).scroll(function() {
|
2012-03-15 18:08:03 -04:00
|
|
|
if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) {
|
2012-03-15 05:40:52 -04:00
|
|
|
clearTimeout(poll_interval);
|
|
|
|
poll_interval = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(poll_interval === false) {
|
|
|
|
poll_interval = setTimeout(poll, 1500);
|
|
|
|
}
|
|
|
|
}).trigger('scroll');
|
2012-03-14 23:44:15 -04:00
|
|
|
});
|
|
|
|
|