|
|
@ -6,7 +6,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Directive, EmbeddedViewRef, Input, OnChanges, OnDestroy, Renderer2, SimpleChanges, TemplateRef, ViewContainerRef } from '@angular/core'; |
|
|
import { ChangeDetectorRef, Directive, EmbeddedViewRef, Input, OnChanges, OnDestroy, Renderer2, SimpleChanges, TemplateRef, ViewContainerRef } from '@angular/core'; |
|
|
import { Subscription } from 'rxjs'; |
|
|
import { Subscription, timer } from 'rxjs'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
DialogModel, |
|
|
DialogModel, |
|
|
@ -22,6 +22,7 @@ import { RootViewComponent } from './root-view.component'; |
|
|
export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
private subscription: Subscription | null = null; |
|
|
private subscription: Subscription | null = null; |
|
|
private documentClickListener: Function | null = null; |
|
|
private documentClickListener: Function | null = null; |
|
|
|
|
|
private documentClickTimer: Subscription | null = null; |
|
|
private renderedView: EmbeddedViewRef<any> | null = null; |
|
|
private renderedView: EmbeddedViewRef<any> | null = null; |
|
|
|
|
|
|
|
|
@Input('sqxModalView') |
|
|
@Input('sqxModalView') |
|
|
@ -76,6 +77,8 @@ export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.unsubscribeToClick(); |
|
|
|
|
|
|
|
|
if (isOpen && !this.renderedView) { |
|
|
if (isOpen && !this.renderedView) { |
|
|
const container = this.getContainer(); |
|
|
const container = this.getContainer(); |
|
|
|
|
|
|
|
|
@ -85,9 +88,9 @@ export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
this.renderer.setStyle(this.renderedView.rootNodes[0], 'display', 'block'); |
|
|
this.renderer.setStyle(this.renderedView.rootNodes[0], 'display', 'block'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
this.documentClickTimer = timer(1000, 0).subscribe(() => { |
|
|
this.startListening(); |
|
|
this.startListening(); |
|
|
}, 1000); |
|
|
}); |
|
|
|
|
|
|
|
|
this.changeDetector.detectChanges(); |
|
|
this.changeDetector.detectChanges(); |
|
|
} else if (!isOpen && this.renderedView) { |
|
|
} else if (!isOpen && this.renderedView) { |
|
|
@ -98,8 +101,6 @@ export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
|
|
|
|
|
|
this.renderedView = null; |
|
|
this.renderedView = null; |
|
|
|
|
|
|
|
|
this.unsubscribeToClick(); |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetector.detectChanges(); |
|
|
this.changeDetector.detectChanges(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -113,6 +114,8 @@ export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.unsubscribeToClick(); |
|
|
|
|
|
|
|
|
this.documentClickListener = |
|
|
this.documentClickListener = |
|
|
this.renderer.listen('document', 'click', (event: MouseEvent) => { |
|
|
this.renderer.listen('document', 'click', (event: MouseEvent) => { |
|
|
if (!event.target || this.renderedView === null) { |
|
|
if (!event.target || this.renderedView === null) { |
|
|
@ -156,5 +159,10 @@ export class ModalViewDirective implements OnChanges, OnDestroy { |
|
|
this.documentClickListener(); |
|
|
this.documentClickListener(); |
|
|
this.documentClickListener = null; |
|
|
this.documentClickListener = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.documentClickTimer) { |
|
|
|
|
|
this.documentClickTimer.unsubscribe(); |
|
|
|
|
|
this.documentClickTimer = null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |