##// END OF EJS Templates
Made blink effect on thread update more soft
Made blink effect on thread update more soft

File last commit:

r481:61c787a5 default
r481:61c787a5 default
Show More
thread_update.js
196 lines | 5.5 KiB | application/javascript | JavascriptLexer
neko259
Decreased anti-flood posting delay. Added lisence text to the thread...
r365 /*
@licstart The following is the entire license notice for the
JavaScript code in this page.
Copyright (C) 2013 neko259
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this page.
*/
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 var THREAD_UPDATE_DELAY = 10000;
var loading = false;
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 var lastUpdateTime = null;
neko259
Showing unread posts count when new posts appear in the background tab
r468 var unreadPosts = 0
neko259
Update thread by time, not post id. This will help with getting updated posts
r363
function blink(node) {
var blinkCount = 2;
var nodeToAnimate = node;
for (var i = 0; i < blinkCount; i++) {
neko259
Made blink effect on thread update more soft
r481 nodeToAnimate = nodeToAnimate.fadeTo('fast', 0.5).fadeTo('fast', 1.0);
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 }
}
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361
function updateThread() {
if (loading) {
return;
}
loading = true;
var threadPosts = $('div.thread').children('.post');
var lastPost = threadPosts.last();
var threadId = threadPosts.first().attr('id');
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/';
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 $.getJSON(diffUrl)
.success(function(data) {
neko259
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
r373 var bottom = isPageBottom();
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 var addedPosts = data.added;
for (var i = 0; i < addedPosts.length; i++) {
var postText = addedPosts[i];
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 var post = $(postText);
post.appendTo(lastPost.parent());
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 addRefLinkPreview(post[0]);
lastPost = post;
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 blink(post);
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 }
neko259
Loading updated posts in thread autoupdate
r364 var updatedPosts = data.updated;
for (var i = 0; i < updatedPosts.length; i++) {
var postText = updatedPosts[i];
var post = $(postText);
var postId = post.attr('id');
var oldPost = $('div.thread').children('.post[id=' + postId + ']');
oldPost.replaceWith(post);
addRefLinkPreview(post[0]);
blink(post);
}
neko259
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
r373 // TODO Process deleted posts
neko259
Update thread by time, not post id. This will help with getting updated posts
r363
lastUpdateTime = data.last_update;
loading = false;
neko259
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
r373
if (bottom) {
var $target = $('html,body');
$target.animate({scrollTop: $target.height()}, 1000);
}
neko259
Update reply and image count after thread update
r391
$('#reply-count').text(getReplyCount());
$('#image-count').text(getImageCount());
neko259
Updating bumplimit progress on thread update
r420
neko259
Updated posts must not affect bumplimit bar
r427 updateBumplimitProgress(data.added.length);
neko259
Add dead_post class to the posts when thread reached bumplimit on autoupdate
r429 updatePostBumpableStatus();
neko259
Added new posts notification in the not active browser page
r451
if (data.added.length + data.updated.length > 0) {
neko259
Showing unread posts count when new posts appear in the background tab
r468 showNewPostsTitle(data.added.length);
neko259
Added new posts notification in the not active browser page
r451 }
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 })
.error(function(data) {
// TODO Show error message that server is unavailable?
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 loading = false;
});
}
neko259
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
r373 function isPageBottom() {
var scroll = $(window).scrollTop() / ($(document).height()
- $(window).height())
return scroll == 1
}
neko259
Update thread by time, not post id. This will help with getting updated posts
r363 function initAutoupdate() {
loading = false;
lastUpdateTime = $('.metapanel').attr('data-last-update');
setInterval(updateThread, THREAD_UPDATE_DELAY);
}
neko259
Update reply and image count after thread update
r391
function getReplyCount() {
neko259
Fixed thread OP id in thread view. Fixed reply count in thread view
r404 return $('.thread').children('.post').length
neko259
Update reply and image count after thread update
r391 }
function getImageCount() {
return $('.thread').find('img').length
}
neko259
Updating bumplimit progress on thread update
r420
neko259
Add dead_post class to the posts when thread reached bumplimit on autoupdate
r429 /**
* Update bumplimit progress bar
*/
neko259
Updating bumplimit progress on thread update
r420 function updateBumplimitProgress(postDelta) {
var progressBar = $('#bumplimit_progress');
if (progressBar) {
var postsToLimitElement = $('#left_to_limit');
var oldPostsToLimit = parseInt(postsToLimitElement.text());
var postCount = getReplyCount();
var bumplimit = postCount - postDelta + oldPostsToLimit;
var newPostsToLimit = bumplimit - postCount;
neko259
Add dead_post class to the posts when thread reached bumplimit on autoupdate
r429 if (newPostsToLimit <= 0) {
$('.bar-bg').remove();
neko259
Updating bumplimit progress on thread update
r420 } else {
postsToLimitElement.text(newPostsToLimit);
progressBar.width((100 - postCount / bumplimit * 100.0) + '%');
}
}
neko259
Updated posts must not affect bumplimit bar
r427 }
neko259
Add dead_post class to the posts when thread reached bumplimit on autoupdate
r429
/**
* If the bumplimit is reached, add dead_post class to all posts
*/
function updatePostBumpableStatus() {
var postCount = getReplyCount();
var postsToLimitElement = $('#left_to_limit');
var postsToLimit = parseInt(postsToLimitElement.text());
if (postsToLimit <= 0) {
$('.thread').find('.post').addClass('dead_post');
}
}
neko259
Added new posts notification in the not active browser page
r451
var documentOriginalTitle = '';
/**
* Show 'new posts' text in the title if the document is not visible to a user
*/
neko259
Showing unread posts count when new posts appear in the background tab
r468 function showNewPostsTitle(newPostCount) {
neko259
Added new posts notification in the not active browser page
r451 if (document.hidden) {
neko259
Showing unread posts count when new posts appear in the background tab
r468 if (documentOriginalTitle === '') {
documentOriginalTitle = document.title;
}
unreadPosts = unreadPosts + newPostCount;
document.title = '[' + unreadPosts + '] ' + documentOriginalTitle;
neko259
Added new posts notification in the not active browser page
r451
document.addEventListener('visibilitychange', function() {
if (documentOriginalTitle !== '') {
document.title = documentOriginalTitle;
documentOriginalTitle = '';
neko259
Showing unread posts count when new posts appear in the background tab
r468 unreadPosts = 0;
neko259
Added new posts notification in the not active browser page
r451 }
document.removeEventListener('visibilitychange', null);
});
}
neko259
Added a server-side gallery and mode switcher
r458 }
$(document).ready(function(){
initAutoupdate();
});