2015-02-04 10:46:36 +01:00
|
|
|
/*! Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-09 18:45:16 +02:00
|
|
|
|
|
|
|
(function(Icinga, $) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Icinga.Behaviors = Icinga.Behaviors || {};
|
|
|
|
|
2014-09-10 10:45:34 +02:00
|
|
|
var Tooltip = function (icinga) {
|
2014-09-12 09:09:21 +02:00
|
|
|
Icinga.EventListener.call(this, icinga);
|
2014-09-09 18:45:16 +02:00
|
|
|
this.mouseX = 0;
|
|
|
|
this.mouseY = 0;
|
2014-09-12 09:09:21 +02:00
|
|
|
this.on('mousemove', this.onMousemove, this);
|
|
|
|
this.on('rendered', this.onRendered, this);
|
2014-09-09 18:45:16 +02:00
|
|
|
};
|
2014-09-12 09:09:21 +02:00
|
|
|
Tooltip.prototype = new Icinga.EventListener();
|
2014-09-09 18:45:16 +02:00
|
|
|
|
2014-09-12 09:09:21 +02:00
|
|
|
Tooltip.prototype.onMousemove = function(event) {
|
|
|
|
event.data.self.mouseX = event.pageX;
|
|
|
|
event.data.self.mouseY = event.pageY;
|
|
|
|
};
|
|
|
|
|
|
|
|
Tooltip.prototype.onRendered = function(evt) {
|
|
|
|
var self = evt.data.self, icinga = evt.data.icinga, el = evt.target;
|
2014-09-09 18:45:16 +02:00
|
|
|
|
2014-09-12 09:09:21 +02:00
|
|
|
$('[title]', el).each(function () {
|
2014-09-09 18:45:16 +02:00
|
|
|
var $el = $(this);
|
|
|
|
$el.attr('title', $el.data('title-rich') || $el.attr('title'));
|
|
|
|
});
|
|
|
|
$('svg rect.chart-data[title]', el).tipsy({ gravity: 'se', html: true });
|
|
|
|
$('.historycolorgrid a[title]', el).tipsy({ gravity: 's', offset: 2 });
|
|
|
|
$('img.icon[title]', el).tipsy({ gravity: $.fn.tipsy.autoNS, offset: 2 });
|
|
|
|
$('[title]', el).tipsy({ gravity: $.fn.tipsy.autoNS, delayIn: 500 });
|
|
|
|
|
|
|
|
// migrate or remove all orphaned tooltips
|
|
|
|
$('.tipsy').each(function () {
|
|
|
|
var arrow = $('.tipsy-arrow', this)[0];
|
2014-09-10 10:45:34 +02:00
|
|
|
if (!icinga.utils.elementsOverlap(arrow, $('#main')[0])) {
|
2014-09-09 18:45:16 +02:00
|
|
|
$(this).remove();
|
|
|
|
return;
|
|
|
|
}
|
2014-09-10 10:45:34 +02:00
|
|
|
if (!icinga.utils.elementsOverlap(arrow, el)) {
|
2014-09-09 18:45:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var title = $(this).find('.tipsy-inner').html();
|
|
|
|
var atMouse = document.elementFromPoint(self.mouseX, self.mouseY);
|
|
|
|
var nearestTip = $(atMouse).closest('[original-title="' + title + '"]')[0];
|
|
|
|
if (nearestTip) {
|
|
|
|
var tipsy = $.data(nearestTip, 'tipsy');
|
|
|
|
tipsy.$tip = $(this);
|
|
|
|
$.data(this, 'tipsy-pointee', nearestTip);
|
|
|
|
} else {
|
|
|
|
// doesn't match delete
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Export
|
|
|
|
Icinga.Behaviors.Tooltip = Tooltip;
|
|
|
|
|
|
|
|
}) (Icinga, jQuery);
|