JS: Reduce code for the sparkline behavior

refs #5543
This commit is contained in:
Eric Lippmann 2015-11-11 15:23:45 +01:00
parent 6a5efd560d
commit fefdfe3d7b

View File

@ -2,7 +2,7 @@
(function(Icinga, $) { (function(Icinga, $) {
"use strict"; 'use strict';
Icinga.Behaviors = Icinga.Behaviors || {}; Icinga.Behaviors = Icinga.Behaviors || {};
@ -10,45 +10,20 @@
Icinga.EventListener.call(this, icinga); Icinga.EventListener.call(this, icinga);
this.on('rendered', this.onRendered, this); this.on('rendered', this.onRendered, this);
}; };
Sparkline.prototype = new Icinga.EventListener(); Sparkline.prototype = new Icinga.EventListener();
Sparkline.prototype.onRendered = function(evt) { Sparkline.prototype.onRendered = function(e) {
var el = evt.target; var el = e.target;
$('.sparkline', el).each(function(i, element) {
// read custom options
var $spark = $(element);
var title = $spark.attr('title');
if ($spark.attr('labels')) {
$spark.removeAttr('original-title');
}
var options;
if ($spark.hasClass('sparkline-perfdata')) {
options = {
enableTagOptions: true,
width: 16,
height: 16,
title: title,
disableTooltips: true,
borderWidth: 1.4,
borderColor: '#FFF'
};
$spark.sparkline('html', options);
} else if ($spark.hasClass('sparkline-multi')) {
options = {
width: 100,
height: 100,
title: title,
enableTagOptions: true
};
$spark.sparkline('html', options);
}
$(e.target).find('.sparkline').each(function() {
$(this).sparkline('html', {
enableTagOptions: true,
disableTooltips: true
});
}); });
}; };
Icinga.Behaviors.Sparkline = Sparkline; Icinga.Behaviors.Sparkline = Sparkline;
}) (Icinga, jQuery); })(Icinga, jQuery);