v1.18.x
Baris Usakli 7 years ago
parent 94e10c8c32
commit 1454fdceff

@ -50,10 +50,10 @@ define('handleBack', [
var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage); var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage);
if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) { if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) {
pagination.loadPage(page, function () { pagination.loadPage(page, function () {
handleBack.scrollToTopic(bookmarkIndex, clickedIndex, 0); handleBack.scrollToTopic(bookmarkIndex, clickedIndex);
}); });
} else { } else {
handleBack.scrollToTopic(bookmarkIndex, clickedIndex, 0); handleBack.scrollToTopic(bookmarkIndex, clickedIndex);
} }
} else { } else {
if (bookmarkIndex === 0) { if (bookmarkIndex === 0) {
@ -63,9 +63,7 @@ define('handleBack', [
$('[component="category"]').empty(); $('[component="category"]').empty();
loadTopicsMethod(Math.max(0, bookmarkIndex - 1) + 1, function () { loadTopicsMethod(Math.max(0, bookmarkIndex - 1) + 1, function () {
$(window).one('action:topics.loaded', function () { handleBack.scrollToTopic(bookmarkIndex, clickedIndex);
handleBack.scrollToTopic(bookmarkIndex, clickedIndex, 0);
});
}); });
} }
} }
@ -82,24 +80,17 @@ define('handleBack', [
} }
}; };
handleBack.scrollToTopic = function (bookmarkIndex, clickedIndex, duration, offset) { handleBack.scrollToTopic = function (bookmarkIndex, clickedIndex) {
if (!utils.isNumber(bookmarkIndex)) { if (!utils.isNumber(bookmarkIndex)) {
return; return;
} }
if (!offset) {
offset = 0;
}
var scrollTo = components.get('category/topic', 'index', bookmarkIndex); var scrollTo = components.get('category/topic', 'index', bookmarkIndex);
if (scrollTo.length) { if (scrollTo.length) {
$('html, body').animate({ $(window).scrollTop(scrollTo.offset().top);
scrollTop: (scrollTo.offset().top - offset) + 'px', handleBack.highlightTopic(clickedIndex);
}, duration !== undefined ? duration : 400, function () { navigator.update();
handleBack.highlightTopic(clickedIndex);
navigator.update();
});
} }
}; };

@ -18,12 +18,11 @@ define('topicList', ['forum/infinitescroll', 'handleBack', 'topicSelect'], funct
$(window).on('action:ajaxify.start', function () { $(window).on('action:ajaxify.start', function () {
TopicList.removeListeners(); TopicList.removeListeners();
loadTopicsCallback = null;
}); });
TopicList.init = function (template, cb) { TopicList.init = function (template, cb) {
templateName = template; templateName = template;
loadTopicsCallback = cb; loadTopicsCallback = cb || loadTopicsAfter;
TopicList.watchForNewPosts(); TopicList.watchForNewPosts();
@ -33,8 +32,13 @@ define('topicList', ['forum/infinitescroll', 'handleBack', 'topicSelect'], funct
infinitescroll.init(TopicList.loadMoreTopics); infinitescroll.init(TopicList.loadMoreTopics);
} }
handleBack.init(function (after, cb) { handleBack.init(function (after, handleBackCallback) {
loadTopicsAfter(after, 1, cb); loadTopicsCallback(after, 1, function (data, loadCallback) {
TopicList.onTopicsLoaded(templateName, data.topics, ajaxify.data.showSelect, 1, function () {
handleBackCallback();
loadCallback();
});
});
}); });
if ($('body').height() <= $(window).height() && $('[component="category"]').children().length >= 20) { if ($('body').height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
@ -202,14 +206,8 @@ define('topicList', ['forum/infinitescroll', 'handleBack', 'topicSelect'], funct
return; return;
} }
var loadFn = loadTopicsCallback || loadTopicsAfter; loadTopicsCallback(after, direction, function (data, done) {
loadFn(after, direction, function (data, done) { TopicList.onTopicsLoaded(templateName, data.topics, ajaxify.data.showSelect, direction, done);
if (data.topics && data.topics.length) {
TopicList.onTopicsLoaded(templateName, data.topics, ajaxify.data.showSelect, direction, done);
} else {
done();
$('#load-more-btn').hide();
}
}); });
}; };
@ -229,12 +227,21 @@ define('topicList', ['forum/infinitescroll', 'handleBack', 'topicSelect'], funct
}, callback); }, callback);
} }
TopicList.onTopicsLoaded = function (templateName, topics, showSelect, direction, callback) { function filterTopicsOnDom(topics) {
topics = topics.filter(function (topic) { return topics.filter(function (topic) {
return !$('[component="category/topic"][data-tid="' + topic.tid + '"]').length; return !$('[component="category/topic"][data-tid="' + topic.tid + '"]').length;
}); });
}
TopicList.onTopicsLoaded = function (templateName, topics, showSelect, direction, callback) {
if (!topics || !topics.length) {
$('#load-more-btn').hide();
return callback();
}
topics = filterTopicsOnDom(topics);
if (!topics.length) { if (!topics.length) {
$('#load-more-btn').hide();
return callback(); return callback();
} }

Loading…
Cancel
Save