From 49997639e98eb37c74ba0d194c434ba295f0ac8e Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 28 Feb 2014 16:08:25 -0500 Subject: [PATCH] moved widget rendering code into ajaxify.renderWidgets --- public/src/ajaxify.js | 69 ++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 47a6a0b2a0..a302e81aea 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -110,38 +110,12 @@ var ajaxify = {}; app.processPage(); - var widgetLocations = []; - - require(['vendor/async'], function(async) { - $('#content [widget-area]').each(function() { - widgetLocations.push($(this).attr('widget-area')); - }); - - async.each(widgetLocations, function(location, next) { - var area = $('#content [widget-area="' + location + '"]'); - - socket.emit('widgets.render', {template: tpl_url + '.tpl', url: url, location: location}, function(err, renderedWidgets) { - area.html(templates.prepare(area.html()).parse({ - widgets: renderedWidgets - })).removeClass('hidden'); - - if (!renderedWidgets.length) { - $('body [no-widget-class]').each(function() { - var $this = $(this); - $this.removeClass(); - $this.addClass($this.attr('no-widget-class')); - }); - } - - next(err); - }); - }, function(err) { - $('#content, #footer').stop(true, true).removeClass('ajaxifying'); - ajaxify.initialLoad = false; + ajaxify.renderWidgets(tpl_url, url, location, function(err) { + $('#content, #footer').stop(true, true).removeClass('ajaxifying'); + ajaxify.initialLoad = false; - app.refreshTitle(url); - $(window).trigger('action:ajaxify.end', { url: url }); - }); + app.refreshTitle(url); + $(window).trigger('action:ajaxify.end', { url: url }); }); }, url); @@ -151,6 +125,39 @@ var ajaxify = {}; return false; }; + ajaxify.renderWidgets = function(tpl_url, url, location, callback) { + var widgetLocations = []; + + require(['vendor/async'], function(async) { + $('#content [widget-area]').each(function() { + widgetLocations.push($(this).attr('widget-area')); + }); + + async.each(widgetLocations, function(location, next) { + var area = $('#content [widget-area="' + location + '"]'); + + socket.emit('widgets.render', {template: tpl_url + '.tpl', url: url, location: location}, function(err, renderedWidgets) { + area.html(templates.prepare(area.html()).parse({ + widgets: renderedWidgets + })).removeClass('hidden'); + + if (!renderedWidgets.length) { + $('body [no-widget-class]').each(function() { + var $this = $(this); + $this.removeClass(); + $this.addClass($this.attr('no-widget-class')); + }); + } + + next(err); + }); + }, function(err) { + callback(err); + }); + }); + }; + + ajaxify.refresh = function() { ajaxify.go(ajaxify.currentPage); };