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