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,GAA2C;QAChE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC/B,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC9B,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC/B,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC/B,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAChC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QAC9B,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;KAC9B,CAAC;IACF,0BAAC;AAAD,CAAC,AAhPD,IAgPC","sourcesContent":["import {\n Directive, ElementRef, EmbeddedViewRef, EventEmitter, HostBinding, Input, OnDestroy, OnInit, Output,\n Renderer, ViewContainerRef\n} from '@angular/core';\nimport { Subscription } from 'rxjs/Subscription';\nimport 'rxjs/add/operator/filter';\nimport { ComponentLoader, ComponentLoaderFactory } from '../component-loader';\n\nimport { BsDropdownConfig } from './bs-dropdown.config';\nimport { BsDropdownContainerComponent } from './bs-dropdown-container.component';\nimport { BsDropdownState } from './bs-dropdown.state';\nimport { BsComponentRef } from '../component-loader/bs-component-ref.class';\nimport { BsDropdownMenuDirective } from './';\nimport { isBs3 } from '../utils/ng2-bootstrap-config';\n\n\nexport class BsDropdownDirective implements OnInit, OnDestroy {\n /**\n * Placement of a popover. Accepts: \"top\", \"bottom\", \"left\", \"right\"\n */\n placement: string;\n /**\n * Specifies events that should trigger. Supports a space separated list of\n * event names.\n */\n triggers: string;\n /**\n * A selector specifying the element the popover should be appended to.\n * Currently only supports \"body\".\n */\n container: string;\n\n /**\n * This attribute indicates that the dropdown should be opened upwards\n */\n dropup: boolean;\n\n /**\n * Indicates that dropdown will be closed on item or document click,\n * and after pressing ESC\n */\n set autoClose(value: boolean) {\n if (typeof value === 'boolean') {\n this._state.autoClose = value;\n }\n };\n\n get autoClose(): boolean {\n return this._state.autoClose;\n }\n\n /**\n * Disables dropdown toggle and hides dropdown menu if opened\n */\n set isDisabled(value: boolean) {\n this._isDisabled = value;\n this._state.isDisabledChange.emit(value);\n if (value) {\n this.hide();\n }\n }\n\n get isDisabled(): boolean { return this._isDisabled; }\n\n /**\n * Returns whether or not the popover is currently being shown\n */\n get isOpen(): boolean {\n if (this._showInline) {\n return this._isInlineOpen;\n }\n return this._dropdown.isShown;\n }\n\n set isOpen(value: boolean) {\n if (value) {\n this.show();\n } else {\n this.hide();\n }\n }\n\n /**\n * Emits an event when the popover is shown\n */\n onShown: EventEmitter<any>;\n /**\n * Emits an event when the popover is hidden\n */\n onHidden: EventEmitter<any>;\n\n get isBs4(): boolean {\n return !isBs3();\n }\n // todo: move to component loader\n private _isInlineOpen = false;\n private _showInline: boolean;\n private _inlinedMenu: EmbeddedViewRef<BsDropdownMenuDirective>;\n\n private _isDisabled: boolean;\n private _dropdown: ComponentLoader<BsDropdownContainerComponent>;\n private _subscriptions: Subscription[] = [];\n\n constructor(private _elementRef: ElementRef,\n private _renderer: Renderer,\n private _viewContainerRef: ViewContainerRef,\n private _cis: ComponentLoaderFactory,\n private _config: BsDropdownConfig,\n private _state: BsDropdownState) {\n // create dropdown component loader\n this._dropdown = this._cis\n .createLoader<BsDropdownContainerComponent>(this._elementRef, this._viewContainerRef, this._renderer)\n .provide({provide: BsDropdownState, useValue: this._state});\n\n this.onShown = this._dropdown.onShown;\n this.onHidden = this._dropdown.onHidden;\n\n // set initial dropdown state from config\n this._state.autoClose = this._config.autoClose;\n }\n\n ngOnInit(): void {\n this._showInline = !this.container;\n\n // attach DOM listeners\n this._dropdown.listen({\n triggers: this.triggers,\n show: () => this.show()\n });\n\n // toggle visibility on toggle element click\n this._subscriptions.push(this._state\n .toggleClick.subscribe((value: boolean) => this.toggle(value)));\n\n // hide dropdown if set disabled while opened\n this._subscriptions.push(this._state\n .isDisabledChange\n .filter((value: boolean) => value === true)\n .subscribe((value: boolean) => this.hide()));\n\n // attach dropdown menu inside of dropdown\n if (this._showInline) {\n this._state.dropdownMenu\n .then((dropdownMenu:BsComponentRef<BsDropdownMenuDirective>) => {\n this._inlinedMenu = dropdownMenu.viewContainer.createEmbeddedView(dropdownMenu.templateRef);\n });\n }\n }\n\n /**\n * Opens an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n show(): void {\n if (this.isOpen || this.isDisabled) {\n return;\n }\n\n if (this._showInline) {\n this._isInlineOpen = true;\n this._state.isOpenChange.emit(true);\n return;\n }\n\n this._state.dropdownMenu\n .then((dropdownMenu) => {\n // check direction in which dropdown should be opened\n const _dropup = this.dropup === true ||\n (typeof this.dropup !== 'undefined' && this.dropup !== false);\n this._state.direction = _dropup ? 'up' : 'down';\n const _placement = this.placement ||\n (_dropup ? 'top left' : 'bottom left');\n\n // show dropdown\n this._dropdown\n .attach(BsDropdownContainerComponent)\n .to(this.container)\n .position({attachment: _placement})\n .show({\n content: dropdownMenu.templateRef,\n placement: _placement\n });\n\n this._state.isOpenChange.emit(true);\n });\n }\n\n /**\n * Closes an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n hide(): void {\n if (!this.isOpen) {\n return;\n }\n\n if (this._showInline) {\n this._isInlineOpen = false;\n } else {\n this._dropdown.hide();\n }\n\n this._state.isOpenChange.emit(false);\n }\n\n /**\n * Toggles an element’s popover. This is considered a “manual” triggering of\n * the popover.\n */\n toggle(value?: boolean): void {\n if (this.isOpen || value === false) {\n return this.hide();\n }\n\n return this.show();\n }\n\n ngOnDestroy(): void {\n // clean up subscriptions and destroy dropdown\n for (const sub of this._subscriptions) {\n sub.unsubscribe();\n }\n this._dropdown.dispose();\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Directive, args: [{\n selector: '[bsDropdown],[dropdown]',\n exportAs: 'bs-dropdown',\n providers: [BsDropdownState],\n host: {\n '[class.dropup]': 'dropup',\n '[class.open]': 'isOpen',\n '[class.show]': 'isOpen && isBs4'\n }\n}, ] },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: ElementRef, },\n{type: Renderer, },\n{type: ViewContainerRef, },\n{type: ComponentLoaderFactory, },\n{type: BsDropdownConfig, },\n{type: BsDropdownState, },\n];\nstatic propDecorators: {[key: string]: DecoratorInvocation[]} = {\n'placement': [{ type: Input },],\n'triggers': [{ type: Input },],\n'container': [{ type: Input },],\n'dropup': [{ type: Input },],\n'autoClose': [{ type: Input },],\n'isDisabled': [{ type: Input },],\n'isOpen': [{ type: Input },],\n'onShown': [{ type: Output },],\n'onHidden': [{ type: Output },],\n};\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}
\No newline at end of file