added postcount to topics return; started scrollspy behaviour for "postid / postcount" in topics.

This commit is contained in:
psychobunny
2013-08-27 06:36:49 +08:00
parent f251b9c6c5
commit 469a5221ed
4 changed files with 46 additions and 23 deletions

View File

@@ -605,39 +605,53 @@
var postAuthorImage, postAuthorInfo;
var postAuthorImage, postAuthorInfo, pagination;
var postcount = templates.get('postcount');
function updateHeader() {
jQuery('.post-author-info').css('bottom', '0px');
postAuthorImage = postAuthorImage || document.getElementById('post-author-image');
postAuthorInfo = postAuthorInfo || document.getElementById('post-author-info');
pagination = pagination || document.getElementById('pagination');
var scrollTop = jQuery(window).scrollTop();
var scrollBottom = scrollTop + jQuery(window).height();
var scrollTop = jQuery(window).scrollTop();
var scrollBottom = scrollTop + jQuery(window).height();
if (scrollTop < 50) {
postAuthorImage.src = (jQuery('.main-avatar img').attr('src'));
postAuthorInfo.innerHTML = 'Posted by ' + jQuery('.main-post').attr('data-username') + ', ' + jQuery('.main-post').find('.relativeTimeAgo').html();
return;
}
jQuery('.sub-posts').each(function() {
var el = jQuery(this);
var elTop = el.offset().top;
var height = Math.floor(el.height());
var elBottom = elTop + (height < 300 ? height : 300);
var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom)
&& (elBottom <= scrollBottom) && (elTop >= scrollTop) );
if (scrollTop < 50) {
postAuthorImage.src = (jQuery('.main-avatar img').attr('src'));
postAuthorInfo.innerHTML = 'Posted by ' + jQuery('.main-post').attr('data-username') + ', ' + jQuery('.main-post').find('.relativeTimeAgo').html();
pagination.innerHTML = '0 / ' + postcount;
return;
}
if (inView) {
var count = 0;
postAuthorImage.src = (jQuery(this).find('.profile-image-block img').attr('src'));
postAuthorInfo.innerHTML = 'Posted by ' + jQuery(this).attr('data-username') + ', ' + jQuery(this).find('.relativeTimeAgo').html();
jQuery('.sub-posts').each(function() {
count++;
this.postnumber = count;
}
});
var el = jQuery(this);
var elTop = el.offset().top;
var height = Math.floor(el.height());
var elBottom = elTop + (height < 300 ? height : 300);
var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom)
&& (elBottom <= scrollBottom) && (elTop >= scrollTop));
if (inView) {
pagination.innerHTML = this.postnumber + ' / ' + postcount;
postAuthorImage.src = (jQuery(this).find('.profile-image-block img').attr('src'));
postAuthorInfo.innerHTML = 'Posted by ' + jQuery(this).attr('data-username') + ', ' + jQuery(this).find('.relativeTimeAgo').html();
}
});
if (scrollTop >= jQuery(window).height()) {
//pagination.innerHTML = postcount + ' / ' + postcount;
}
}
window.onscroll = updateHeader;