[Library]: Fix directive click outside for server mode.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57325 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
8e7a67932c
commit
f07c3b6f1f
|
@ -3,6 +3,7 @@ import {Observable} from 'rxjs/Observable';
|
|||
import 'rxjs/add/observable/fromEvent';
|
||||
import 'rxjs/add/operator/delay';
|
||||
import 'rxjs/add/operator/do';
|
||||
import {Subscriber} from "rxjs";
|
||||
|
||||
@Directive({
|
||||
selector: '[click-outside-or-esc]'
|
||||
|
@ -10,8 +11,7 @@ import 'rxjs/add/operator/do';
|
|||
|
||||
export class ClickOutsideOrEsc implements OnInit, OnDestroy {
|
||||
private listening: boolean;
|
||||
private globalClick: any;
|
||||
private escClick: any;
|
||||
private subscriptions: any[] = [];
|
||||
|
||||
@Output('clickOutside') clickOutside: EventEmitter<Object>;
|
||||
|
||||
|
@ -21,15 +21,16 @@ export class ClickOutsideOrEsc implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.globalClick = Observable
|
||||
if(typeof document !== 'undefined') {
|
||||
this.subscriptions.push(Observable
|
||||
.fromEvent(document, 'click')
|
||||
.delay(1)
|
||||
.do(() => {
|
||||
this.listening = true;
|
||||
}).subscribe((event: MouseEvent) => {
|
||||
this.onGlobalClick(event);
|
||||
});
|
||||
this.escClick = Observable
|
||||
}));
|
||||
this.subscriptions.push(Observable
|
||||
.fromEvent(document, 'keydown')
|
||||
.delay(1)
|
||||
.do(() => {
|
||||
|
@ -41,12 +42,17 @@ export class ClickOutsideOrEsc implements OnInit, OnDestroy {
|
|||
value: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.globalClick.unsubscribe();
|
||||
this.escClick.unsubscribe();
|
||||
if (this.subscriptions) {
|
||||
this.subscriptions.forEach((subscription: Subscriber<any>) => {
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
}
|
||||
this.subscriptions = [];
|
||||
}
|
||||
|
||||
onGlobalClick(event: MouseEvent) {
|
||||
|
|
Loading…
Reference in New Issue