Tooltip.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. var core_1 = require("@angular/core");
  12. var TooltipContent_1 = require("./TooltipContent");
  13. var Tooltip = (function () {
  14. // -------------------------------------------------------------------------
  15. // Constructor
  16. // -------------------------------------------------------------------------
  17. function Tooltip(viewContainerRef, resolver) {
  18. this.viewContainerRef = viewContainerRef;
  19. this.resolver = resolver;
  20. this.tooltipAnimation = true;
  21. this.tooltipPlacement = "bottom";
  22. }
  23. // -------------------------------------------------------------------------
  24. // Public Methods
  25. // -------------------------------------------------------------------------
  26. Tooltip.prototype.show = function () {
  27. if (this.tooltipDisabled || this.visible)
  28. return;
  29. this.visible = true;
  30. if (typeof this.content === "string") {
  31. var factory = this.resolver.resolveComponentFactory(TooltipContent_1.TooltipContent);
  32. if (!this.visible)
  33. return;
  34. this.tooltip = this.viewContainerRef.createComponent(factory);
  35. this.tooltip.instance.hostElement = this.viewContainerRef.element.nativeElement;
  36. this.tooltip.instance.content = this.content;
  37. this.tooltip.instance.placement = this.tooltipPlacement;
  38. this.tooltip.instance.animation = this.tooltipAnimation;
  39. }
  40. else {
  41. var tooltip = this.content;
  42. tooltip.hostElement = this.viewContainerRef.element.nativeElement;
  43. tooltip.placement = this.tooltipPlacement;
  44. tooltip.animation = this.tooltipAnimation;
  45. tooltip.show();
  46. }
  47. };
  48. Tooltip.prototype.hide = function () {
  49. if (!this.visible)
  50. return;
  51. this.visible = false;
  52. if (this.tooltip)
  53. this.tooltip.destroy();
  54. if (this.content instanceof TooltipContent_1.TooltipContent)
  55. this.content.hide();
  56. };
  57. return Tooltip;
  58. }());
  59. __decorate([
  60. core_1.Input("tooltip"),
  61. __metadata("design:type", Object)
  62. ], Tooltip.prototype, "content", void 0);
  63. __decorate([
  64. core_1.Input(),
  65. __metadata("design:type", Boolean)
  66. ], Tooltip.prototype, "tooltipDisabled", void 0);
  67. __decorate([
  68. core_1.Input(),
  69. __metadata("design:type", Boolean)
  70. ], Tooltip.prototype, "tooltipAnimation", void 0);
  71. __decorate([
  72. core_1.Input(),
  73. __metadata("design:type", String)
  74. ], Tooltip.prototype, "tooltipPlacement", void 0);
  75. __decorate([
  76. core_1.HostListener("focusin"),
  77. core_1.HostListener("mouseenter"),
  78. __metadata("design:type", Function),
  79. __metadata("design:paramtypes", []),
  80. __metadata("design:returntype", void 0)
  81. ], Tooltip.prototype, "show", null);
  82. __decorate([
  83. core_1.HostListener("focusout"),
  84. core_1.HostListener("mouseleave"),
  85. __metadata("design:type", Function),
  86. __metadata("design:paramtypes", []),
  87. __metadata("design:returntype", void 0)
  88. ], Tooltip.prototype, "hide", null);
  89. Tooltip = __decorate([
  90. core_1.Directive({
  91. selector: "[tooltip]"
  92. }),
  93. __metadata("design:paramtypes", [core_1.ViewContainerRef,
  94. core_1.ComponentFactoryResolver])
  95. ], Tooltip);
  96. exports.Tooltip = Tooltip;
  97. //# sourceMappingURL=Tooltip.js.map