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
1 changed files with 10 additions and 35 deletions

View File

@ -2,7 +2,7 @@
(function(Icinga, $) {
"use strict";
'use strict';
Icinga.Behaviors = Icinga.Behaviors || {};
@ -10,42 +10,17 @@
Icinga.EventListener.call(this, icinga);
this.on('rendered', this.onRendered, this);
};
Sparkline.prototype = new Icinga.EventListener();
Sparkline.prototype.onRendered = function(evt) {
var el = evt.target;
Sparkline.prototype.onRendered = function(e) {
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 = {
$(e.target).find('.sparkline').each(function() {
$(this).sparkline('html', {
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);
}
disableTooltips: true
});
});
};