info_popover.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { each } from 'lodash';
  2. // @ts-ignore
  3. import Drop from 'tether-drop';
  4. import coreModule from 'app/angular/core_module';
  5. export function infoPopover() {
  6. return {
  7. restrict: 'E',
  8. template: `<icon name="'info-circle'" style="margin-left: 10px;" size="'xs'"></icon>`,
  9. transclude: true,
  10. link: (scope: any, elem: any, attrs: any, ctrl: any, transclude: any) => {
  11. const offset = attrs.offset || '0 -10px';
  12. const position = attrs.position || 'right middle';
  13. let classes = 'drop-help drop-hide-out-of-bounds';
  14. const openOn = 'hover';
  15. elem.addClass('gf-form-help-icon');
  16. if (attrs.wide) {
  17. classes += ' drop-wide';
  18. }
  19. if (attrs.mode) {
  20. elem.addClass('gf-form-help-icon--' + attrs.mode);
  21. }
  22. transclude((clone: any, newScope: any) => {
  23. const content = document.createElement('div');
  24. content.className = 'markdown-html';
  25. each(clone, (node) => {
  26. content.appendChild(node);
  27. });
  28. const dropOptions = {
  29. target: elem[0],
  30. content: content,
  31. position: position,
  32. classes: classes,
  33. openOn: openOn,
  34. hoverOpenDelay: 400,
  35. tetherOptions: {
  36. offset: offset,
  37. constraints: [
  38. {
  39. to: 'window',
  40. attachment: 'together',
  41. pin: true,
  42. },
  43. ],
  44. },
  45. };
  46. // Create drop in next digest after directive content is rendered.
  47. scope.$applyAsync(() => {
  48. const drop = new Drop(dropOptions);
  49. const unbind = scope.$on('$destroy', () => {
  50. drop.destroy();
  51. unbind();
  52. });
  53. });
  54. });
  55. },
  56. };
  57. }
  58. coreModule.directive('infoPopover', infoPopover);