UNPKG

ng2-bootstrap

Version:
64 lines 2.65 kB
import { Directive, ElementRef, HostBinding, HostListener } from '@angular/core'; import { BsDropdownState } from './bs-dropdown.state'; export var BsDropdownToggleDirective = (function () { function BsDropdownToggleDirective(_state, _element) { var _this = this; this._state = _state; this._element = _element; this.isDisabled = null; this._subscriptions = []; // sync is open value with state this._subscriptions.push(this._state .isOpenChange.subscribe(function (value) { return _this.isOpen = value; })); // populate disabled state this._subscriptions.push(this._state .isDisabledChange .subscribe(function (value) { return _this.isDisabled = value || null; })); } BsDropdownToggleDirective.prototype.onClick = function () { if (this.isDisabled) { return; } this._state.toggleClick.emit(); }; BsDropdownToggleDirective.prototype.onDocumentClick = function (event) { if (this._state.autoClose && event.button !== 2 && !this._element.nativeElement.contains(event.target)) { this._state.toggleClick.emit(false); } }; BsDropdownToggleDirective.prototype.onEsc = function () { if (this._state.autoClose) { this._state.toggleClick.emit(false); } }; BsDropdownToggleDirective.prototype.ngOnDestroy = function () { for (var _i = 0, _a = this._subscriptions; _i < _a.length; _i++) { var sub = _a[_i]; sub.unsubscribe(); } }; BsDropdownToggleDirective.decorators = [ { type: Directive, args: [{ selector: '[bsDropdownToggle],[dropdownToggle]', exportAs: 'bs-dropdown-toggle', host: { '[attr.aria-haspopup]': 'true' } },] }, ]; /** @nocollapse */ BsDropdownToggleDirective.ctorParameters = function () { return [ { type: BsDropdownState, }, { type: ElementRef, }, ]; }; BsDropdownToggleDirective.propDecorators = { 'isDisabled': [{ type: HostBinding, args: ['attr.disabled',] },], 'isOpen': [{ type: HostBinding, args: ['attr.aria-expanded',] },], 'onClick': [{ type: HostListener, args: ['click',] },], 'onDocumentClick': [{ type: HostListener, args: ['document:click', ['$event'],] },], 'onEsc': [{ type: HostListener, args: ['keyup.esc',] },], }; return BsDropdownToggleDirective; }()); //# sourceMappingURL=bs-dropdown-toggle.directive.js.map