summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-12-23 17:31:47 +0100
committerczaks <marcin@6irc.net>2013-12-23 17:31:47 +0100
commitfa28560982590127705a7abf3619bff75f9dde83 (patch)
tree143421d44ae4ca50327dd3373995e8a3d117472e /js
parent42ae3550f92a4ab480cbf5fb82c1c44b0a01cfa1 (diff)
auto-reload.js: add a number indicating new posts in the tab title
Diffstat (limited to 'js')
-rw-r--r--js/auto-reload.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/js/auto-reload.js b/js/auto-reload.js
index f3f04639..725b4b51 100644
--- a/js/auto-reload.js
+++ b/js/auto-reload.js
@@ -23,7 +23,33 @@ $(document).ready(function(){
var poll_interval;
var end_of_page = false;
+
+ var orig_title = document.title;
+ var new_posts = 0;
+ var first_new_post = null;
+ var update_title = function() {
+ document.title = (new_posts ? "("+new_posts+") " : "") + orig_title;
+ };
+
+ var window_active = true;
+ $(window).focus(function() {
+ window_active = true;
+ recheck_activated();
+ });
+ $(window).blur(function() {
+ window_active = false;
+ });
+ var recheck_activated = function() {
+ if (new_posts && window_active &&
+ $(window).scrollTop() + $(window).height() >=
+ $(first_new_post).position().top) {
+
+ new_posts = 0;
+ }
+ update_title();
+ };
+
var poll = function() {
$.ajax({
url: document.location,
@@ -31,8 +57,13 @@ $(document).ready(function(){
$(data).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
+ if (!new_posts) {
+ first_new_post = this;
+ }
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
+ new_posts++;
$(document).trigger('new_post', this);
+ recheck_activated();
}
});
}
@@ -43,7 +74,10 @@ $(document).ready(function(){
};
$(window).scroll(function() {
- if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) {
+ recheck_activated();
+
+ if($(this).scrollTop() + $(this).height() <
+ $('div.post:last').position().top + $('div.post:last').height()) {
end_of_page = false;
return;
}