info_popover.ts 1.7 KB

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