You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/public/src/widgets.js

76 lines
2.6 KiB
JavaScript

8 years ago
'use strict';
(function (ajaxify) {
11 years ago
ajaxify.widgets = {};
11 years ago
ajaxify.widgets.reposition = function (location) {
8 years ago
$('body [has-widget-class]').each(function () {
var $this = $(this);
8 years ago
if ($this.attr('has-widget-target') === location) {
$this.removeClass();
8 years ago
$this.addClass($this.attr('has-widget-class'));
}
});
};
ajaxify.widgets.render = function (template, callback) {
callback = callback || function () {};
10 years ago
if (template.match(/^admin/)) {
return callback();
10 years ago
}
10 years ago
var locations = Object.keys(ajaxify.data.widgets);
locations.forEach(function (location) {
var area = $('#content [widget-area="' + location + '"]');
if (area.length) {
return;
}
var widgetsAtLocation = ajaxify.data.widgets[location] || [];
var html = '';
8 years ago
widgetsAtLocation.forEach(function (widget) {
html += widget.html;
8 years ago
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>'));
8 years ago
}
});
area = $('#content [widget-area="' + location + '"]');
if (html && area.length) {
8 years ago
area.html(html);
}
8 years ago
if (widgetsAtLocation.length) {
area.removeClass('hidden');
ajaxify.widgets.reposition(location);
8 years ago
}
});
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'),
});
8 years ago
});
$(window).trigger('action:widgets.loaded', {});
callback();
};
}(ajaxify || {}));