"use strict"; /*global ajaxify, templates*/ (function(ajaxify) { ajaxify.widgets = {}; ajaxify.widgets.reposition = function(location) { $('body [no-widget-class]').each(function() { var $this = $(this); if ($this.attr('no-widget-target') === location) { $this.removeClass(); $this.addClass($this.attr('no-widget-class')); } }); }; ajaxify.widgets.render = function(template, url, callback) { var widgetLocations = ['sidebar', 'footer', 'header'], numLocations; $('#content [widget-area]').each(function() { var location = $(this).attr('widget-area'); if ($.inArray(location, widgetLocations) === -1) { widgetLocations.push(location); } }); numLocations = widgetLocations.length; if (!numLocations) { ajaxify.widgets.reposition(); } 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($('
')); } area = $('#content [widget-area="' + location + '"]'); } area.html(html); 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(); } }); } renderWidgets(widgetLocations); }; }(ajaxify || {}));