ngx-tooltip.amd.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. 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;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var __metadata = (this && this.__metadata) || function (k, v) {
  8. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  9. };
  10. define("ngx-tooltip/TooltipContent", ["require", "exports", "@angular/core"], function (require, exports, core_1) {
  11. "use strict";
  12. var TooltipContent = (function () {
  13. // -------------------------------------------------------------------------
  14. // Constructor
  15. // -------------------------------------------------------------------------
  16. function TooltipContent(element, cdr) {
  17. this.element = element;
  18. this.cdr = cdr;
  19. this.placement = "bottom";
  20. this.animation = true;
  21. // -------------------------------------------------------------------------
  22. // Properties
  23. // -------------------------------------------------------------------------
  24. this.top = -100000;
  25. this.left = -100000;
  26. this.isIn = false;
  27. this.isFade = false;
  28. }
  29. // -------------------------------------------------------------------------
  30. // Lifecycle callbacks
  31. // -------------------------------------------------------------------------
  32. TooltipContent.prototype.ngAfterViewInit = function () {
  33. this.show();
  34. this.cdr.detectChanges();
  35. };
  36. // -------------------------------------------------------------------------
  37. // Public Methods
  38. // -------------------------------------------------------------------------
  39. TooltipContent.prototype.show = function () {
  40. if (!this.hostElement)
  41. return;
  42. var p = this.positionElements(this.hostElement, this.element.nativeElement.children[0], this.placement);
  43. this.top = p.top;
  44. this.left = p.left;
  45. this.isIn = true;
  46. if (this.animation)
  47. this.isFade = true;
  48. };
  49. TooltipContent.prototype.hide = function () {
  50. this.top = -100000;
  51. this.left = -100000;
  52. this.isIn = true;
  53. if (this.animation)
  54. this.isFade = false;
  55. };
  56. // -------------------------------------------------------------------------
  57. // Private Methods
  58. // -------------------------------------------------------------------------
  59. TooltipContent.prototype.positionElements = function (hostEl, targetEl, positionStr, appendToBody) {
  60. if (appendToBody === void 0) { appendToBody = false; }
  61. var positionStrParts = positionStr.split("-");
  62. var pos0 = positionStrParts[0];
  63. var pos1 = positionStrParts[1] || "center";
  64. var hostElPos = appendToBody ? this.offset(hostEl) : this.position(hostEl);
  65. var targetElWidth = targetEl.offsetWidth;
  66. var targetElHeight = targetEl.offsetHeight;
  67. var shiftWidth = {
  68. center: function () {
  69. return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2;
  70. },
  71. left: function () {
  72. return hostElPos.left;
  73. },
  74. right: function () {
  75. return hostElPos.left + hostElPos.width;
  76. }
  77. };
  78. var shiftHeight = {
  79. center: function () {
  80. return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2;
  81. },
  82. top: function () {
  83. return hostElPos.top;
  84. },
  85. bottom: function () {
  86. return hostElPos.top + hostElPos.height;
  87. }
  88. };
  89. var targetElPos;
  90. switch (pos0) {
  91. case "right":
  92. targetElPos = {
  93. top: shiftHeight[pos1](),
  94. left: shiftWidth[pos0]()
  95. };
  96. break;
  97. case "left":
  98. targetElPos = {
  99. top: shiftHeight[pos1](),
  100. left: hostElPos.left - targetElWidth
  101. };
  102. break;
  103. case "bottom":
  104. targetElPos = {
  105. top: shiftHeight[pos0](),
  106. left: shiftWidth[pos1]()
  107. };
  108. break;
  109. default:
  110. targetElPos = {
  111. top: hostElPos.top - targetElHeight,
  112. left: shiftWidth[pos1]()
  113. };
  114. break;
  115. }
  116. return targetElPos;
  117. };
  118. TooltipContent.prototype.position = function (nativeEl) {
  119. var offsetParentBCR = { top: 0, left: 0 };
  120. var elBCR = this.offset(nativeEl);
  121. var offsetParentEl = this.parentOffsetEl(nativeEl);
  122. if (offsetParentEl !== window.document) {
  123. offsetParentBCR = this.offset(offsetParentEl);
  124. offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop;
  125. offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft;
  126. }
  127. var boundingClientRect = nativeEl.getBoundingClientRect();
  128. return {
  129. width: boundingClientRect.width || nativeEl.offsetWidth,
  130. height: boundingClientRect.height || nativeEl.offsetHeight,
  131. top: elBCR.top - offsetParentBCR.top,
  132. left: elBCR.left - offsetParentBCR.left
  133. };
  134. };
  135. TooltipContent.prototype.offset = function (nativeEl) {
  136. var boundingClientRect = nativeEl.getBoundingClientRect();
  137. return {
  138. width: boundingClientRect.width || nativeEl.offsetWidth,
  139. height: boundingClientRect.height || nativeEl.offsetHeight,
  140. top: boundingClientRect.top + (window.pageYOffset || window.document.documentElement.scrollTop),
  141. left: boundingClientRect.left + (window.pageXOffset || window.document.documentElement.scrollLeft)
  142. };
  143. };
  144. TooltipContent.prototype.getStyle = function (nativeEl, cssProp) {
  145. if (nativeEl.currentStyle)
  146. return nativeEl.currentStyle[cssProp];
  147. if (window.getComputedStyle)
  148. return window.getComputedStyle(nativeEl)[cssProp];
  149. // finally try and get inline style
  150. return nativeEl.style[cssProp];
  151. };
  152. TooltipContent.prototype.isStaticPositioned = function (nativeEl) {
  153. return (this.getStyle(nativeEl, "position") || "static") === "static";
  154. };
  155. TooltipContent.prototype.parentOffsetEl = function (nativeEl) {
  156. var offsetParent = nativeEl.offsetParent || window.document;
  157. while (offsetParent && offsetParent !== window.document && this.isStaticPositioned(offsetParent)) {
  158. offsetParent = offsetParent.offsetParent;
  159. }
  160. return offsetParent || window.document;
  161. };
  162. return TooltipContent;
  163. }());
  164. __decorate([
  165. core_1.Input(),
  166. __metadata("design:type", HTMLElement)
  167. ], TooltipContent.prototype, "hostElement", void 0);
  168. __decorate([
  169. core_1.Input(),
  170. __metadata("design:type", String)
  171. ], TooltipContent.prototype, "content", void 0);
  172. __decorate([
  173. core_1.Input(),
  174. __metadata("design:type", String)
  175. ], TooltipContent.prototype, "placement", void 0);
  176. __decorate([
  177. core_1.Input(),
  178. __metadata("design:type", Boolean)
  179. ], TooltipContent.prototype, "animation", void 0);
  180. TooltipContent = __decorate([
  181. core_1.Component({
  182. selector: "tooltip-content",
  183. template: "\n<div class=\"tooltip {{ placement }}\"\n [style.top]=\"top + 'px'\"\n [style.left]=\"left + 'px'\"\n [class.in]=\"isIn\"\n [class.fade]=\"isFade\"\n role=\"tooltip\">\n <div class=\"tooltip-arrow\"></div> \n <div class=\"tooltip-inner\">\n <ng-content></ng-content>\n {{ content }}\n </div> \n</div>\n"
  184. }),
  185. __metadata("design:paramtypes", [core_1.ElementRef,
  186. core_1.ChangeDetectorRef])
  187. ], TooltipContent);
  188. exports.TooltipContent = TooltipContent;
  189. });
  190. define("ngx-tooltip/Tooltip", ["require", "exports", "@angular/core", "ngx-tooltip/TooltipContent"], function (require, exports, core_2, TooltipContent_1) {
  191. "use strict";
  192. var Tooltip = (function () {
  193. // -------------------------------------------------------------------------
  194. // Constructor
  195. // -------------------------------------------------------------------------
  196. function Tooltip(viewContainerRef, resolver) {
  197. this.viewContainerRef = viewContainerRef;
  198. this.resolver = resolver;
  199. this.tooltipAnimation = true;
  200. this.tooltipPlacement = "bottom";
  201. }
  202. // -------------------------------------------------------------------------
  203. // Public Methods
  204. // -------------------------------------------------------------------------
  205. Tooltip.prototype.show = function () {
  206. if (this.tooltipDisabled || this.visible)
  207. return;
  208. this.visible = true;
  209. if (typeof this.content === "string") {
  210. var factory = this.resolver.resolveComponentFactory(TooltipContent_1.TooltipContent);
  211. if (!this.visible)
  212. return;
  213. this.tooltip = this.viewContainerRef.createComponent(factory);
  214. this.tooltip.instance.hostElement = this.viewContainerRef.element.nativeElement;
  215. this.tooltip.instance.content = this.content;
  216. this.tooltip.instance.placement = this.tooltipPlacement;
  217. this.tooltip.instance.animation = this.tooltipAnimation;
  218. }
  219. else {
  220. var tooltip = this.content;
  221. tooltip.hostElement = this.viewContainerRef.element.nativeElement;
  222. tooltip.placement = this.tooltipPlacement;
  223. tooltip.animation = this.tooltipAnimation;
  224. tooltip.show();
  225. }
  226. };
  227. Tooltip.prototype.hide = function () {
  228. if (!this.visible)
  229. return;
  230. this.visible = false;
  231. if (this.tooltip)
  232. this.tooltip.destroy();
  233. if (this.content instanceof TooltipContent_1.TooltipContent)
  234. this.content.hide();
  235. };
  236. return Tooltip;
  237. }());
  238. __decorate([
  239. core_2.Input("tooltip"),
  240. __metadata("design:type", Object)
  241. ], Tooltip.prototype, "content", void 0);
  242. __decorate([
  243. core_2.Input(),
  244. __metadata("design:type", Boolean)
  245. ], Tooltip.prototype, "tooltipDisabled", void 0);
  246. __decorate([
  247. core_2.Input(),
  248. __metadata("design:type", Boolean)
  249. ], Tooltip.prototype, "tooltipAnimation", void 0);
  250. __decorate([
  251. core_2.Input(),
  252. __metadata("design:type", String)
  253. ], Tooltip.prototype, "tooltipPlacement", void 0);
  254. __decorate([
  255. core_2.HostListener("focusin"),
  256. core_2.HostListener("mouseenter"),
  257. __metadata("design:type", Function),
  258. __metadata("design:paramtypes", []),
  259. __metadata("design:returntype", void 0)
  260. ], Tooltip.prototype, "show", null);
  261. __decorate([
  262. core_2.HostListener("focusout"),
  263. core_2.HostListener("mouseleave"),
  264. __metadata("design:type", Function),
  265. __metadata("design:paramtypes", []),
  266. __metadata("design:returntype", void 0)
  267. ], Tooltip.prototype, "hide", null);
  268. Tooltip = __decorate([
  269. core_2.Directive({
  270. selector: "[tooltip]"
  271. }),
  272. __metadata("design:paramtypes", [core_2.ViewContainerRef,
  273. core_2.ComponentFactoryResolver])
  274. ], Tooltip);
  275. exports.Tooltip = Tooltip;
  276. });
  277. define("ngx-tooltip/index", ["require", "exports", "@angular/core", "@angular/common", "ngx-tooltip/Tooltip", "ngx-tooltip/TooltipContent", "ngx-tooltip/Tooltip", "ngx-tooltip/TooltipContent"], function (require, exports, core_3, common_1, Tooltip_1, TooltipContent_2, Tooltip_2, TooltipContent_3) {
  278. "use strict";
  279. function __export(m) {
  280. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  281. }
  282. __export(Tooltip_2);
  283. __export(TooltipContent_3);
  284. var TooltipModule = (function () {
  285. function TooltipModule() {
  286. }
  287. return TooltipModule;
  288. }());
  289. TooltipModule = __decorate([
  290. core_3.NgModule({
  291. imports: [
  292. common_1.CommonModule
  293. ],
  294. declarations: [
  295. Tooltip_1.Tooltip,
  296. TooltipContent_2.TooltipContent,
  297. ],
  298. exports: [
  299. Tooltip_1.Tooltip,
  300. TooltipContent_2.TooltipContent,
  301. ],
  302. entryComponents: [
  303. TooltipContent_2.TooltipContent
  304. ]
  305. })
  306. ], TooltipModule);
  307. exports.TooltipModule = TooltipModule;
  308. });
  309. define("ngx-tooltip", ["require", "exports", "ngx-tooltip/index"], function (require, exports, index_1) {
  310. "use strict";
  311. function __export(m) {
  312. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  313. }
  314. __export(index_1);
  315. });