From ecd00bb679eab63eb9a77b546628f4ff90c019d7 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 16 Sep 2014 10:12:12 -0400 Subject: [PATCH] refactored widgets api call to render all at once rather than one area at a time, closes https://github.com/NodeBB/NodeBB/issues/2062 --- public/src/widgets.js | 82 ++++++++++++++++++++---------------------- src/controllers/api.js | 29 +++++++++++---- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/public/src/widgets.js b/public/src/widgets.js index 23a37e4222..32b01f599f 100644 --- a/public/src/widgets.js +++ b/public/src/widgets.js @@ -30,60 +30,56 @@ ajaxify.widgets.reposition(); } - function renderWidgets(location) { - var area = $('#content [widget-area="' + location + '"]'), - areaData = { - location: location, - template: template + '.tpl', - url: url - }; - - $.get(RELATIVE_PATH + '/api/widgets/render', areaData, function(renderedWidgets) { - var html = ''; - - for (var i=0; i
')); - } else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) { - $('#content > *').wrapAll($('
')); - $('#content').append($('
')); - } else if (location === 'header' && !$('#content [widget-area="header"]').length) { - $('#content').prepend($('
')); + function renderWidgets(locations) { + var areaDatas = []; + + $.get(RELATIVE_PATH + '/api/widgets/render', { + locations: locations, + template: template + '.tpl', + url: url + }, function(renderedAreas) { + for (var x=0; x
')); + } else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) { + $('#content > *').wrapAll($('
')); + $('#content').append($('
')); + } else if (location === 'header' && !$('#content [widget-area="header"]').length) { + $('#content').prepend($('
')); + } - if (!renderedWidgets.length) { - area.addClass('hidden'); - ajaxify.widgets.reposition(location); - } + area = $('#content [widget-area="' + location + '"]'); + } - $('#content [widget-area] img:not(.user-img)').addClass('img-responsive'); - checkCallback(); - }); - } + area.html(html); - function checkCallback() { - numLocations--; - if (numLocations < 0) { + if (!renderedWidgets.length) { + area.addClass('hidden'); + ajaxify.widgets.reposition(location); + } + + $('#content [widget-area] img:not(.user-img)').addClass('img-responsive'); + } + $(window).trigger('action:widgets.loaded', {}); + if (typeof callback === 'function') { callback(); } - } - } - - for (var i=0; i