mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 05:37:35 +02:00
fix: hacking handleBack module to work with world page
This commit is contained in:
@@ -3,10 +3,10 @@
|
|||||||
define('forum/world', [
|
define('forum/world', [
|
||||||
'forum/infinitescroll', 'search', 'sort', 'hooks',
|
'forum/infinitescroll', 'search', 'sort', 'hooks',
|
||||||
'alerts', 'api', 'bootbox', 'helpers', 'forum/category/tools',
|
'alerts', 'api', 'bootbox', 'helpers', 'forum/category/tools',
|
||||||
'translator', 'quickreply',
|
'translator', 'quickreply', 'handleBack',
|
||||||
], function (infinitescroll, search, sort, hooks,
|
], function (infinitescroll, search, sort, hooks,
|
||||||
alerts, api, bootbox, helpers, categoryTools,
|
alerts, api, bootbox, helpers, categoryTools,
|
||||||
translator, quickreply) {
|
translator, quickreply, handleBack) {
|
||||||
const World = {};
|
const World = {};
|
||||||
|
|
||||||
World.init = function () {
|
World.init = function () {
|
||||||
@@ -47,6 +47,20 @@ define('forum/world', [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleBack.init((after, handleBackCb) => {
|
||||||
|
loadTopicsAfter(after, 1, (payload, callback) => {
|
||||||
|
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
||||||
|
const listEl = document.getElementById('world-feed');
|
||||||
|
$(listEl).append(html);
|
||||||
|
html.find('.timeago').timeago();
|
||||||
|
handleImages();
|
||||||
|
handleShowMoreButtons();
|
||||||
|
callback();
|
||||||
|
handleBackCb();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, { container: '#world-feed' });
|
||||||
|
|
||||||
search.enableQuickSearch({
|
search.enableQuickSearch({
|
||||||
searchElements: {
|
searchElements: {
|
||||||
inputEl: $('[component="category-search"]'),
|
inputEl: $('[component="category-search"]'),
|
||||||
@@ -65,6 +79,10 @@ define('forum/world', [
|
|||||||
if (!config.usePagination) {
|
if (!config.usePagination) {
|
||||||
infinitescroll.init((direction) => {
|
infinitescroll.init((direction) => {
|
||||||
const posts = Array.from(document.querySelectorAll('[component="category/topic"]'));
|
const posts = Array.from(document.querySelectorAll('[component="category/topic"]'));
|
||||||
|
if (!posts.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const afterEl = direction > 0 ? posts.pop() : posts.shift();
|
const afterEl = direction > 0 ? posts.pop() : posts.shift();
|
||||||
const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||||
if (after < config.topicsPerPage) {
|
if (after < config.topicsPerPage) {
|
||||||
@@ -74,7 +92,7 @@ define('forum/world', [
|
|||||||
loadTopicsAfter(after, direction, (payload, callback) => {
|
loadTopicsAfter(after, direction, (payload, callback) => {
|
||||||
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {
|
||||||
const listEl = document.getElementById('world-feed');
|
const listEl = document.getElementById('world-feed');
|
||||||
$(listEl).append(html);
|
$(listEl)[direction === -1 ? 'prepend' : 'append'](html);
|
||||||
html.find('.timeago').timeago();
|
html.find('.timeago').timeago();
|
||||||
handleImages();
|
handleImages();
|
||||||
handleShowMoreButtons();
|
handleShowMoreButtons();
|
||||||
|
|||||||
@@ -8,9 +8,17 @@ define('handleBack', [
|
|||||||
], function (components, storage, navigator, pagination) {
|
], function (components, storage, navigator, pagination) {
|
||||||
const handleBack = {};
|
const handleBack = {};
|
||||||
let loadTopicsMethod;
|
let loadTopicsMethod;
|
||||||
|
const elements = new Map();
|
||||||
|
const defaults = new Map([
|
||||||
|
['container', '[component="category"]'],
|
||||||
|
]);
|
||||||
|
|
||||||
handleBack.init = function (_loadTopicsMethod) {
|
handleBack.init = function (_loadTopicsMethod, _elements = {}) {
|
||||||
loadTopicsMethod = _loadTopicsMethod;
|
loadTopicsMethod = _loadTopicsMethod;
|
||||||
|
['container'].forEach((prop) => {
|
||||||
|
elements.set(prop, _elements[prop] || defaults.get(prop));
|
||||||
|
});
|
||||||
|
|
||||||
saveClickedIndex();
|
saveClickedIndex();
|
||||||
$(window).off('action:popstate', onBackClicked).on('action:popstate', onBackClicked);
|
$(window).off('action:popstate', onBackClicked).on('action:popstate', onBackClicked);
|
||||||
};
|
};
|
||||||
@@ -18,10 +26,10 @@ define('handleBack', [
|
|||||||
handleBack.onBackClicked = onBackClicked;
|
handleBack.onBackClicked = onBackClicked;
|
||||||
|
|
||||||
function saveClickedIndex() {
|
function saveClickedIndex() {
|
||||||
$('[component="category"]').on('click', '[component="topic/header"]', function () {
|
$(elements.get('container')).on('click', '[data-index]', function () {
|
||||||
const clickedIndex = $(this).parents('[data-index]').attr('data-index');
|
const clickedIndex = $(this).attr('data-index');
|
||||||
const windowScrollTop = $(window).scrollTop();
|
const windowScrollTop = $(window).scrollTop();
|
||||||
$('[component="category/topic"]').each(function (index, el) {
|
$(elements.get('container')).find('[data-index]').each(function (index, el) {
|
||||||
if ($(el).offset().top - windowScrollTop > 0) {
|
if ($(el).offset().top - windowScrollTop > 0) {
|
||||||
storage.setItem('category:bookmark', $(el).attr('data-index'));
|
storage.setItem('category:bookmark', $(el).attr('data-index'));
|
||||||
storage.setItem('category:bookmark:clicked', clickedIndex);
|
storage.setItem('category:bookmark:clicked', clickedIndex);
|
||||||
@@ -38,6 +46,7 @@ define('handleBack', [
|
|||||||
ajaxify.data.template.category ||
|
ajaxify.data.template.category ||
|
||||||
ajaxify.data.template.recent ||
|
ajaxify.data.template.recent ||
|
||||||
ajaxify.data.template.popular ||
|
ajaxify.data.template.popular ||
|
||||||
|
ajaxify.data.template.world ||
|
||||||
highlightUnread
|
highlightUnread
|
||||||
) {
|
) {
|
||||||
let bookmarkIndex = storage.getItem('category:bookmark');
|
let bookmarkIndex = storage.getItem('category:bookmark');
|
||||||
@@ -67,7 +76,7 @@ define('handleBack', [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('[component="category"]').empty();
|
$(elements.get('container')).empty();
|
||||||
loadTopicsMethod(Math.max(0, bookmarkIndex - 1) + 1, function () {
|
loadTopicsMethod(Math.max(0, bookmarkIndex - 1) + 1, function () {
|
||||||
handleBack.scrollToTopic(bookmarkIndex, clickedIndex);
|
handleBack.scrollToTopic(bookmarkIndex, clickedIndex);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user