ngx-bootstrap-popover.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import { Injectable, Component, ChangeDetectionStrategy, Input, Directive, ElementRef, Renderer2, ViewContainerRef, Output, NgModule } from '@angular/core';
  2. import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';
  3. import { isBs3 } from 'ngx-bootstrap/utils';
  4. import { PositioningService } from 'ngx-bootstrap/positioning';
  5. import { CommonModule } from '@angular/common';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. /**
  11. * Configuration service for the Popover directive.
  12. * You can inject this service, typically in your root component, and customize
  13. * the values of its properties in order to provide default values for all the
  14. * popovers used in the application.
  15. */
  16. var PopoverConfig = /** @class */ (function () {
  17. function PopoverConfig() {
  18. /**
  19. * sets disable adaptive position
  20. */
  21. this.adaptivePosition = true;
  22. /**
  23. * Placement of a popover. Accepts: "top", "bottom", "left", "right", "auto"
  24. */
  25. this.placement = 'top';
  26. /**
  27. * Specifies events that should trigger. Supports a space separated list of
  28. * event names.
  29. */
  30. this.triggers = 'click';
  31. this.outsideClick = false;
  32. }
  33. PopoverConfig.decorators = [
  34. { type: Injectable }
  35. ];
  36. return PopoverConfig;
  37. }());
  38. /**
  39. * @fileoverview added by tsickle
  40. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  41. */
  42. var PopoverContainerComponent = /** @class */ (function () {
  43. function PopoverContainerComponent(config) {
  44. Object.assign(this, config);
  45. }
  46. Object.defineProperty(PopoverContainerComponent.prototype, "isBs3", {
  47. get: /**
  48. * @return {?}
  49. */
  50. function () {
  51. return isBs3();
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. PopoverContainerComponent.decorators = [
  57. { type: Component, args: [{
  58. selector: 'popover-container',
  59. changeDetection: ChangeDetectionStrategy.OnPush,
  60. // tslint:disable-next-line
  61. host: {
  62. '[class]': '"popover in popover-" + placement + " " + "bs-popover-" + placement + " " + placement + " " + containerClass',
  63. '[class.show]': '!isBs3',
  64. '[class.bs3]': 'isBs3',
  65. role: 'tooltip',
  66. style: 'display:block;'
  67. },
  68. template: "<div class=\"popover-arrow arrow\"></div>\n<h3 class=\"popover-title popover-header\" *ngIf=\"title\">{{ title }}</h3>\n<div class=\"popover-content popover-body\">\n <ng-content></ng-content>\n</div>\n",
  69. styles: ["\n :host.bs3.popover-top {\n margin-bottom: 10px;\n }\n :host.bs3.popover.top>.arrow {\n margin-left: -2px;\n }\n :host.bs3.popover.top {\n margin-bottom: 10px;\n }\n :host.popover.bottom>.arrow {\n margin-left: -4px;\n }\n :host.bs3.bs-popover-left {\n margin-right: .5rem;\n }\n :host.bs3.bs-popover-right .arrow, :host.bs3.bs-popover-left .arrow{\n margin: .3rem 0;\n }\n "]
  70. }] }
  71. ];
  72. /** @nocollapse */
  73. PopoverContainerComponent.ctorParameters = function () { return [
  74. { type: PopoverConfig }
  75. ]; };
  76. PopoverContainerComponent.propDecorators = {
  77. placement: [{ type: Input }],
  78. title: [{ type: Input }]
  79. };
  80. return PopoverContainerComponent;
  81. }());
  82. /**
  83. * @fileoverview added by tsickle
  84. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  85. */
  86. /**
  87. * A lightweight, extensible directive for fancy popover creation.
  88. */
  89. var PopoverDirective = /** @class */ (function () {
  90. function PopoverDirective(_config, _elementRef, _renderer, _viewContainerRef, cis, _positionService) {
  91. this._positionService = _positionService;
  92. /**
  93. * Close popover on outside click
  94. */
  95. this.outsideClick = false;
  96. /**
  97. * Css class for popover container
  98. */
  99. this.containerClass = '';
  100. this._isInited = false;
  101. this._popover = cis
  102. .createLoader(_elementRef, _viewContainerRef, _renderer)
  103. .provide({ provide: PopoverConfig, useValue: _config });
  104. Object.assign(this, _config);
  105. this.onShown = this._popover.onShown;
  106. this.onHidden = this._popover.onHidden;
  107. // fix: no focus on button on Mac OS #1795
  108. if (typeof window !== 'undefined') {
  109. _elementRef.nativeElement.addEventListener('click', (/**
  110. * @return {?}
  111. */
  112. function () {
  113. try {
  114. _elementRef.nativeElement.focus();
  115. }
  116. catch (err) {
  117. return;
  118. }
  119. }));
  120. }
  121. }
  122. Object.defineProperty(PopoverDirective.prototype, "isOpen", {
  123. /**
  124. * Returns whether or not the popover is currently being shown
  125. */
  126. get: /**
  127. * Returns whether or not the popover is currently being shown
  128. * @return {?}
  129. */
  130. function () {
  131. return this._popover.isShown;
  132. },
  133. set: /**
  134. * @param {?} value
  135. * @return {?}
  136. */
  137. function (value) {
  138. if (value) {
  139. this.show();
  140. }
  141. else {
  142. this.hide();
  143. }
  144. },
  145. enumerable: true,
  146. configurable: true
  147. });
  148. /**
  149. * Opens an element’s popover. This is considered a “manual” triggering of
  150. * the popover.
  151. */
  152. /**
  153. * Opens an element’s popover. This is considered a “manual” triggering of
  154. * the popover.
  155. * @return {?}
  156. */
  157. PopoverDirective.prototype.show = /**
  158. * Opens an element’s popover. This is considered a “manual” triggering of
  159. * the popover.
  160. * @return {?}
  161. */
  162. function () {
  163. if (this._popover.isShown || !this.popover) {
  164. return;
  165. }
  166. this._positionService.setOptions({
  167. modifiers: {
  168. flip: {
  169. enabled: this.adaptivePosition
  170. },
  171. preventOverflow: {
  172. enabled: this.adaptivePosition
  173. }
  174. }
  175. });
  176. this._popover
  177. .attach(PopoverContainerComponent)
  178. .to(this.container)
  179. .position({ attachment: this.placement })
  180. .show({
  181. content: this.popover,
  182. context: this.popoverContext,
  183. placement: this.placement,
  184. title: this.popoverTitle,
  185. containerClass: this.containerClass
  186. });
  187. if (!this.adaptivePosition) {
  188. this._positionService.calcPosition();
  189. this._positionService.deletePositionElement(this._popover._componentRef.location);
  190. }
  191. this.isOpen = true;
  192. };
  193. /**
  194. * Closes an element’s popover. This is considered a “manual” triggering of
  195. * the popover.
  196. */
  197. /**
  198. * Closes an element’s popover. This is considered a “manual” triggering of
  199. * the popover.
  200. * @return {?}
  201. */
  202. PopoverDirective.prototype.hide = /**
  203. * Closes an element’s popover. This is considered a “manual” triggering of
  204. * the popover.
  205. * @return {?}
  206. */
  207. function () {
  208. if (this.isOpen) {
  209. this._popover.hide();
  210. this.isOpen = false;
  211. }
  212. };
  213. /**
  214. * Toggles an element’s popover. This is considered a “manual” triggering of
  215. * the popover.
  216. */
  217. /**
  218. * Toggles an element’s popover. This is considered a “manual” triggering of
  219. * the popover.
  220. * @return {?}
  221. */
  222. PopoverDirective.prototype.toggle = /**
  223. * Toggles an element’s popover. This is considered a “manual” triggering of
  224. * the popover.
  225. * @return {?}
  226. */
  227. function () {
  228. if (this.isOpen) {
  229. return this.hide();
  230. }
  231. this.show();
  232. };
  233. /**
  234. * @return {?}
  235. */
  236. PopoverDirective.prototype.ngOnInit = /**
  237. * @return {?}
  238. */
  239. function () {
  240. var _this = this;
  241. // fix: seems there are an issue with `routerLinkActive`
  242. // which result in duplicated call ngOnInit without call to ngOnDestroy
  243. // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885
  244. if (this._isInited) {
  245. return;
  246. }
  247. this._isInited = true;
  248. this._popover.listen({
  249. triggers: this.triggers,
  250. outsideClick: this.outsideClick,
  251. show: (/**
  252. * @return {?}
  253. */
  254. function () { return _this.show(); })
  255. });
  256. };
  257. /**
  258. * @return {?}
  259. */
  260. PopoverDirective.prototype.ngOnDestroy = /**
  261. * @return {?}
  262. */
  263. function () {
  264. this._popover.dispose();
  265. };
  266. PopoverDirective.decorators = [
  267. { type: Directive, args: [{ selector: '[popover]', exportAs: 'bs-popover' },] }
  268. ];
  269. /** @nocollapse */
  270. PopoverDirective.ctorParameters = function () { return [
  271. { type: PopoverConfig },
  272. { type: ElementRef },
  273. { type: Renderer2 },
  274. { type: ViewContainerRef },
  275. { type: ComponentLoaderFactory },
  276. { type: PositioningService }
  277. ]; };
  278. PopoverDirective.propDecorators = {
  279. adaptivePosition: [{ type: Input }],
  280. popover: [{ type: Input }],
  281. popoverContext: [{ type: Input }],
  282. popoverTitle: [{ type: Input }],
  283. placement: [{ type: Input }],
  284. outsideClick: [{ type: Input }],
  285. triggers: [{ type: Input }],
  286. container: [{ type: Input }],
  287. containerClass: [{ type: Input }],
  288. isOpen: [{ type: Input }],
  289. onShown: [{ type: Output }],
  290. onHidden: [{ type: Output }]
  291. };
  292. return PopoverDirective;
  293. }());
  294. /**
  295. * @fileoverview added by tsickle
  296. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  297. */
  298. var PopoverModule = /** @class */ (function () {
  299. function PopoverModule() {
  300. }
  301. /**
  302. * @return {?}
  303. */
  304. PopoverModule.forRoot = /**
  305. * @return {?}
  306. */
  307. function () {
  308. return {
  309. ngModule: PopoverModule,
  310. providers: [PopoverConfig, ComponentLoaderFactory, PositioningService]
  311. };
  312. };
  313. PopoverModule.decorators = [
  314. { type: NgModule, args: [{
  315. imports: [CommonModule],
  316. declarations: [PopoverDirective, PopoverContainerComponent],
  317. exports: [PopoverDirective],
  318. entryComponents: [PopoverContainerComponent]
  319. },] }
  320. ];
  321. return PopoverModule;
  322. }());
  323. export { PopoverConfig, PopoverContainerComponent, PopoverDirective, PopoverModule };
  324. //# sourceMappingURL=ngx-bootstrap-popover.js.map