info_popover.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. content.className = "markdown-html";
  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);