Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici authored and Çağatay Çivici committed Jul 20, 2018
1 parent 5873ab2 commit a40fd23
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/app/components/overlaypanel/overlaypanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class OverlayPanel implements AfterViewInit,AfterViewChecked,OnDestroy {
targetClickEvent: boolean;

closeClick: boolean;

documentResizeListener: any;

constructor(public el: ElementRef, public domHandler: DomHandler, public renderer: Renderer2, private cd: ChangeDetectorRef) {}

Expand All @@ -85,6 +87,7 @@ export class OverlayPanel implements AfterViewInit,AfterViewChecked,OnDestroy {
if(this.willShow) {
this.domHandler.absolutePosition(this.container, this.target);
this.bindDocumentClickListener();
this.bindDocumentResizeListener();
this.onAfterShow.emit(null);
this.willShow = false;
}
Expand Down Expand Up @@ -149,6 +152,7 @@ export class OverlayPanel implements AfterViewInit,AfterViewChecked,OnDestroy {
this.selfClick = false;
this.targetClickEvent = false;
this.unbindDocumentClickListener();
this.unbindDocumentResizeListener();
}
}

Expand All @@ -167,8 +171,25 @@ export class OverlayPanel implements AfterViewInit,AfterViewChecked,OnDestroy {
event.preventDefault();
}

onWindowResize(event) {
this.hide();
}

bindDocumentResizeListener() {
this.documentResizeListener = this.onWindowResize.bind(this);
window.addEventListener('resize', this.documentResizeListener);
}

unbindDocumentResizeListener() {
if (this.documentResizeListener) {
window.removeEventListener('resize', this.documentResizeListener);
this.documentResizeListener = null;
}
}

ngOnDestroy() {
this.unbindDocumentClickListener();
this.unbindDocumentResizeListener();

if(this.appendTo) {
this.el.nativeElement.appendChild(this.container);
Expand Down

0 comments on commit a40fd23

Please sign in to comment.