info_popover.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import coreModule from 'app/core/core_module';
  4. import Drop from 'tether-drop';
  5. export function infoPopover() {
  6. return {
  7. restrict: 'E',
  8. template: '<i class="fa fa-info-circle"></i>',
  9. transclude: true,
  10. link: function(scope, elem, attrs, ctrl, transclude) {
  11. let offset = attrs.offset || '0 -10px';
  12. let position = attrs.position || 'right middle';
  13. let classes = 'drop-help drop-hide-out-of-bounds';
  14. let 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(function(clone, newScope) {
  23. let content = document.createElement('div');
  24. content.className = 'markdown-html';
  25. _.each(clone, node => {
  26. content.appendChild(node);
  27. });
  28. let 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. let drop = new Drop(dropOptions);
  49. let unbind = scope.$on('$destroy', function() {
  50. drop.destroy();
  51. unbind();
  52. });
  53. });
  54. });
  55. },
  56. };
  57. }
  58. coreModule.directive('infoPopover', infoPopover);