UNPKG

ngx-bootstrap

Version:
135 lines 4.6 kB
import { Directive, Input, Output, Renderer, ElementRef, ViewContainerRef } from '@angular/core'; import { PopoverConfig } from './popover.config'; import { ComponentLoaderFactory } from '../component-loader'; import { PopoverContainerComponent } from './popover-container.component'; /** * A lightweight, extensible directive for fancy popover creation. */ var PopoverDirective = (function () { function PopoverDirective(_elementRef, _renderer, _viewContainerRef, _config, cis) { /** * Close popover on outside click */ this.outsideClick = false; /** * Css class for popover container */ this.containerClass = ''; this._isInited = false; this._popover = cis .createLoader(_elementRef, _viewContainerRef, _renderer) .provide({ provide: PopoverConfig, useValue: _config }); Object.assign(this, _config); this.onShown = this._popover.onShown; this.onHidden = this._popover.onHidden; // fix: no focus on button on Mac OS #1795 _elementRef.nativeElement.addEventListener('click', function () { try { _elementRef.nativeElement.focus(); } catch (err) { return; } }); } Object.defineProperty(PopoverDirective.prototype, "isOpen", { /** * Returns whether or not the popover is currently being shown */ get: function () { return this._popover.isShown; }, set: function (value) { if (value) { this.show(); } else { this.hide(); } }, enumerable: true, configurable: true }); /** * Opens an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.show = function () { if (this._popover.isShown) { return; } this._popover .attach(PopoverContainerComponent) .to(this.container) .position({ attachment: this.placement }) .show({ content: this.popover, placement: this.placement, title: this.popoverTitle, containerClass: this.containerClass }); this.isOpen = true; }; /** * Closes an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.hide = function () { if (this.isOpen) { this._popover.hide(); this.isOpen = false; } }; /** * Toggles an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.toggle = function () { if (this.isOpen) { return this.hide(); } this.show(); }; PopoverDirective.prototype.ngOnInit = function () { var _this = this; // fix: seems there are an issue with `routerLinkActive` // which result in duplicated call ngOnInit without call to ngOnDestroy // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885 if (this._isInited) { return; } this._isInited = true; this._popover.listen({ triggers: this.triggers, outsideClick: this.outsideClick, show: function () { return _this.show(); } }); }; PopoverDirective.prototype.ngOnDestroy = function () { this._popover.dispose(); }; PopoverDirective.decorators = [ { type: Directive, args: [{ selector: '[popover]', exportAs: 'bs-popover' },] }, ]; /** @nocollapse */ PopoverDirective.ctorParameters = function () { return [ { type: ElementRef, }, { type: Renderer, }, { type: ViewContainerRef, }, { type: PopoverConfig, }, { type: ComponentLoaderFactory, }, ]; }; PopoverDirective.propDecorators = { 'popover': [{ type: Input },], 'popoverTitle': [{ type: Input },], 'placement': [{ type: Input },], 'outsideClick': [{ type: Input },], 'triggers': [{ type: Input },], 'container': [{ type: Input },], 'containerClass': [{ type: Input },], 'isOpen': [{ type: Input },], 'onShown': [{ type: Output },], 'onHidden': [{ type: Output },], }; return PopoverDirective; }()); export { PopoverDirective }; //# sourceMappingURL=popover.directive.js.map