mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
move removeExtra to IS
This commit is contained in:
@@ -10,6 +10,7 @@ define('forum/category', [
|
||||
'sort',
|
||||
'components',
|
||||
'translator'
|
||||
|
||||
], function(pagination, infinitescroll, share, navigator, categoryTools, sort, components, translator) {
|
||||
var Category = {};
|
||||
|
||||
@@ -307,17 +308,12 @@ define('forum/category', [
|
||||
before = topics.first();
|
||||
}
|
||||
|
||||
templates.parse('category', 'topics', data, function(html) {
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var container = $('[component="category"]'),
|
||||
html = $(translatedHTML);
|
||||
|
||||
infinitescroll.parseAndTranslate('category', 'topics', data, function(html) {
|
||||
$('[component="category"]').removeClass('hidden');
|
||||
$('.category-sidebar').removeClass('hidden');
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
|
||||
if (after) {
|
||||
html.insertAfter(after);
|
||||
} else if (before) {
|
||||
@@ -328,39 +324,18 @@ define('forum/category', [
|
||||
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
container.append(html);
|
||||
$('[component="category"]').append(html);
|
||||
}
|
||||
|
||||
removeExtraTopics(direction);
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
infinitescroll.removeExtra($('[component="category/topic"]'), direction, 60);
|
||||
|
||||
html.find('.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
function removeExtraTopics(direction) {
|
||||
var topics = $('[component="category/topic"]');
|
||||
if (topics.length > 60) {
|
||||
var removeCount = topics.length - 60;
|
||||
if (direction > 0) {
|
||||
var height = $(document).height(),
|
||||
scrollTop = $(window).scrollTop();
|
||||
|
||||
topics.slice(0, removeCount).remove();
|
||||
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
topics.slice(topics.length - removeCount).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Category;
|
||||
});
|
||||
@@ -68,5 +68,23 @@ define('forum/infinitescroll', ['translator'], function(translator) {
|
||||
});
|
||||
};
|
||||
|
||||
scroll.removeExtra = function(els, direction, count) {
|
||||
if (els.length <= count) {
|
||||
return;
|
||||
}
|
||||
|
||||
var removeCount = els.length - count;
|
||||
if (direction > 0) {
|
||||
var height = $(document).height(),
|
||||
scrollTop = $(window).scrollTop();
|
||||
|
||||
els.slice(0, removeCount).remove();
|
||||
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
els.slice(els.length - removeCount).remove();
|
||||
}
|
||||
};
|
||||
|
||||
return scroll;
|
||||
});
|
||||
@@ -152,7 +152,7 @@ define('forum/topic/posts', [
|
||||
components.get('topic').append(html);
|
||||
}
|
||||
|
||||
removeExtraPosts(direction);
|
||||
infinitescroll.removeExtra(components.get('posts'), direction, 40);
|
||||
|
||||
html.hide().fadeIn('slow');
|
||||
|
||||
@@ -167,23 +167,6 @@ define('forum/topic/posts', [
|
||||
});
|
||||
}
|
||||
|
||||
function removeExtraPosts(direction) {
|
||||
var posts = components.get('post');
|
||||
if (posts.length > 40) {
|
||||
var removeCount = posts.length - 40;
|
||||
if (direction > 0) {
|
||||
var height = $(document).height(),
|
||||
scrollTop = $(window).scrollTop();
|
||||
|
||||
posts.slice(0, removeCount).remove();
|
||||
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
posts.slice(posts.length - removeCount).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onNewPostsLoaded(html, pids) {
|
||||
if (app.user.uid) {
|
||||
socket.emit('posts.getPrivileges', pids, function(err, privileges) {
|
||||
|
||||
Reference in New Issue
Block a user