mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
closes #5116
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
ajaxify.widgets = {};
|
||||
|
||||
ajaxify.widgets.reposition = function (location) {
|
||||
$('body [no-widget-class]').each(function () {
|
||||
$('body [has-widget-class]').each(function () {
|
||||
var $this = $(this);
|
||||
if ($this.attr('no-widget-target') === location) {
|
||||
if ($this.attr('has-widget-target') === location) {
|
||||
$this.removeClass();
|
||||
$this.addClass($this.attr('no-widget-class'));
|
||||
$this.addClass($this.attr('has-widget-class'));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -20,7 +20,7 @@
|
||||
return callback();
|
||||
}
|
||||
|
||||
var widgetLocations = ['sidebar', 'footer', 'header'], numLocations;
|
||||
var widgetLocations = ['sidebar', 'footer', 'header'];
|
||||
|
||||
$('#content [widget-area]').each(function () {
|
||||
var location = $(this).attr('widget-area');
|
||||
@@ -29,71 +29,61 @@
|
||||
}
|
||||
});
|
||||
|
||||
numLocations = widgetLocations.length;
|
||||
$.get(config.relative_path + '/api/widgets/render' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''), {
|
||||
locations: widgetLocations,
|
||||
template: template + '.tpl',
|
||||
url: url,
|
||||
isMobile: utils.isMobile()
|
||||
}, function (renderedAreas) {
|
||||
for (var x = 0; x < renderedAreas.length; ++x) {
|
||||
var renderedWidgets = renderedAreas[x].widgets;
|
||||
var location = renderedAreas[x].location;
|
||||
var html = '';
|
||||
|
||||
if (!numLocations) {
|
||||
ajaxify.widgets.reposition();
|
||||
}
|
||||
|
||||
function renderWidgets(locations) {
|
||||
$.get(config.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 < renderedAreas.length; ++x) {
|
||||
var renderedWidgets = renderedAreas[x].widgets,
|
||||
location = renderedAreas[x].location,
|
||||
html = '';
|
||||
|
||||
for (var i = 0; i < renderedWidgets.length; ++i) {
|
||||
html += templates.parse(renderedWidgets[i].html, {});
|
||||
}
|
||||
|
||||
var area = $('#content [widget-area="' + location + '"]');
|
||||
|
||||
if (!area.length && window.location.pathname.indexOf('/admin') === -1 && renderedWidgets.length) {
|
||||
if (location === 'footer' && !$('#content [widget-area="footer"]').length) {
|
||||
$('#content').append($('<div class="row"><div widget-area="footer" class="col-xs-12"></div></div>'));
|
||||
} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) {
|
||||
if ($('[component="account/cover"]').length) {
|
||||
$('[component="account/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
} else if ($('[component="groups/cover"]').length) {
|
||||
$('[component="groups/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
} else {
|
||||
$('#content > *').wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
}
|
||||
} else if (location === 'header' && !$('#content [widget-area="header"]').length) {
|
||||
$('#content').prepend($('<div class="row"><div widget-area="header" class="col-xs-12"></div></div>'));
|
||||
}
|
||||
|
||||
area = $('#content [widget-area="' + location + '"]');
|
||||
}
|
||||
|
||||
area.html(html);
|
||||
|
||||
if (!renderedWidgets.length) {
|
||||
area.addClass('hidden');
|
||||
ajaxify.widgets.reposition(location);
|
||||
}
|
||||
for (var i = 0; i < renderedWidgets.length; ++i) {
|
||||
html += templates.parse(renderedWidgets[i].html, {});
|
||||
}
|
||||
|
||||
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')
|
||||
});
|
||||
var area = $('#content [widget-area="' + location + '"]');
|
||||
|
||||
if (!area.length && window.location.pathname.indexOf('/admin') === -1 && renderedWidgets.length) {
|
||||
if (location === 'footer' && !$('#content [widget-area="footer"]').length) {
|
||||
$('#content').append($('<div class="row"><div widget-area="footer" class="col-xs-12"></div></div>'));
|
||||
} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) {
|
||||
if ($('[component="account/cover"]').length) {
|
||||
$('[component="account/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
} else if ($('[component="groups/cover"]').length) {
|
||||
$('[component="groups/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
} else {
|
||||
$('#content > *').wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||
}
|
||||
} else if (location === 'header' && !$('#content [widget-area="header"]').length) {
|
||||
$('#content').prepend($('<div class="row"><div widget-area="header" class="col-xs-12"></div></div>'));
|
||||
}
|
||||
|
||||
area = $('#content [widget-area="' + location + '"]');
|
||||
}
|
||||
|
||||
area.html(html);
|
||||
|
||||
if (renderedWidgets.length) {
|
||||
area.removeClass('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', {});
|
||||
|
||||
callback(renderedAreas);
|
||||
});
|
||||
}
|
||||
$(window).trigger('action:widgets.loaded', {});
|
||||
|
||||
renderWidgets(widgetLocations);
|
||||
callback(renderedAreas);
|
||||
});
|
||||
};
|
||||
}(ajaxify || {}));
|
||||
|
||||
Reference in New Issue
Block a user