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

68 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-12-20 12:33:33 +01:00
import _ from 'lodash';
import coreModule from 'app/core/core_module';
import Drop from 'tether-drop';
2016-02-21 18:08:44 +01:00
2016-03-01 21:01:41 +01:00
export function infoPopover() {
2016-02-21 18:08:44 +01:00
return {
2017-12-20 12:33:33 +01:00
restrict: 'E',
2016-04-15 19:56:39 -04:00
template: '<i class="fa fa-info-circle"></i>',
2016-02-22 10:17:35 +01:00
transclude: true,
link: function(scope, elem, attrs, ctrl, transclude) {
2018-08-26 17:14:40 +02:00
const offset = attrs.offset || '0 -10px';
const position = attrs.position || 'right middle';
2017-12-31 14:26:02 +03:00
let classes = 'drop-help drop-hide-out-of-bounds';
2018-08-26 17:14:40 +02:00
const openOn = 'hover';
2016-04-15 19:56:39 -04:00
2017-12-20 12:33:33 +01:00
elem.addClass('gf-form-help-icon');
2016-04-15 19:56:39 -04:00
2016-03-01 21:01:41 +01:00
if (attrs.wide) {
2017-12-20 12:33:33 +01:00
classes += ' drop-wide';
2016-03-01 21:01:41 +01:00
}
2016-02-22 10:17:35 +01:00
2016-04-15 19:56:39 -04:00
if (attrs.mode) {
2017-12-20 12:33:33 +01:00
elem.addClass('gf-form-help-icon--' + attrs.mode);
2016-04-15 19:56:39 -04:00
}
2016-02-22 10:17:35 +01:00
transclude(function(clone, newScope) {
2018-08-26 17:14:40 +02:00
const content = document.createElement('div');
2017-12-20 12:33:33 +01:00
content.className = 'markdown-html';
2017-10-07 10:31:39 +02:00
2017-12-19 16:06:54 +01:00
_.each(clone, node => {
2016-02-22 10:17:35 +01:00
content.appendChild(node);
});
2018-08-26 17:14:40 +02:00
const dropOptions = {
2016-04-15 19:56:39 -04:00
target: elem[0],
2016-02-22 10:17:35 +01:00
content: content,
2016-03-01 21:01:41 +01:00
position: position,
classes: classes,
2016-04-15 19:56:39 -04:00
openOn: openOn,
hoverOpenDelay: 400,
2016-02-22 10:17:35 +01:00
tetherOptions: {
offset: offset,
constraints: [
2017-12-19 16:06:54 +01:00
{
2017-12-20 12:33:33 +01:00
to: 'window',
attachment: 'together',
pin: true,
},
],
},
2017-12-31 14:26:02 +03:00
};
// Create drop in next digest after directive content is rendered.
scope.$applyAsync(() => {
2018-08-26 17:14:40 +02:00
const drop = new Drop(dropOptions);
2016-02-22 10:17:35 +01:00
2018-08-26 17:14:40 +02:00
const unbind = scope.$on('$destroy', function() {
2017-12-31 14:26:02 +03:00
drop.destroy();
unbind();
});
2016-02-22 10:17:35 +01:00
});
2016-02-21 18:08:44 +01:00
});
2017-12-20 12:33:33 +01:00
},
2016-02-21 18:08:44 +01:00
};
}
2017-12-20 12:33:33 +01:00
coreModule.directive('infoPopover', infoPopover);