Requirements
Forum Version : phpbb3Other : Topics with more than one page
Introduction
This is a small project I started a few weeks ago, but never completely finished. Basically it applies a button to the topic which allows you to load more pages, similar to "endless" scrolling. Here's a demonstration : http://generaltesting.forumotion.com/t1-test-subjectYou will see a button by scrolling to the bottom of the topic.
Clicking this button loads the next ( or previous ) page, without transitioning to a new page.
It uses a global object -- $fa_topic -- to store necessary data related to the current topic. Mostly topic data, page numbers, nodes, and a method for getting pages.
It's still in the early stages, as the script is only optimized for phpbb3.
Installation
The only things that need to be changed to work, would be the perpage variable. This should be changed to the amount of replies you allow perpage; Default is 15. You can find this value by going to Administration Panel > General > Messages > Configuration > Posts per pageThere's also a language config object in case you want to change or translate words.
To install : go to Administration Panel > Modules > JavaScript codes management > Create a new script
Placement : In the topics
- Code:
$(function() {
// start up variables
var perpage = 15,
// general language config
lang = {
next : 'Next Page',
previous : 'Previous Page',
first : 'Reached Beginning of Topic',
last : 'Reached End of Topic',
loading : 'Loading...',
page : 'Page'
},
main = document.getElementById('main-content'), // main container
topicId = window.location.href.replace(/.*?t(\d+).*/, '$1'),
pagination = $('p.pagination', main),
first = $('.post', main)[0],
title = document.createElement('H2'),
topHook,
bottomHook = document.anchors.bottomtitle,
topBlock = document.createElement('DIV'),
bottomBlock = document.createElement('DIV'),
next = document.createElement('INPUT'),
previous = document.createElement('INPUT'),
page,
i = 0;
if (!pagination[0]) return; // return if no pagination
page = $('a[href^="/t' + topicId + 'p"]:not(.pag-img)', pagination[0]); // get page list
topHook = pagination[0].nextSibling.nextSibling;
window.$fa_topic = {
id : topicId, // topic id
title : document.title.replace(/(.*?)\s-.*/, '$1'), // topic title ( non-slug )
next : next, // next button
previous : previous, // previous button
loading : false, // currently loading the next page ?
prevPage : +pagination[0].getElementsByTagName('STRONG')[0].innerHTML, // previous page number
currentPage : +pagination[0].getElementsByTagName('STRONG')[0].innerHTML, // current page number
lastPage : pagination[0].getElementsByTagName('SPAN')[0].lastChild.tagName == 'STRONG' ? +pagination[0].getElementsByTagName('STRONG')[0].innerHTML : +page[page.length - 1].innerHTML, // last page number
hook : [bottomHook, topHook],
perpage : perpage,
pageList : {}, // contains a list of page links
lang : lang,
// gets the page specified
// @param page : a number representing a valid page
// @param position : a string; 'top' or 'bottom', Depends where the next page is placed
getPage : function(page, position) {
if ($fa_topic.loading) return;
position = position ? position.toLowerCase() : 'bottom';
if (position == 'bottom' && $fa_topic.currentPage >= $fa_topic.lastPage) return $fa_topic.next.innerHTML = $fa_topic.lang.last;
else if (position == 'top' && 1 >= $fa_topic.prevPage) return $fa_topic.previous.innerHTML = $fa_topic.lang.first;
var where = position == 'bottom' ? true : false, payload = document.createElement('DIV'), dropPoint = $fa_topic.hook[where ? 0 : 1], i = 0, posts, j;
$fa_topic.loading = true;
where ? $fa_topic.currentPage++ : $fa_topic.prevPage--;
$fa_topic.next.value = $fa_topic.lang.loading;
$fa_topic.previous.value = $fa_topic.lang.loading;
payload.style.display = 'none';
payload.innerHTML = '<div style="height:30px" id="fa_topic_page' + (where ? $fa_topic.currentPage : $fa_topic.prevPage) + '"></div><h2>' + $fa_topic.title + ' - ' + $fa_topic.lang.page + ' ' + (where ? $fa_topic.currentPage : $fa_topic.prevPage) + '</h2>';
$.get($fa_topic.pageList[page], function(d) {
for (posts = $('div.post', d), j = posts.length; i < j; i++) posts[i].nextSibling.tagName != 'HR' && payload.appendChild(posts[i]);
dropPoint.parentNode.insertBefore(payload, where ? dropPoint : dropPoint.nextSibling.nextSibling);
$(payload).fadeIn(750);
$fa_topic.next.value = $fa_topic.currentPage >= $fa_topic.lastPage ? $fa_topic.lang.last : $fa_topic.lang.next + ' (' + ($fa_topic.currentPage + 1) + ' / ' + $fa_topic.lastPage + ')';
$fa_topic.previous.value = 1 >= $fa_topic.prevPage ? $fa_topic.lang.first : $fa_topic.lang.previous + ' (' + ($fa_topic.prevPage - 1) + ' / ' + $fa_topic.lastPage + ')';
$fa_topic.loading = false;
window.location.hash = 'fa_topic_page' + (where ? $fa_topic.currentPage : $fa_topic.prevPage);
});
}
};
// insert current title
title.innerHTML = $fa_topic.title + ' - ' + $fa_topic.lang.page + ' ' + $fa_topic.currentPage;
title.id = 'fa_topic_page' + $fa_topic.currentPage;
first.parentNode.insertBefore(title, first);
// next button attributes
next.type = 'button';
next.className = 'button2';
next.value = $fa_topic.currentPage == $fa_topic.lastPage ? $fa_topic.lang.last : $fa_topic.lang.next + ' (' + ($fa_topic.currentPage + 1) + ' / ' + $fa_topic.lastPage + ')';
next.onclick = function() {
$fa_topic.getPage($fa_topic.currentPage + 1, 'bottom');
};
// previous button attributes
if ($fa_topic.currentPage > 1) {
previous.type = 'button';
previous.className = 'button2';
previous.value = $fa_topic.lang.previous + ' (' + ($fa_topic.prevPage - 1) + ' / ' + $fa_topic.lastPage + ')';
previous.onclick = function() {
$fa_topic.getPage($fa_topic.prevPage - 1, 'top');
};
topBlock.style.textAlign = 'center';
topBlock.appendChild(previous);
topHook.parentNode.insertBefore(topBlock, topHook.nextSibling);
}
// append bottom nodes
bottomBlock.style.textAlign = 'center';
bottomBlock.appendChild(next);
bottomHook.parentNode.insertBefore(bottomBlock, bottomHook.nextSibling);
// form page list so it can be used to load later pages
while (i ++< $fa_topic.lastPage) $fa_topic.pageList[i] = '/t' + $fa_topic.id + 'p' + ($fa_topic.perpage * i - $fa_topic.perpage) + '-';
'par ange tuteur';
});
In the mean time, if you use phpbb3 you can enjoy this..