"use strict"; /*global ajaxify, templates, config, RELATIVE_PATH*/ (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) { if (template.match(/^admin/)) { return 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' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''), { locations: locations, template: template + '.tpl', url: url, isMobile: utils.isMobile() }, function(renderedAreas) { for (var x=0; x
')); } else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) { if ($('[component="account/cover"]').length) { $('[component="account/cover"]').nextAll().wrapAll($('
')); } else if ($('[component="groups/cover"]').length) { $('[component="groups/cover"]').nextAll().wrapAll($('
')); } else { $('#content > *').wrapAll($('
')); } } 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); } } var widgetAreas = $('#content [widget-area]'); widgetAreas.find('img:not(.not-responsive)').addClass('img-responsive'); widgetAreas.find('.timeago').timeago(); widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function() { $(this).tooltip({ placement: 'top', title: $(this).attr('title') }); }); $(window).trigger('action:widgets.loaded', {}); if (typeof callback === 'function') { callback(); } }); } renderWidgets(widgetLocations); }; }(ajaxify || {}));