@@ -5,43 +5,46 @@ import { Directive, ElementRef, OnInit, HostBinding, HostListener, Renderer2 } f
55} )
66export class FullScreenWizardDirective implements OnInit {
77 private modalElement : Element ;
8+ private hostTagName : string ;
89 constructor ( el : ElementRef , private renderer : Renderer2 ) {
910 this . modalElement = el . nativeElement ;
11+ this . hostTagName = this . modalElement . tagName ;
1012 }
1113
1214 ngOnInit ( ) {
1315 let observer = new MutationObserver ( ( mutations , observe ) => {
14- if ( mutations . length > 0 ) {
15- let wizardOpen = mutations [ 0 ] . target . parentElement . getAttribute ( 'ng-reflect-clr-wizard- open') ;
16+ if ( mutations . length > 0 && this . hostTagName === 'CLR-WIZARD' ) {
17+ let wizardOpen = ( < Element > mutations [ 0 ] . target ) . classList . contains ( ' open') ;
1618 if ( wizardOpen ) {
17- let div : HTMLDivElement = < HTMLDivElement > this . modalElement . firstChild . childNodes [ 1 ] ;
18- if ( div ) {
19- let content = < HTMLDivElement > div . firstChild ;
20- let modalHeader = < HTMLElement > ( < HTMLCollection > content . getElementsByClassName ( 'modal-header' ) ) [ 0 ] ;
21- let button : Element = this . renderer . createElement ( 'button' ) ;
22- button . addEventListener ( 'click' , ( ) => {
23- let shape = button . firstElementChild . getAttribute ( 'shape' )
24- if ( 'window-restore' == shape ) {
25- this . winRestore ( div ) ;
26- button . firstElementChild . setAttribute ( 'shape' , 'window-max' ) ;
27- } else {
28- this . winMax ( div ) ;
29- button . firstElementChild . setAttribute ( 'shape' , 'window-restore' ) ;
30- }
31- } ) ;
32- button . classList . add ( 'close' ) ;
33- button . innerHTML = '<clr-icon shape="window-max"></clr-icon>' ;
34- this . renderer . setAttribute ( button , 'style' , 'margin-right:16px' ) ;
35- this . renderer . insertBefore ( modalHeader , button , modalHeader . lastElementChild ) ;
19+ if ( this . modalElement . firstChild . childNodes . length > 1 ) {
20+ let div : HTMLDivElement = < HTMLDivElement > this . modalElement . firstChild . childNodes [ 1 ] ;
21+ if ( div ) {
22+ let content = < HTMLDivElement > div . firstChild ;
23+ let modalHeader = < HTMLElement > ( < HTMLCollection > content . getElementsByClassName ( 'modal-header' ) ) [ 0 ] ;
24+ let button : Element = this . renderer . createElement ( 'button' ) ;
25+ button . classList . add ( 'close' ) ;
26+ button . innerHTML = '<clr-icon shape="window-max"></clr-icon>' ;
27+ button . addEventListener ( 'click' , ( ) => {
28+ let shape = button . firstElementChild . getAttribute ( 'shape' )
29+ if ( 'window-restore' === shape ) {
30+ this . winRestore ( div ) ;
31+ button . firstElementChild . setAttribute ( 'shape' , 'window-max' ) ;
32+ } else {
33+ this . winMax ( div ) ;
34+ button . firstElementChild . setAttribute ( 'shape' , 'window-restore' ) ;
35+ }
36+ } ) ;
37+ this . renderer . setAttribute ( button , 'style' , 'margin-right:16px' ) ;
38+ this . renderer . insertBefore ( modalHeader , button , modalHeader . lastElementChild ) ;
39+ }
3640 }
3741 }
3842 }
3943 } ) ;
4044 observer . observe ( this . modalElement . firstChild , { childList : true } ) ;
4145 }
4246
43- winMax ( div : HTMLDivElement ) {
44- // full scren
47+ private winMax ( div : HTMLDivElement ) {
4548 div . style . padding = '0px' ;
4649 let content = < HTMLDivElement > div . firstChild ;
4750 content . style . height = '100vh' ;
@@ -52,8 +55,8 @@ export class FullScreenWizardDirective implements OnInit {
5255 modalContent . style . maxHeight = '100vh' ;
5356 }
5457
55- winRestore ( div : HTMLDivElement ) {
56- div . style . padding = '0px ' ;
58+ private winRestore ( div : HTMLDivElement ) {
59+ div . style . padding = '' ;
5760 let content = < HTMLDivElement > div . firstChild ;
5861 content . style . height = '75vh' ;
5962 content . style . width = '' ;
@@ -62,4 +65,4 @@ export class FullScreenWizardDirective implements OnInit {
6265 modalNav . style . maxHeight = '75vh' ;
6366 modalContent . style . maxHeight = '75vh' ;
6467 }
65- }
68+ }
0 commit comments