diff --git a/public/src/forum/account.js b/public/src/forum/account.js index 41f1310b62..dfe3c9ed11 100644 --- a/public/src/forum/account.js +++ b/public/src/forum/account.js @@ -74,9 +74,12 @@ define(['forum/accountheader'], function(header) { socket.emit('user.isOnline', theirid, Account.handleUserOnline); socket.on('event:new_post', function(data) { - var html = templates.prepare(templates['account'].blocks['posts']).parse(data); - $('.user-recent-posts').prepend(html); - $('.user-recent-posts span.timeago').timeago(); + templates.preload_template('account', function() { + templates['account'].parse({posts:[]}); + var html = templates.prepare(templates['account'].blocks['posts']).parse(data); + $('.user-recent-posts').prepend(html); + $('.user-recent-posts span.timeago').timeago(); + }); }); }); diff --git a/public/src/forum/accountposts.js b/public/src/forum/accountposts.js index 7ca5c37ee9..4f6e09307e 100644 --- a/public/src/forum/accountposts.js +++ b/public/src/forum/accountposts.js @@ -34,20 +34,23 @@ define(['forum/accountheader'], function(header) { } function onTopicsLoaded(posts) { - var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({ - posts: posts - }); - - translator.translate(html, function(translatedHTML) { - - $('#category-no-topics').remove(); - - html = $(translatedHTML); - html.find('img').addClass('img-responsive'); - $('.user-favourite-posts').append(html); - $('span.timeago').timeago(); - app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + templates.preload_template('accountposts', function() { + templates['accountposts'].parse(posts: []); + var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({ + posts: posts + }); + + translator.translate(html, function(translatedHTML) { + + $('#category-no-topics').remove(); + + html = $(translatedHTML); + html.find('img').addClass('img-responsive'); + $('.user-favourite-posts').append(html); + $('span.timeago').timeago(); + app.createUserTooltips(); + app.makeNumbersHumanReadable(html.find('.human-readable-number')); + }); }); } diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js index 144adfd26a..417da007bf 100644 --- a/public/src/forum/admin/categories.js +++ b/public/src/forum/admin/categories.js @@ -117,14 +117,17 @@ define(['uploader'], function(uploader) { timeout: 2000 }); - var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({ - categories: [data] + templates.preload_template('admin/categories', function() { + templates['admin/categories'].parse({categories:[]}); + var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({ + categories: [data] + }); + html = $(html); + html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker); + + $('#entry-container').append(html); + $('#new-category-modal').modal('hide'); }); - html = $(html); - html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker); - - $('#entry-container').append(html); - $('#new-category-modal').modal('hide'); }); } diff --git a/public/src/forum/admin/topics.js b/public/src/forum/admin/topics.js index 545fc6b2a3..bcd4a2f4ec 100644 --- a/public/src/forum/admin/topics.js +++ b/public/src/forum/admin/topics.js @@ -62,20 +62,23 @@ define(function() { var btnEl = $('#topics_loadmore'); if (topics.length > 0) { - var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ - topics: topics - }), - topicsListEl = $('.topics'); + templates.preload_template('admin/topics', function() { + templates['admin/topics'].parse({topics:[]}); + var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ + topics: topics + }), + topicsListEl = $('.topics'); - // Fix relative paths - html = html.replace(/\{relative_path\}/g, RELATIVE_PATH); + // Fix relative paths + 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'); - $('span.timeago').timeago(); + btnEl.html('Load More Topics'); + $('span.timeago').timeago(); + }); } else { // Exhausted all topics btnEl.addClass('disabled'); diff --git a/public/src/forum/admin/users.js b/public/src/forum/admin/users.js index 25e6aee335..1ffabcb4c4 100644 --- a/public/src/forum/admin/users.js +++ b/public/src/forum/admin/users.js @@ -190,27 +190,30 @@ define(function() { return app.alertError(err.message); } - var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ - users: data.users - }), - userListEl = document.querySelector('.users'); - - userListEl.innerHTML = html; - $('.fa-spinner').addClass('none'); - - if (data && data.users.length === 0) { - $('#user-notfound-notify').html('User not found!') - .show() - .addClass('label-danger') - .removeClass('label-success'); - } else { - $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.') - .show() - .addClass('label-success') - .removeClass('label-danger'); - } - - updateButtons(); + templates.preload_template('admin/users', function() { + templates['admin/users'].parse({users:[]}); + var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ + users: data.users + }), + userListEl = document.querySelector('.users'); + + userListEl.innerHTML = html; + $('.fa-spinner').addClass('none'); + + if (data && data.users.length === 0) { + $('#user-notfound-notify').html('User not found!') + .show() + .addClass('label-danger') + .removeClass('label-success'); + } else { + $('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.') + .show() + .addClass('label-success') + .removeClass('label-danger'); + } + + updateButtons(); + }); }); }, 250); }); @@ -220,14 +223,17 @@ define(function() { handleUserCreate(); function onUsersLoaded(users) { - var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ - users: users - }); - html = $(html); - $('#users-container').append(html); + templates.preload_template('admin/users', function() { + templates['admin/users'].parse({users:[]}); + var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ + users: users + }); + html = $(html); + $('#users-container').append(html); - updateUserBanButtons(html.find('.ban-btn')); - updateUserAdminButtons(html.find('.admin-btn')); + updateUserBanButtons(html.find('.ban-btn')); + updateUserAdminButtons(html.find('.admin-btn')); + }); } function loadMoreUsers() { diff --git a/public/src/forum/category.js b/public/src/forum/category.js index 80231bc931..7f94f0b33d 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -162,45 +162,47 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { Category.onNewTopic = function(data) { $(window).trigger('filter:categories.new_topic', data); - - var html = templates.prepare(templates['category'].blocks['topics']).parse({ - topics: [data] - }); - - translator.translate(html, function(translatedHTML) { - var topic = $(translatedHTML), - container = $('#topics-container'), - topics = $('#topics-container').children('.category-item'), - numTopics = topics.length; - - $('#topics-container, .category-sidebar').removeClass('hidden'); - $('#category-no-topics').remove(); - - if (numTopics > 0) { - for (var x = 0; x < numTopics; x++) { - if ($(topics[x]).find('.fa-thumb-tack').length) { - if(x === numTopics - 1) { - topic.insertAfter(topics[x]); + templates.preload_template('category', function() { + templates['category'].parse({topics:[]}); + var html = templates.prepare(templates['category'].blocks['topics']).parse({ + topics: [data] + }); + + translator.translate(html, function(translatedHTML) { + var topic = $(translatedHTML), + container = $('#topics-container'), + topics = $('#topics-container').children('.category-item'), + numTopics = topics.length; + + $('#topics-container, .category-sidebar').removeClass('hidden'); + $('#category-no-topics').remove(); + + if (numTopics > 0) { + for (var x = 0; x < numTopics; x++) { + if ($(topics[x]).find('.fa-thumb-tack').length) { + if(x === numTopics - 1) { + topic.insertAfter(topics[x]); + } + continue; } - continue; + topic.insertBefore(topics[x]); + break; } - topic.insertBefore(topics[x]); - break; + } else { + 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) { - pagination.recreatePaginationLinks(newPageCount); - }); + socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) { + pagination.recreatePaginationLinks(newPageCount); + }); - topic.find('span.timeago').timeago(); - app.createUserTooltips(); + topic.find('span.timeago').timeago(); + app.createUserTooltips(); - $(window).trigger('action:categories.new_topic.loaded'); + $(window).trigger('action:categories.new_topic.loaded'); + }); }); }; @@ -239,36 +241,39 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { findInsertionPoint(); - var html = templates.prepare(templates['category'].blocks['topics']).parse({ - topics: topics - }); + templates.preload_template('category', function() { + templates['category'].parse({topics:[]}); + var html = templates.prepare(templates['category'].blocks['topics']).parse({ + topics: topics + }); - translator.translate(html, function(translatedHTML) { - var container = $('#topics-container'), - html = $(translatedHTML); + translator.translate(html, function(translatedHTML) { + var container = $('#topics-container'), + html = $(translatedHTML); - $('#topics-container, .category-sidebar').removeClass('hidden'); - $('#category-no-topics').remove(); + $('#topics-container, .category-sidebar').removeClass('hidden'); + $('#category-no-topics').remove(); - if(config.usePagination) { - container.empty().append(html); - } else { - if(after) { - html.insertAfter(after); - } else if(before) { - html.insertBefore(before); + if(config.usePagination) { + container.empty().append(html); } else { - container.append(html); + if(after) { + html.insertAfter(after); + } else if(before) { + html.insertBefore(before); + } else { + container.append(html); + } } - } - html.find('span.timeago').timeago(); - app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + html.find('span.timeago').timeago(); + app.createUserTooltips(); + app.makeNumbersHumanReadable(html.find('.human-readable-number')); - if (typeof callback === 'function') { - callback(topics); - } + if (typeof callback === 'function') { + callback(topics); + } + }); }); }; diff --git a/public/src/forum/favourites.js b/public/src/forum/favourites.js index 81fe7fda5e..6bfc07da4b 100644 --- a/public/src/forum/favourites.js +++ b/public/src/forum/favourites.js @@ -33,20 +33,23 @@ define(['forum/accountheader'], function(header) { } function onTopicsLoaded(posts) { - var html = templates.prepare(templates['favourites'].blocks['posts']).parse({ - posts: posts - }); - - translator.translate(html, function(translatedHTML) { - - $('#category-no-topics').remove(); - - html = $(translatedHTML); - html.find('img').addClass('img-responsive'); - $('.user-favourite-posts').append(html); - $('span.timeago').timeago(); - app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + templates.preload_template('favourites', function() { + templates['favourites'].parse({posts:[]}); + var html = templates.prepare(templates['favourites'].blocks['posts']).parse({ + posts: posts + }); + + translator.translate(html, function(translatedHTML) { + + $('#category-no-topics').remove(); + + html = $(translatedHTML); + html.find('img').addClass('img-responsive'); + $('.user-favourite-posts').append(html); + $('span.timeago').timeago(); + app.createUserTooltips(); + app.makeNumbersHumanReadable(html.find('.human-readable-number')); + }); }); } diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js index 8c7d6c3b32..e75ecad06b 100644 --- a/public/src/forum/recent.js +++ b/public/src/forum/recent.js @@ -116,19 +116,22 @@ define(function() { } Recent.onTopicsLoaded = function(template, topics) { - var html = templates.prepare(templates[template].blocks['topics']).parse({ - topics: topics - }); - - translator.translate(html, function(translatedHTML) { - - $('#category-no-topics').remove(); - - html = $(translatedHTML); - $('#topics-container').append(html); - $('span.timeago').timeago(); - app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + templates.preload_template(template, function() { + templates[template].parse({topics:[]}); + var html = templates.prepare(templates[template].blocks['topics']).parse({ + topics: topics + }); + + translator.translate(html, function(translatedHTML) { + + $('#category-no-topics').remove(); + + html = $(translatedHTML); + $('#topics-container').append(html); + $('span.timeago').timeago(); + app.createUserTooltips(); + app.makeNumbersHumanReadable(html.find('.human-readable-number')); + }); }); } diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 2280bb728f..6f7cc1a4b4 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -1233,8 +1233,11 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } function parseAndTranslatePosts(data, callback) { - var html = templates.prepare(templates['topic'].blocks['posts']).parse(data); - translator.translate(html, callback); + templates.preload_template('topic', function() { + templates['topic'].parse({posts: []}); + var html = templates.prepare(templates['topic'].blocks['posts']).parse(data); + translator.translate(html, callback); + }); } diff --git a/public/src/forum/users.js b/public/src/forum/users.js index e64b29ec00..4106ebde34 100644 --- a/public/src/forum/users.js +++ b/public/src/forum/users.js @@ -59,22 +59,24 @@ define(function() { return; } - var html = templates.prepare(templates['users'].blocks['users']).parse({ - users: data.users - }), - userListEl = $('#users-container'); - - userListEl.html(html); - - - if (data && data.users.length === 0) { - $('#user-notfound-notify').html('User not found!'); - $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); - } else { - $('#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'); - } - + templates.preload_template('users', function() { + templates['users'].parse({users:[]}); + var html = templates.prepare(templates['users'].blocks['users']).parse({ + users: data.users + }), + userListEl = $('#users-container'); + + userListEl.html(html); + + + if (data && data.users.length === 0) { + $('#user-notfound-notify').html('User not found!'); + $('#user-notfound-notify').parent().addClass('btn-warning label-warning'); + } else { + $('#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'); + } + }); }); }, 500); //replace this with global throttling function/constant @@ -108,17 +110,20 @@ define(function() { } function onUsersLoaded(users, emptyContainer) { - var html = templates.prepare(templates['users'].blocks['users']).parse({ - users: users - }); + templates.preload_template('users', function() { + templates['useres'].parse({users:[]}); + var html = templates.prepare(templates['users'].blocks['users']).parse({ + users: users + }); - translator.translate(html, function(translated) { - if(emptyContainer) { - $('#users-container .registered-user').remove(); - } + translator.translate(html, function(translated) { + if(emptyContainer) { + $('#users-container .registered-user').remove(); + } - $('#users-container').append(translated); - $('#users-container .anon-user').appendTo($('#users-container')); + $('#users-container').append(translated); + $('#users-container .anon-user').appendTo($('#users-container')); + }); }); }