Skip to content

Node.js based forum software built for the modern web

closes #857

Baris Soner Usakli5759b1b1a205
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index 1e53f9a4e8..0b1410a905 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -28,27 +28,14 @@ var ajaxify = {};
}
};
- var pagination, paginator_bar;
-
ajaxify.currentPage = null;
ajaxify.initialLoad = false;
ajaxify.go = function (url, callback, quiet) {
// "quiet": If set to true, will not call pushState
-
- // start: the following should be set like so: ajaxify.onchange(function(){}); where the code actually belongs
- $(window).off('scroll');
app.enterRoom('global');
- pagination = pagination || document.getElementById('pagination');
- paginator_bar = pagination ? document.body.querySelector('.progress-container') : undefined;
- if (pagination) {
- pagination.parentNode.style.display = 'none';
- paginator_bar.style.display = 'none';
- }
-
- window.onscroll = null;
- // end
+ $('body').trigger('action:ajaxifying', {url: url});
if ($('#content').hasClass('ajaxifying')) {
templates.cancelRequest();
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 365e1482e5..056f2572c2 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -1,7 +1,6 @@
define(['composer', 'forum/pagination'], function(composer, pagination) {
var Topic = {},
- infiniteLoaderActive = false,
- pagination;
+ infiniteLoaderActive = false;
function showBottomPostBar() {
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
@@ -9,6 +8,27 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
}
+ $('body').on('action:ajaxifying', function(ev, data) {
+
+ if(data.url.indexOf('topic') === 0) {
+ $('.pagination-block a').on('click', function() {
+ return false;
+ });
+
+ $('.pagination-block i:first').on('click', function() {
+ app.scrollToTop();
+ });
+
+ $('.pagination-block i:last').on('click', function() {
+ app.scrollToBottom();
+ });
+
+ } else {
+ $(window).off('scroll');
+ $('.pagination-block').addClass('hide');
+ }
+ });
+
Topic.init = function() {
var expose_tools = templates.get('expose_tools'),
tid = templates.get('topic_id'),
@@ -346,6 +366,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
function enableInfiniteLoading() {
if(!config.usePagination) {
+ $('.pagination-block').removeClass('hide');
app.enableInfiniteLoading(function() {
if (!infiniteLoaderActive && $('#post-container').children().length) {
loadMorePosts(tid, function(posts) {
@@ -927,39 +948,21 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
}
- window.onscroll = updateHeader;
+ $(window).on('scroll', updateHeader);
};
function updateHeader() {
- if (pagination == null) {
- $('.pagination-block a').on('click', function() {
- return false;
- });
-
- jQuery('.pagination-block i:first').on('click', function() {
- app.scrollToTop();
- });
-
- jQuery('.pagination-block i:last').on('click', function() {
- app.scrollToBottom();
- });
- }
- pagination = pagination || document.getElementById('pagination');
+ var paginationEl = $('#pagination');
var windowHeight = jQuery(window).height();
var scrollTop = jQuery(window).scrollTop();
var scrollBottom = scrollTop + windowHeight;
var progressBar = $('.progress-bar');
- var progressBarContainer = $('.progress-container');
var tid = templates.get('topic_id');
- if(pagination.parentNode)
- pagination.parentNode.style.display = 'block';
- progressBarContainer.css('display', '');
-
if (scrollTop < jQuery('.posts > .post-row:first-child').height() && Topic.postCount > 1) {
localStorage.removeItem("topic:" + tid + ":bookmark");
- pagination.innerHTML = '1 out of ' + Topic.postCount;
+ paginationEl.html('1 out of ' + Topic.postCount);
progressBar.width(0);
return;
}
@@ -986,14 +989,14 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
smallestNonNegative = Number.MAX_VALUE;
}
- pagination.innerHTML = (this.postnumber-1) + ' out of ' + Topic.postCount;
+ paginationEl.html((this.postnumber-1) + ' out of ' + Topic.postCount);
progressBar.width(((this.postnumber-1) / Topic.postCount * 100) + '%');
}
});
setTimeout(function() {
if (scrollTop + windowHeight == jQuery(document).height() && !infiniteLoaderActive) {
- pagination.innerHTML = Topic.postCount + ' out of ' + Topic.postCount;
+ paginationEl.html(Topic.postCount + ' out of ' + Topic.postCount);
progressBar.width('100%');
}
}, 100);
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 02cd2ecf69..8ad089b46a 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -156,7 +156,7 @@
</li>
</ul>
- <ul class="nav navbar-nav navbar-right pagination-block">
+ <ul class="nav navbar-nav navbar-right pagination-block hide">
<li class="active">
<a href="#">
<i class="fa fa-chevron-up pointer"></i>