grafana/public/app/core/components/info_popover.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

2016-03-01 14:01:41 -06:00
///<reference path="../../headers/common.d.ts" />
2016-02-21 11:08:44 -06:00
import _ from 'lodash';
2016-03-01 14:01:41 -06:00
import coreModule from 'app/core/core_module';
2016-02-21 11:08:44 -06:00
import Drop from 'tether-drop';
2016-03-01 14:01:41 -06:00
export function infoPopover() {
2016-02-21 11:08:44 -06:00
return {
restrict: 'E',
2016-04-15 18:56:39 -05:00
template: '<i class="fa fa-info-circle"></i>',
2016-02-22 03:17:35 -06:00
transclude: true,
link: function(scope, elem, attrs, ctrl, transclude) {
2016-02-22 04:41:50 -06:00
var offset = attrs.offset || '0 -10px';
2016-03-01 14:01:41 -06:00
var position = attrs.position || 'right middle';
var classes = 'drop-help drop-hide-out-of-bounds';
2016-04-15 18:56:39 -05:00
var openOn = 'hover';
elem.addClass('gf-form-help-icon');
2016-03-01 14:01:41 -06:00
if (attrs.wide) {
classes += ' drop-wide';
}
2016-02-22 03:17:35 -06:00
2016-04-15 18:56:39 -05:00
if (attrs.mode) {
elem.addClass('gf-form-help-icon--' + attrs.mode);
}
2016-02-22 03:17:35 -06:00
transclude(function(clone, newScope) {
var content = document.createElement("div");
_.each(clone, (node) => {
content.appendChild(node);
});
var drop = new Drop({
2016-04-15 18:56:39 -05:00
target: elem[0],
2016-02-22 03:17:35 -06:00
content: content,
2016-03-01 14:01:41 -06:00
position: position,
classes: classes,
2016-04-15 18:56:39 -05:00
openOn: openOn,
hoverOpenDelay: 400,
2016-02-22 03:17:35 -06:00
tetherOptions: {
offset: offset,
constraints: [
{
to: 'window',
attachment: 'together',
pin: true
}
],
2016-02-22 03:17:35 -06:00
}
});
var unbind = scope.$on('$destroy', function() {
2016-02-22 03:17:35 -06:00
drop.destroy();
unbind();
2016-02-22 03:17:35 -06:00
});
2016-02-21 11:08:44 -06:00
});
}
};
}
2016-03-01 14:01:41 -06:00
coreModule.directive('infoPopover', infoPopover);