mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
fixed pagination, and loading of template blocks on cold load (temp solution)
This commit is contained in:
@@ -74,9 +74,12 @@ define(['forum/accountheader'], function(header) {
|
|||||||
socket.emit('user.isOnline', theirid, Account.handleUserOnline);
|
socket.emit('user.isOnline', theirid, Account.handleUserOnline);
|
||||||
|
|
||||||
socket.on('event:new_post', function(data) {
|
socket.on('event:new_post', function(data) {
|
||||||
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
|
templates.preload_template('account', function() {
|
||||||
$('.user-recent-posts').prepend(html);
|
templates['account'].parse({posts:[]});
|
||||||
$('.user-recent-posts span.timeago').timeago();
|
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
|
||||||
|
$('.user-recent-posts').prepend(html);
|
||||||
|
$('.user-recent-posts span.timeago').timeago();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,20 +34,23 @@ define(['forum/accountheader'], function(header) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onTopicsLoaded(posts) {
|
function onTopicsLoaded(posts) {
|
||||||
var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({
|
templates.preload_template('accountposts', function() {
|
||||||
posts: posts
|
templates['accountposts'].parse(posts: []);
|
||||||
});
|
var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({
|
||||||
|
posts: posts
|
||||||
|
});
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
html.find('img').addClass('img-responsive');
|
html.find('img').addClass('img-responsive');
|
||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,14 +117,17 @@ define(['uploader'], function(uploader) {
|
|||||||
timeout: 2000
|
timeout: 2000
|
||||||
});
|
});
|
||||||
|
|
||||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
templates.preload_template('admin/categories', function() {
|
||||||
categories: [data]
|
templates['admin/categories'].parse({categories:[]});
|
||||||
});
|
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
||||||
html = $(html);
|
categories: [data]
|
||||||
html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
});
|
||||||
|
html = $(html);
|
||||||
|
html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||||
|
|
||||||
$('#entry-container').append(html);
|
$('#entry-container').append(html);
|
||||||
$('#new-category-modal').modal('hide');
|
$('#new-category-modal').modal('hide');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,20 +62,23 @@ define(function() {
|
|||||||
var btnEl = $('#topics_loadmore');
|
var btnEl = $('#topics_loadmore');
|
||||||
|
|
||||||
if (topics.length > 0) {
|
if (topics.length > 0) {
|
||||||
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
templates.preload_template('admin/topics', function() {
|
||||||
topics: topics
|
templates['admin/topics'].parse({topics:[]});
|
||||||
}),
|
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
||||||
topicsListEl = $('.topics');
|
topics: topics
|
||||||
|
}),
|
||||||
|
topicsListEl = $('.topics');
|
||||||
|
|
||||||
// Fix relative paths
|
// Fix relative paths
|
||||||
html = html.replace(/\{relative_path\}/g, RELATIVE_PATH);
|
html = html.replace(/\{relative_path\}/g, RELATIVE_PATH);
|
||||||
|
|
||||||
topicsListEl.html(topicsListEl.html() + html);
|
topicsListEl.html(topicsListEl.html() + html);
|
||||||
|
|
||||||
Topics.resolveButtonStates();
|
Topics.resolveButtonStates();
|
||||||
|
|
||||||
btnEl.html('Load More Topics');
|
btnEl.html('Load More Topics');
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Exhausted all topics
|
// Exhausted all topics
|
||||||
btnEl.addClass('disabled');
|
btnEl.addClass('disabled');
|
||||||
|
|||||||
@@ -190,27 +190,30 @@ define(function() {
|
|||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
templates.preload_template('admin/users', function() {
|
||||||
users: data.users
|
templates['admin/users'].parse({users:[]});
|
||||||
}),
|
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||||
userListEl = document.querySelector('.users');
|
users: data.users
|
||||||
|
}),
|
||||||
|
userListEl = document.querySelector('.users');
|
||||||
|
|
||||||
userListEl.innerHTML = html;
|
userListEl.innerHTML = html;
|
||||||
$('.fa-spinner').addClass('none');
|
$('.fa-spinner').addClass('none');
|
||||||
|
|
||||||
if (data && data.users.length === 0) {
|
if (data && data.users.length === 0) {
|
||||||
$('#user-notfound-notify').html('User not found!')
|
$('#user-notfound-notify').html('User not found!')
|
||||||
.show()
|
.show()
|
||||||
.addClass('label-danger')
|
.addClass('label-danger')
|
||||||
.removeClass('label-success');
|
.removeClass('label-success');
|
||||||
} else {
|
} else {
|
||||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.')
|
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.')
|
||||||
.show()
|
.show()
|
||||||
.addClass('label-success')
|
.addClass('label-success')
|
||||||
.removeClass('label-danger');
|
.removeClass('label-danger');
|
||||||
}
|
}
|
||||||
|
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, 250);
|
}, 250);
|
||||||
});
|
});
|
||||||
@@ -220,14 +223,17 @@ define(function() {
|
|||||||
handleUserCreate();
|
handleUserCreate();
|
||||||
|
|
||||||
function onUsersLoaded(users) {
|
function onUsersLoaded(users) {
|
||||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
templates.preload_template('admin/users', function() {
|
||||||
users: users
|
templates['admin/users'].parse({users:[]});
|
||||||
});
|
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||||
html = $(html);
|
users: users
|
||||||
$('#users-container').append(html);
|
});
|
||||||
|
html = $(html);
|
||||||
|
$('#users-container').append(html);
|
||||||
|
|
||||||
updateUserBanButtons(html.find('.ban-btn'));
|
updateUserBanButtons(html.find('.ban-btn'));
|
||||||
updateUserAdminButtons(html.find('.admin-btn'));
|
updateUserAdminButtons(html.find('.admin-btn'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMoreUsers() {
|
function loadMoreUsers() {
|
||||||
|
|||||||
@@ -162,45 +162,47 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
Category.onNewTopic = function(data) {
|
Category.onNewTopic = function(data) {
|
||||||
$(window).trigger('filter:categories.new_topic', data);
|
$(window).trigger('filter:categories.new_topic', data);
|
||||||
|
templates.preload_template('category', function() {
|
||||||
|
templates['category'].parse({topics:[]});
|
||||||
|
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||||
|
topics: [data]
|
||||||
|
});
|
||||||
|
|
||||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
translator.translate(html, function(translatedHTML) {
|
||||||
topics: [data]
|
var topic = $(translatedHTML),
|
||||||
});
|
container = $('#topics-container'),
|
||||||
|
topics = $('#topics-container').children('.category-item'),
|
||||||
|
numTopics = topics.length;
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||||
var topic = $(translatedHTML),
|
$('#category-no-topics').remove();
|
||||||
container = $('#topics-container'),
|
|
||||||
topics = $('#topics-container').children('.category-item'),
|
|
||||||
numTopics = topics.length;
|
|
||||||
|
|
||||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
if (numTopics > 0) {
|
||||||
$('#category-no-topics').remove();
|
for (var x = 0; x < numTopics; x++) {
|
||||||
|
if ($(topics[x]).find('.fa-thumb-tack').length) {
|
||||||
if (numTopics > 0) {
|
if(x === numTopics - 1) {
|
||||||
for (var x = 0; x < numTopics; x++) {
|
topic.insertAfter(topics[x]);
|
||||||
if ($(topics[x]).find('.fa-thumb-tack').length) {
|
}
|
||||||
if(x === numTopics - 1) {
|
continue;
|
||||||
topic.insertAfter(topics[x]);
|
|
||||||
}
|
}
|
||||||
continue;
|
topic.insertBefore(topics[x]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
topic.insertBefore(topics[x]);
|
} else {
|
||||||
break;
|
container.append(topic);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
container.append(topic);
|
|
||||||
}
|
|
||||||
|
|
||||||
topic.hide().fadeIn('slow');
|
topic.hide().fadeIn('slow');
|
||||||
|
|
||||||
socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) {
|
socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) {
|
||||||
pagination.recreatePaginationLinks(newPageCount);
|
pagination.recreatePaginationLinks(newPageCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
topic.find('span.timeago').timeago();
|
||||||
|
app.createUserTooltips();
|
||||||
|
|
||||||
|
$(window).trigger('action:categories.new_topic.loaded');
|
||||||
});
|
});
|
||||||
|
|
||||||
topic.find('span.timeago').timeago();
|
|
||||||
app.createUserTooltips();
|
|
||||||
|
|
||||||
$(window).trigger('action:categories.new_topic.loaded');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -239,36 +241,39 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
findInsertionPoint();
|
findInsertionPoint();
|
||||||
|
|
||||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
templates.preload_template('category', function() {
|
||||||
topics: topics
|
templates['category'].parse({topics:[]});
|
||||||
});
|
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||||
|
topics: topics
|
||||||
|
});
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
var container = $('#topics-container'),
|
var container = $('#topics-container'),
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
|
|
||||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
if(config.usePagination) {
|
if(config.usePagination) {
|
||||||
container.empty().append(html);
|
container.empty().append(html);
|
||||||
} else {
|
|
||||||
if(after) {
|
|
||||||
html.insertAfter(after);
|
|
||||||
} else if(before) {
|
|
||||||
html.insertBefore(before);
|
|
||||||
} else {
|
} else {
|
||||||
container.append(html);
|
if(after) {
|
||||||
|
html.insertAfter(after);
|
||||||
|
} else if(before) {
|
||||||
|
html.insertBefore(before);
|
||||||
|
} else {
|
||||||
|
container.append(html);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback(topics);
|
callback(topics);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,20 +33,23 @@ define(['forum/accountheader'], function(header) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onTopicsLoaded(posts) {
|
function onTopicsLoaded(posts) {
|
||||||
var html = templates.prepare(templates['favourites'].blocks['posts']).parse({
|
templates.preload_template('favourites', function() {
|
||||||
posts: posts
|
templates['favourites'].parse({posts:[]});
|
||||||
});
|
var html = templates.prepare(templates['favourites'].blocks['posts']).parse({
|
||||||
|
posts: posts
|
||||||
|
});
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
html.find('img').addClass('img-responsive');
|
html.find('img').addClass('img-responsive');
|
||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,19 +116,22 @@ define(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Recent.onTopicsLoaded = function(template, topics) {
|
Recent.onTopicsLoaded = function(template, topics) {
|
||||||
var html = templates.prepare(templates[template].blocks['topics']).parse({
|
templates.preload_template(template, function() {
|
||||||
topics: topics
|
templates[template].parse({topics:[]});
|
||||||
});
|
var html = templates.prepare(templates[template].blocks['topics']).parse({
|
||||||
|
topics: topics
|
||||||
|
});
|
||||||
|
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
$('#topics-container').append(html);
|
$('#topics-container').append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1233,8 +1233,11 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseAndTranslatePosts(data, callback) {
|
function parseAndTranslatePosts(data, callback) {
|
||||||
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
|
templates.preload_template('topic', function() {
|
||||||
translator.translate(html, callback);
|
templates['topic'].parse({posts: []});
|
||||||
|
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
|
||||||
|
translator.translate(html, callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,22 +59,24 @@ define(function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
templates.preload_template('users', function() {
|
||||||
users: data.users
|
templates['users'].parse({users:[]});
|
||||||
}),
|
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||||
userListEl = $('#users-container');
|
users: data.users
|
||||||
|
}),
|
||||||
|
userListEl = $('#users-container');
|
||||||
|
|
||||||
userListEl.html(html);
|
userListEl.html(html);
|
||||||
|
|
||||||
|
|
||||||
if (data && data.users.length === 0) {
|
if (data && data.users.length === 0) {
|
||||||
$('#user-notfound-notify').html('User not found!');
|
$('#user-notfound-notify').html('User not found!');
|
||||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||||
} else {
|
} else {
|
||||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
||||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, 500); //replace this with global throttling function/constant
|
}, 500); //replace this with global throttling function/constant
|
||||||
|
|
||||||
@@ -108,17 +110,20 @@ define(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onUsersLoaded(users, emptyContainer) {
|
function onUsersLoaded(users, emptyContainer) {
|
||||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
templates.preload_template('users', function() {
|
||||||
users: users
|
templates['useres'].parse({users:[]});
|
||||||
});
|
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||||
|
users: users
|
||||||
|
});
|
||||||
|
|
||||||
translator.translate(html, function(translated) {
|
translator.translate(html, function(translated) {
|
||||||
if(emptyContainer) {
|
if(emptyContainer) {
|
||||||
$('#users-container .registered-user').remove();
|
$('#users-container .registered-user').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#users-container').append(translated);
|
$('#users-container').append(translated);
|
||||||
$('#users-container .anon-user').appendTo($('#users-container'));
|
$('#users-container .anon-user').appendTo($('#users-container'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user