info_popover.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import $ from 'jquery';
  4. import coreModule from 'app/core/core_module';
  5. import Drop from 'tether-drop';
  6. export function infoPopover() {
  7. return {
  8. restrict: 'E',
  9. template: '<i class="fa fa-info-circle"></i>',
  10. transclude: true,
  11. link: function(scope, elem, attrs, ctrl, transclude) {
  12. var offset = attrs.offset || '0 -10px';
  13. var position = attrs.position || 'right middle';
  14. var classes = 'drop-help drop-hide-out-of-bounds';
  15. var openOn = 'hover';
  16. elem.addClass('gf-form-help-icon');
  17. if (attrs.wide) {
  18. classes += ' drop-wide';
  19. }
  20. if (attrs.mode) {
  21. elem.addClass('gf-form-help-icon--' + attrs.mode);
  22. }
  23. transclude(function(clone, newScope) {
  24. var content = document.createElement("div");
  25. _.each(clone, (node) => {
  26. content.appendChild(node);
  27. });
  28. var drop = new Drop({
  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. var unbind = scope.$on('$destroy', function() {
  47. drop.destroy();
  48. unbind();
  49. });
  50. });
  51. }
  52. };
  53. }
  54. coreModule.directive('infoPopover', infoPopover);