From 5b6acbad1e14b6c4f7b539230ff0caedaaeda5bd Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 9 Jul 2014 19:23:03 -0400 Subject: [PATCH] optimized widget call by bundling all queries into one for #1428; fixes active users widget crash also fixes b3819fd0766bd3b2a83771fcbf7078635833a3ee properly --- public/src/ajaxify.js | 2 +- public/src/widgets.js | 15 ++++++++++----- src/controllers/api.js | 9 +++++++-- src/routes/api.js | 2 +- src/widgets.js | 1 - 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index a649a243f0..bc97a6bac7 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -93,7 +93,7 @@ var ajaxify = ajaxify || {}; templates.parse(tpl_url, data, function(template) { translator.translate(template, function(translatedTemplate) { $('#content').html(translatedTemplate); - ajaxify.widgets.render(tpl_url, function() { + ajaxify.widgets.render(tpl_url, url, function() { if (typeof callback === 'function') { callback(); } diff --git a/public/src/widgets.js b/public/src/widgets.js index edc4f2bc7e..eb73e95d36 100644 --- a/public/src/widgets.js +++ b/public/src/widgets.js @@ -1,5 +1,5 @@ "use strict"; -/*global ajaxify, socket, templates*/ +/*global ajaxify, templates*/ (function(ajaxify) { ajaxify.widgets = {}; @@ -14,7 +14,7 @@ }); }; - ajaxify.widgets.render = function(tpl_url, callback) { + ajaxify.widgets.render = function(template, url, callback) { var widgetLocations = ['sidebar', 'footer', 'header'], numLocations; $('#content [widget-area]').each(function() { @@ -29,11 +29,16 @@ if (!numLocations) { ajaxify.widgets.reposition(); } - + function renderWidgets(location) { - var area = $('#content [widget-area="' + location + '"]'); + var area = $('#content [widget-area="' + location + '"]'), + areaData = { + location: location, + template: template + '.tpl', + url: url + }; - $.get(RELATIVE_PATH + '/api/widgets/render/' + tpl_url + '/' + location, function(renderedWidgets) { + $.get(RELATIVE_PATH + '/api/widgets/render', areaData, function(renderedWidgets) { var html = ''; for (var i=0; i