ngx-tooltip.system.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. System.register("ngx-tooltip/TooltipContent", ["@angular/core"], function (exports_1, context_1) {
  11. "use strict";
  12. var __moduleName = context_1 && context_1.id;
  13. var core_1, TooltipContent;
  14. return {
  15. setters: [
  16. function (core_1_1) {
  17. core_1 = core_1_1;
  18. }
  19. ],
  20. execute: function () {
  21. TooltipContent = (function () {
  22. // -------------------------------------------------------------------------
  23. // Constructor
  24. // -------------------------------------------------------------------------
  25. function TooltipContent(element, cdr) {
  26. this.element = element;
  27. this.cdr = cdr;
  28. this.placement = "bottom";
  29. this.animation = true;
  30. // -------------------------------------------------------------------------
  31. // Properties
  32. // -------------------------------------------------------------------------
  33. this.top = -100000;
  34. this.left = -100000;
  35. this.isIn = false;
  36. this.isFade = false;
  37. }
  38. // -------------------------------------------------------------------------
  39. // Lifecycle callbacks
  40. // -------------------------------------------------------------------------
  41. TooltipContent.prototype.ngAfterViewInit = function () {
  42. this.show();
  43. this.cdr.detectChanges();
  44. };
  45. // -------------------------------------------------------------------------
  46. // Public Methods
  47. // -------------------------------------------------------------------------
  48. TooltipContent.prototype.show = function () {
  49. if (!this.hostElement)
  50. return;
  51. var p = this.positionElements(this.hostElement, this.element.nativeElement.children[0], this.placement);
  52. this.top = p.top;
  53. this.left = p.left;
  54. this.isIn = true;
  55. if (this.animation)
  56. this.isFade = true;
  57. };
  58. TooltipContent.prototype.hide = function () {
  59. this.top = -100000;
  60. this.left = -100000;
  61. this.isIn = true;
  62. if (this.animation)
  63. this.isFade = false;
  64. };
  65. // -------------------------------------------------------------------------
  66. // Private Methods
  67. // -------------------------------------------------------------------------
  68. TooltipContent.prototype.positionElements = function (hostEl, targetEl, positionStr, appendToBody) {
  69. if (appendToBody === void 0) { appendToBody = false; }
  70. var positionStrParts = positionStr.split("-");
  71. var pos0 = positionStrParts[0];
  72. var pos1 = positionStrParts[1] || "center";
  73. var hostElPos = appendToBody ? this.offset(hostEl) : this.position(hostEl);
  74. var targetElWidth = targetEl.offsetWidth;
  75. var targetElHeight = targetEl.offsetHeight;
  76. var shiftWidth = {
  77. center: function () {
  78. return hostElPos.left + hostElPos.width / 2 - targetElWidth / 2;
  79. },
  80. left: function () {
  81. return hostElPos.left;
  82. },
  83. right: function () {
  84. return hostElPos.left + hostElPos.width;
  85. }
  86. };
  87. var shiftHeight = {
  88. center: function () {
  89. return hostElPos.top + hostElPos.height / 2 - targetElHeight / 2;
  90. },
  91. top: function () {
  92. return hostElPos.top;
  93. },
  94. bottom: function () {
  95. return hostElPos.top + hostElPos.height;
  96. }
  97. };
  98. var targetElPos;
  99. switch (pos0) {
  100. case "right":
  101. targetElPos = {
  102. top: shiftHeight[pos1](),
  103. left: shiftWidth[pos0]()
  104. };
  105. break;
  106. case "left":
  107. targetElPos = {
  108. top: shiftHeight[pos1](),
  109. left: hostElPos.left - targetElWidth
  110. };
  111. break;
  112. case "bottom":
  113. targetElPos = {
  114. top: shiftHeight[pos0](),
  115. left: shiftWidth[pos1]()
  116. };
  117. break;
  118. default:
  119. targetElPos = {
  120. top: hostElPos.top - targetElHeight,
  121. left: shiftWidth[pos1]()
  122. };
  123. break;
  124. }
  125. return targetElPos;
  126. };
  127. TooltipContent.prototype.position = function (nativeEl) {
  128. var offsetParentBCR = { top: 0, left: 0 };
  129. var elBCR = this.offset(nativeEl);
  130. var offsetParentEl = this.parentOffsetEl(nativeEl);
  131. if (offsetParentEl !== window.document) {
  132. offsetParentBCR = this.offset(offsetParentEl);
  133. offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop;
  134. offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft;
  135. }
  136. var boundingClientRect = nativeEl.getBoundingClientRect();
  137. return {
  138. width: boundingClientRect.width || nativeEl.offsetWidth,
  139. height: boundingClientRect.height || nativeEl.offsetHeight,
  140. top: elBCR.top - offsetParentBCR.top,
  141. left: elBCR.left - offsetParentBCR.left
  142. };
  143. };
  144. TooltipContent.prototype.offset = function (nativeEl) {
  145. var boundingClientRect = nativeEl.getBoundingClientRect();
  146. return {
  147. width: boundingClientRect.width || nativeEl.offsetWidth,
  148. height: boundingClientRect.height || nativeEl.offsetHeight,
  149. top: boundingClientRect.top + (window.pageYOffset || window.document.documentElement.scrollTop),
  150. left: boundingClientRect.left + (window.pageXOffset || window.document.documentElement.scrollLeft)
  151. };
  152. };
  153. TooltipContent.prototype.getStyle = function (nativeEl, cssProp) {
  154. if (nativeEl.currentStyle)
  155. return nativeEl.currentStyle[cssProp];
  156. if (window.getComputedStyle)
  157. return window.getComputedStyle(nativeEl)[cssProp];
  158. // finally try and get inline style
  159. return nativeEl.style[cssProp];
  160. };
  161. TooltipContent.prototype.isStaticPositioned = function (nativeEl) {
  162. return (this.getStyle(nativeEl, "position") || "static") === "static";
  163. };
  164. TooltipContent.prototype.parentOffsetEl = function (nativeEl) {
  165. var offsetParent = nativeEl.offsetParent || window.document;
  166. while (offsetParent && offsetParent !== window.document && this.isStaticPositioned(offsetParent)) {
  167. offsetParent = offsetParent.offsetParent;
  168. }
  169. return offsetParent || window.document;
  170. };
  171. return TooltipContent;
  172. }());
  173. __decorate([
  174. core_1.Input(),
  175. __metadata("design:type", HTMLElement)
  176. ], TooltipContent.prototype, "hostElement", void 0);
  177. __decorate([
  178. core_1.Input(),
  179. __metadata("design:type", String)
  180. ], TooltipContent.prototype, "content", void 0);
  181. __decorate([
  182. core_1.Input(),
  183. __metadata("design:type", String)
  184. ], TooltipContent.prototype, "placement", void 0);
  185. __decorate([
  186. core_1.Input(),
  187. __metadata("design:type", Boolean)
  188. ], TooltipContent.prototype, "animation", void 0);
  189. TooltipContent = __decorate([
  190. core_1.Component({
  191. selector: "tooltip-content",
  192. 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"
  193. }),
  194. __metadata("design:paramtypes", [core_1.ElementRef,
  195. core_1.ChangeDetectorRef])
  196. ], TooltipContent);
  197. exports_1("TooltipContent", TooltipContent);
  198. }
  199. };
  200. });
  201. System.register("ngx-tooltip/Tooltip", ["@angular/core", "ngx-tooltip/TooltipContent"], function (exports_2, context_2) {
  202. "use strict";
  203. var __moduleName = context_2 && context_2.id;
  204. var core_2, TooltipContent_1, Tooltip;
  205. return {
  206. setters: [
  207. function (core_2_1) {
  208. core_2 = core_2_1;
  209. },
  210. function (TooltipContent_1_1) {
  211. TooltipContent_1 = TooltipContent_1_1;
  212. }
  213. ],
  214. execute: function () {
  215. Tooltip = (function () {
  216. // -------------------------------------------------------------------------
  217. // Constructor
  218. // -------------------------------------------------------------------------
  219. function Tooltip(viewContainerRef, resolver) {
  220. this.viewContainerRef = viewContainerRef;
  221. this.resolver = resolver;
  222. this.tooltipAnimation = true;
  223. this.tooltipPlacement = "bottom";
  224. }
  225. // -------------------------------------------------------------------------
  226. // Public Methods
  227. // -------------------------------------------------------------------------
  228. Tooltip.prototype.show = function () {
  229. if (this.tooltipDisabled || this.visible)
  230. return;
  231. this.visible = true;
  232. if (typeof this.content === "string") {
  233. var factory = this.resolver.resolveComponentFactory(TooltipContent_1.TooltipContent);
  234. if (!this.visible)
  235. return;
  236. this.tooltip = this.viewContainerRef.createComponent(factory);
  237. this.tooltip.instance.hostElement = this.viewContainerRef.element.nativeElement;
  238. this.tooltip.instance.content = this.content;
  239. this.tooltip.instance.placement = this.tooltipPlacement;
  240. this.tooltip.instance.animation = this.tooltipAnimation;
  241. }
  242. else {
  243. var tooltip = this.content;
  244. tooltip.hostElement = this.viewContainerRef.element.nativeElement;
  245. tooltip.placement = this.tooltipPlacement;
  246. tooltip.animation = this.tooltipAnimation;
  247. tooltip.show();
  248. }
  249. };
  250. Tooltip.prototype.hide = function () {
  251. if (!this.visible)
  252. return;
  253. this.visible = false;
  254. if (this.tooltip)
  255. this.tooltip.destroy();
  256. if (this.content instanceof TooltipContent_1.TooltipContent)
  257. this.content.hide();
  258. };
  259. return Tooltip;
  260. }());
  261. __decorate([
  262. core_2.Input("tooltip"),
  263. __metadata("design:type", Object)
  264. ], Tooltip.prototype, "content", void 0);
  265. __decorate([
  266. core_2.Input(),
  267. __metadata("design:type", Boolean)
  268. ], Tooltip.prototype, "tooltipDisabled", void 0);
  269. __decorate([
  270. core_2.Input(),
  271. __metadata("design:type", Boolean)
  272. ], Tooltip.prototype, "tooltipAnimation", void 0);
  273. __decorate([
  274. core_2.Input(),
  275. __metadata("design:type", String)
  276. ], Tooltip.prototype, "tooltipPlacement", void 0);
  277. __decorate([
  278. core_2.HostListener("focusin"),
  279. core_2.HostListener("mouseenter"),
  280. __metadata("design:type", Function),
  281. __metadata("design:paramtypes", []),
  282. __metadata("design:returntype", void 0)
  283. ], Tooltip.prototype, "show", null);
  284. __decorate([
  285. core_2.HostListener("focusout"),
  286. core_2.HostListener("mouseleave"),
  287. __metadata("design:type", Function),
  288. __metadata("design:paramtypes", []),
  289. __metadata("design:returntype", void 0)
  290. ], Tooltip.prototype, "hide", null);
  291. Tooltip = __decorate([
  292. core_2.Directive({
  293. selector: "[tooltip]"
  294. }),
  295. __metadata("design:paramtypes", [core_2.ViewContainerRef,
  296. core_2.ComponentFactoryResolver])
  297. ], Tooltip);
  298. exports_2("Tooltip", Tooltip);
  299. }
  300. };
  301. });
  302. System.register("ngx-tooltip/index", ["@angular/core", "@angular/common", "ngx-tooltip/Tooltip", "ngx-tooltip/TooltipContent"], function (exports_3, context_3) {
  303. "use strict";
  304. var __moduleName = context_3 && context_3.id;
  305. var core_3, common_1, Tooltip_1, TooltipContent_2, TooltipModule;
  306. var exportedNames_1 = {
  307. "TooltipModule": true
  308. };
  309. function exportStar_1(m) {
  310. var exports = {};
  311. for (var n in m) {
  312. if (n !== "default" && !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
  313. }
  314. exports_3(exports);
  315. }
  316. return {
  317. setters: [
  318. function (core_3_1) {
  319. core_3 = core_3_1;
  320. },
  321. function (common_1_1) {
  322. common_1 = common_1_1;
  323. },
  324. function (Tooltip_1_1) {
  325. Tooltip_1 = Tooltip_1_1;
  326. exportStar_1(Tooltip_1_1);
  327. },
  328. function (TooltipContent_2_1) {
  329. TooltipContent_2 = TooltipContent_2_1;
  330. exportStar_1(TooltipContent_2_1);
  331. }
  332. ],
  333. execute: function () {
  334. TooltipModule = (function () {
  335. function TooltipModule() {
  336. }
  337. return TooltipModule;
  338. }());
  339. TooltipModule = __decorate([
  340. core_3.NgModule({
  341. imports: [
  342. common_1.CommonModule
  343. ],
  344. declarations: [
  345. Tooltip_1.Tooltip,
  346. TooltipContent_2.TooltipContent,
  347. ],
  348. exports: [
  349. Tooltip_1.Tooltip,
  350. TooltipContent_2.TooltipContent,
  351. ],
  352. entryComponents: [
  353. TooltipContent_2.TooltipContent
  354. ]
  355. })
  356. ], TooltipModule);
  357. exports_3("TooltipModule", TooltipModule);
  358. }
  359. };
  360. });
  361. System.register("ngx-tooltip", ["ngx-tooltip/index"], function (exports_4, context_4) {
  362. "use strict";
  363. var __moduleName = context_4 && context_4.id;
  364. function exportStar_2(m) {
  365. var exports = {};
  366. for (var n in m) {
  367. if (n !== "default") exports[n] = m[n];
  368. }
  369. exports_4(exports);
  370. }
  371. return {
  372. setters: [
  373. function (index_1_1) {
  374. exportStar_2(index_1_1);
  375. }
  376. ],
  377. execute: function () {
  378. }
  379. };
  380. });