Skip to content

Node.js based forum software built for the modern web

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

psychobunny469a5221ed94
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 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
- <a class="navbar-brand" href="/">{title}</a>
+ <a class="navbar-brand" href="/">{title}<div id="pagination">
+ 0 / 0
+ </div></a>
</div>
<div class="navbar-collapse collapse">
@@ -56,7 +58,12 @@
<li>
<a href="/users">Users</a>
</li>
+ <li>
+ <a href="/"></a>
+ </li>
</ul>
+
+
<ul id="right-menu" class="nav navbar-nav pull-right">
<li class="notifications dropdown text-center">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" id="notif_dropdown"><i class="icon-circle-blank"></i></a>
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index b05f534bde..a3418a85bb 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -234,6 +234,7 @@
<input type="hidden" template-variable="deleted" value="{deleted}" />
<input type="hidden" template-variable="pinned" value="{pinned}" />
<input type="hidden" template-variable="topic_name" value="{topic_name}" />
+<input type="hidden" template-variable="postcount" value="{postcount}" />
diff --git a/src/topics.js b/src/topics.js
index 25611f3550..363b2c0609 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -379,6 +379,7 @@ marked.setOptions({
'deleted': topicData.deleted,
'pinned': topicData.pinned,
'slug': topicData.slug,
+ 'postcount' : topicData.postcount,
'topic_id': tid,
'expose_tools': privileges.editable ? 1 : 0,
'posts': topicPosts,