UNPKG

ngx-bootstrap

Version:
165 lines 5.63 kB
import { Directive, ElementRef, EventEmitter, Input, Output, Renderer2, ViewContainerRef } from '@angular/core'; import { PopoverConfig } from './popover.config'; import { ComponentLoaderFactory } from '../component-loader/index'; import { PopoverContainerComponent } from './popover-container.component'; /** * A lightweight, extensible directive for fancy popover creation. */ var PopoverDirective = /** @class */ (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 if (typeof window !== 'undefined') { _elementRef.nativeElement.addEventListener('click', function () { try { _elementRef.nativeElement.focus(); } catch (err) { return; } }); } } Object.defineProperty(PopoverDirective.prototype, "isOpen", { get: /** * Returns whether or not the popover is currently being shown */ 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. */ /** * Opens an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.show = /** * Opens an element’s popover. This is considered a “manual” triggering of * the popover. */ function () { if (this._popover.isShown || !this.popover) { return; } this._popover .attach(PopoverContainerComponent) .to(this.container) .position({ attachment: this.placement }) .show({ content: this.popover, context: this.popoverContext, 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. */ /** * Closes an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.hide = /** * Closes an element’s popover. This is considered a “manual” triggering of * the popover. */ function () { if (this.isOpen) { this._popover.hide(); this.isOpen = false; } }; /** * Toggles an element’s popover. This is considered a “manual” triggering of * the popover. */ /** * Toggles an element’s popover. This is considered a “manual” triggering of * the popover. */ PopoverDirective.prototype.toggle = /** * Toggles an element’s popover. This is considered a “manual” triggering of * the popover. */ 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: Renderer2, }, { type: ViewContainerRef, }, { type: PopoverConfig, }, { type: ComponentLoaderFactory, }, ]; }; PopoverDirective.propDecorators = { "popover": [{ type: Input },], "popoverContext": [{ 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