diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
| commit | fef9a3ca82144348924852f68aee35ff4bf6ca25 (patch) | |
| tree | 2eb7dd277177fcbd572884d15ed3ce100aa61c7c /js/auto-reload.js | |
| parent | 52443d3da98e992953d8214b7848350f70d02336 (diff) | |
| parent | 2df1ebd88c266d984cbaa6c26917c2ea89c2ae0e (diff) | |
Merge branch 'master' of github.com:savetheinternet/Tinyboard-Tools into tools
Conflicts:
README.md
Diffstat (limited to 'js/auto-reload.js')
| -rw-r--r-- | js/auto-reload.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/js/auto-reload.js b/js/auto-reload.js new file mode 100644 index 00000000..f6981bdf --- /dev/null +++ b/js/auto-reload.js @@ -0,0 +1,51 @@ +/* + * 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: + * $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 + + 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'); +}); + |
