From 469a5221ed94a5388c34a831720c20728c4ea494 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 27 Aug 2013 06:36:49 +0800 Subject: [PATCH] added postcount to topics return; started scrollspy behaviour for "postid / postcount" in topics. --- public/src/forum/topic.js | 54 +++++++++++++++++++++++-------------- public/templates/header.tpl | 9 ++++++- public/templates/topic.tpl | 1 + src/topics.js | 1 + 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 07c8e970ab..7aa385bfa4 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -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(); + + 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; + } + - var scrollTop = jQuery(window).scrollTop(); - var scrollBottom = scrollTop + jQuery(window).height(); + var count = 0; - 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() { + count++; + this.postnumber = count; - 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) ); + 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) { - 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 (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; diff --git a/public/templates/header.tpl b/public/templates/header.tpl index baeb3c039f..cb9fe29f66 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -42,7 +42,9 @@ - {title} + {title}