1 | import { Directive, ElementRef, HostBinding, HostListener } from '@angular/core';
|
2 | import { BsDropdownState } from './bs-dropdown.state';
|
3 | export var BsDropdownToggleDirective = (function () {
|
4 | function BsDropdownToggleDirective(_state, _element) {
|
5 | var _this = this;
|
6 | this._state = _state;
|
7 | this._element = _element;
|
8 | this.isDisabled = null;
|
9 | this._subscriptions = [];
|
10 |
|
11 | this._subscriptions.push(this._state
|
12 | .isOpenChange.subscribe(function (value) { return _this.isOpen = value; }));
|
13 |
|
14 | this._subscriptions.push(this._state
|
15 | .isDisabledChange
|
16 | .subscribe(function (value) { return _this.isDisabled = value || null; }));
|
17 | }
|
18 | BsDropdownToggleDirective.prototype.onClick = function () {
|
19 | if (this.isDisabled) {
|
20 | return;
|
21 | }
|
22 | this._state.toggleClick.emit();
|
23 | };
|
24 | BsDropdownToggleDirective.prototype.onDocumentClick = function (event) {
|
25 | if (this._state.autoClose && event.button !== 2 &&
|
26 | !this._element.nativeElement.contains(event.target)) {
|
27 | this._state.toggleClick.emit(false);
|
28 | }
|
29 | };
|
30 | BsDropdownToggleDirective.prototype.onEsc = function () {
|
31 | if (this._state.autoClose) {
|
32 | this._state.toggleClick.emit(false);
|
33 | }
|
34 | };
|
35 | BsDropdownToggleDirective.prototype.ngOnDestroy = function () {
|
36 | for (var _i = 0, _a = this._subscriptions; _i < _a.length; _i++) {
|
37 | var sub = _a[_i];
|
38 | sub.unsubscribe();
|
39 | }
|
40 | };
|
41 | BsDropdownToggleDirective.decorators = [
|
42 | { type: Directive, args: [{
|
43 | selector: '[bsDropdownToggle],[dropdownToggle]',
|
44 | exportAs: 'bs-dropdown-toggle',
|
45 | host: {
|
46 | '[attr.aria-haspopup]': 'true'
|
47 | }
|
48 | },] },
|
49 | ];
|
50 |
|
51 | BsDropdownToggleDirective.ctorParameters = function () { return [
|
52 | { type: BsDropdownState, },
|
53 | { type: ElementRef, },
|
54 | ]; };
|
55 | BsDropdownToggleDirective.propDecorators = {
|
56 | 'isDisabled': [{ type: HostBinding, args: ['attr.disabled',] },],
|
57 | 'isOpen': [{ type: HostBinding, args: ['attr.aria-expanded',] },],
|
58 | 'onClick': [{ type: HostListener, args: ['click',] },],
|
59 | 'onDocumentClick': [{ type: HostListener, args: ['document:click', ['$event'],] },],
|
60 | 'onEsc': [{ type: HostListener, args: ['keyup.esc',] },],
|
61 | };
|
62 | return BsDropdownToggleDirective;
|
63 | }());
|
64 |
|
\ | No newline at end of file |