move removeExtra to IS

v1.18.x
barisusakli 10 years ago
parent 8c17de4221
commit 6457cd02ab

@ -10,6 +10,7 @@ define('forum/category', [
'sort',
'components',
'translator'
], function(pagination, infinitescroll, share, navigator, categoryTools, sort, components, translator) {
var Category = {};
@ -307,60 +308,34 @@ define('forum/category', [
before = topics.first();
}
templates.parse('category', 'topics', data, function(html) {
translator.translate(html, function(translatedHTML) {
var container = $('[component="category"]'),
html = $(translatedHTML);
$('[component="category"]').removeClass('hidden');
$('.category-sidebar').removeClass('hidden');
$('#category-no-topics').remove();
if (after) {
html.insertAfter(after);
} else if (before) {
var height = $(document).height(),
scrollTop = $(window).scrollTop();
html.insertBefore(before);
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
container.append(html);
}
removeExtraTopics(direction);
infinitescroll.parseAndTranslate('category', 'topics', data, function(html) {
$('[component="category"]').removeClass('hidden');
$('.category-sidebar').removeClass('hidden');
if (typeof callback === 'function') {
callback();
}
$('#category-no-topics').remove();
html.find('.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
});
};
function removeExtraTopics(direction) {
var topics = $('[component="category/topic"]');
if (topics.length > 60) {
var removeCount = topics.length - 60;
if (direction > 0) {
if (after) {
html.insertAfter(after);
} else if (before) {
var height = $(document).height(),
scrollTop = $(window).scrollTop();
scrollTop = $(window).scrollTop();
topics.slice(0, removeCount).remove();
html.insertBefore(before);
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
topics.slice(topics.length - removeCount).remove();
$('[component="category"]').append(html);
}
}
}
infinitescroll.removeExtra($('[component="category/topic"]'), direction, 60);
html.find('.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
callback();
});
};
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) {

Loading…
Cancel
Save