mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
closes #6144
This commit is contained in:
@@ -29,7 +29,6 @@ define('forum/topic', [
|
|||||||
app.removeAlert('bookmark');
|
app.removeAlert('bookmark');
|
||||||
|
|
||||||
events.removeListeners();
|
events.removeListeners();
|
||||||
$(window).off('keydown', onKeyDown);
|
|
||||||
|
|
||||||
require(['search'], function (search) {
|
require(['search'], function (search) {
|
||||||
if (search.topicDOM.active) {
|
if (search.topicDOM.active) {
|
||||||
@@ -63,8 +62,6 @@ define('forum/topic', [
|
|||||||
|
|
||||||
addParentHandler();
|
addParentHandler();
|
||||||
|
|
||||||
handleKeys();
|
|
||||||
|
|
||||||
navigator.init('[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex);
|
navigator.init('[component="post"]', ajaxify.data.postcount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex);
|
||||||
|
|
||||||
handleBookmark(tid);
|
handleBookmark(tid);
|
||||||
@@ -76,27 +73,6 @@ define('forum/topic', [
|
|||||||
$(window).trigger('action:topic.loaded', ajaxify.data);
|
$(window).trigger('action:topic.loaded', ajaxify.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleKeys() {
|
|
||||||
if (!config.usePagination) {
|
|
||||||
$(window).off('keydown', onKeyDown).on('keydown', onKeyDown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onKeyDown(ev) {
|
|
||||||
if (ev.target.nodeName === 'BODY') {
|
|
||||||
if (ev.shiftKey || ev.ctrlKey || ev.altKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ev.which === 36) { // home key
|
|
||||||
Topic.toTop();
|
|
||||||
return false;
|
|
||||||
} else if (ev.which === 35) { // end key
|
|
||||||
Topic.toBottom();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleTopicSearch() {
|
function handleTopicSearch() {
|
||||||
require(['search', 'mousetrap'], function (search, mousetrap) {
|
require(['search', 'mousetrap'], function (search, mousetrap) {
|
||||||
$('.topic-search').off('click')
|
$('.topic-search').off('click')
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
|
|
||||||
navigator.scrollActive = false;
|
navigator.scrollActive = false;
|
||||||
|
|
||||||
|
$(window).on('action:ajaxify.start', function () {
|
||||||
|
$(window).off('keydown', onKeyDown);
|
||||||
|
});
|
||||||
|
|
||||||
navigator.init = function (selector, count, toTop, toBottom, callback, calculateIndex) {
|
navigator.init = function (selector, count, toTop, toBottom, callback, calculateIndex) {
|
||||||
index = 1;
|
index = 1;
|
||||||
navigator.selector = selector;
|
navigator.selector = selector;
|
||||||
navigator.callback = callback;
|
navigator.callback = callback;
|
||||||
toTop = toTop || function () {};
|
navigator.toTop = toTop || function () {};
|
||||||
toBottom = toBottom || function () {};
|
navigator.toBottom = toBottom || function () {};
|
||||||
|
|
||||||
$(window).off('scroll', navigator.delayedUpdate).on('scroll', navigator.delayedUpdate);
|
$(window).off('scroll', navigator.delayedUpdate).on('scroll', navigator.delayedUpdate);
|
||||||
|
|
||||||
@@ -29,8 +33,8 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
|
|
||||||
$('.pagination-block .pageup').off('click').on('click', navigator.scrollUp);
|
$('.pagination-block .pageup').off('click').on('click', navigator.scrollUp);
|
||||||
$('.pagination-block .pagedown').off('click').on('click', navigator.scrollDown);
|
$('.pagination-block .pagedown').off('click').on('click', navigator.scrollDown);
|
||||||
$('.pagination-block .pagetop').off('click').on('click', toTop);
|
$('.pagination-block .pagetop').off('click').on('click', navigator.toTop);
|
||||||
$('.pagination-block .pagebottom').off('click').on('click', toBottom);
|
$('.pagination-block .pagebottom').off('click').on('click', navigator.toBottom);
|
||||||
|
|
||||||
$('.pagination-block input').on('keydown', function (e) {
|
$('.pagination-block input').on('keydown', function (e) {
|
||||||
if (e.which === 13) {
|
if (e.which === 13) {
|
||||||
@@ -52,10 +56,33 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handleKeys();
|
||||||
|
|
||||||
navigator.setCount(count);
|
navigator.setCount(count);
|
||||||
navigator.update(0);
|
navigator.update(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function handleKeys() {
|
||||||
|
if (!config.usePagination) {
|
||||||
|
$(window).off('keydown', onKeyDown).on('keydown', onKeyDown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onKeyDown(ev) {
|
||||||
|
if (ev.target.nodeName === 'BODY') {
|
||||||
|
if (ev.shiftKey || ev.ctrlKey || ev.altKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ev.which === 36 && navigator.toTop) { // home key
|
||||||
|
navigator.toTop();
|
||||||
|
return false;
|
||||||
|
} else if (ev.which === 35 && navigator.toBottom) { // end key
|
||||||
|
navigator.toBottom();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function generateUrl(index) {
|
function generateUrl(index) {
|
||||||
var pathname = window.location.pathname.replace(config.relative_path, '');
|
var pathname = window.location.pathname.replace(config.relative_path, '');
|
||||||
var parts = pathname.split('/');
|
var parts = pathname.split('/');
|
||||||
@@ -164,13 +191,26 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index = index > count ? count : index;
|
index = index > count ? count : index;
|
||||||
|
var relIndex = getRelativeIndex();
|
||||||
$('.pagination-block .pagination-text').translateHtml('[[global:pagination.out_of, ' + index + ', ' + count + ']]');
|
$('.pagination-block .pagination-text').translateHtml('[[global:pagination.out_of, ' + relIndex + ', ' + count + ']]');
|
||||||
var fraction = $(window).scrollTop() / ($(document).height() - $(window).height());
|
var fraction = relIndex / count;
|
||||||
$('.pagination-block meter').val(fraction);
|
$('.pagination-block meter').val(fraction);
|
||||||
$('.pagination-block .progress-bar').width((fraction * 100) + '%');
|
$('.pagination-block .progress-bar').width((fraction * 100) + '%');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getRelativeIndex() {
|
||||||
|
var relIndex = index;
|
||||||
|
if (relIndex === 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ajaxify.data.template.topic) {
|
||||||
|
if (config.topicPostSort === 'most_votes' || config.topicPostSort === 'newest_to_oldest') {
|
||||||
|
relIndex = ajaxify.data.postcount - index + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return relIndex;
|
||||||
|
}
|
||||||
|
|
||||||
navigator.scrollUp = function () {
|
navigator.scrollUp = function () {
|
||||||
$('body,html').animate({
|
$('body,html').animate({
|
||||||
scrollTop: $(window).scrollTop() - $(window).height(),
|
scrollTop: $(window).scrollTop() - $(window).height(),
|
||||||
@@ -244,7 +284,7 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
}
|
}
|
||||||
} else if (inCategory) {
|
} else if (inCategory) {
|
||||||
if (config.categoryTopicSort === 'most_posts' || config.categoryTopicSort === 'oldest_to_newest') {
|
if (config.categoryTopicSort === 'most_posts' || config.categoryTopicSort === 'oldest_to_newest') {
|
||||||
index = ajaxify.data.ajaxify.data.topic_count - index;
|
index = ajaxify.data.topic_count - index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user