info_popover.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. var offset = attrs.offset || '0 -10px';
  12. var position = attrs.position || 'right middle';
  13. var classes = 'drop-help drop-hide-out-of-bounds';
  14. var 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. var content = document.createElement("div");
  24. _.each(clone, (node) => {
  25. content.appendChild(node);
  26. });
  27. var drop = new Drop({
  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. var unbind = scope.$on('$destroy', function() {
  46. drop.destroy();
  47. unbind();
  48. });
  49. });
  50. }
  51. };
  52. }
  53. coreModule.directive('infoPopover', infoPopover);