@@ -2,20 +2,19 @@ import {
2
2
Directive ,
3
3
HostListener ,
4
4
Input ,
5
- AfterViewInit , OnInit , ViewChild , ElementRef , ContentChildren , QueryList , AfterContentInit , EventEmitter , Output
5
+ AfterViewInit , OnInit , ContentChildren , QueryList , AfterContentInit , EventEmitter , Output
6
6
} from '@angular/core' ;
7
- import { TlInput } from " ../../input/input" ;
7
+ import { TlInput } from ' ../../input/input' ;
8
8
9
9
10
10
@Directive ( {
11
11
selector : '[mask]' ,
12
12
} )
13
13
export class FieldMaskDirective implements AfterViewInit , OnInit , AfterContentInit {
14
14
15
- private maskGuides ;
16
-
17
15
@ContentChildren ( TlInput ) tlinput : QueryList < TlInput > ;
18
16
17
+ private maskGuides ;
19
18
private value ;
20
19
private input ;
21
20
@@ -54,25 +53,25 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
54
53
const value = this . input . nativeElement . value ;
55
54
const start = this . input . nativeElement . selectionStart ;
56
55
const end = this . input . nativeElement . selectionEnd ;
57
-
56
+
58
57
if ( this . maskGuides ) {
59
- if ( value [ end - 1 ] == this . maskGuideExpression [ end - 1 ] ) {
58
+ if ( value [ end - 1 ] === this . maskGuideExpression [ end - 1 ] ) {
60
59
event . preventDefault ( ) ;
61
60
if ( start > 0 ) {
62
61
this . input . nativeElement . setSelectionRange ( start - 1 , end - 1 ) ;
63
62
}
64
63
}
65
64
66
- if ( value [ end - 1 ] != this . maskGuideExpression [ end - 1 ] ) {
67
- let valueArray = value . split ( '' ) ;
65
+ if ( value [ end - 1 ] !== this . maskGuideExpression [ end - 1 ] ) {
66
+ const valueArray = value . split ( '' ) ;
68
67
event . preventDefault ( ) ;
69
68
let valueResult = '' ;
70
- let self = this ;
71
- valueArray . forEach ( function ( value , index , array ) {
69
+ const self = this ;
70
+ valueArray . forEach ( function ( myValue , index , array ) {
72
71
if ( index === end - 1 ) {
73
72
valueResult = valueResult + self . maskGuideExpression [ end - 1 ] ;
74
73
} else {
75
- valueResult = valueResult + value ;
74
+ valueResult = valueResult + myValue ;
76
75
}
77
76
} ) ;
78
77
@@ -86,10 +85,10 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
86
85
const cursor = this . input . nativeElement . selectionEnd ;
87
86
if ( event . code === 'Delete' ) {
88
87
event . preventDefault ( ) ;
89
- let valueArray = this . input . nativeElement . value . split ( '' ) ;
90
- let self = this ;
88
+ const valueArray = this . input . nativeElement . value . split ( '' ) ;
89
+ const self = this ;
91
90
valueArray . forEach ( function ( value , index , array ) {
92
- if ( index == cursor ) {
91
+ if ( index === cursor ) {
93
92
array [ index ] = self . maskGuideExpression [ cursor ] ;
94
93
}
95
94
} ) ;
@@ -127,7 +126,7 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
127
126
this . setValueOnInicialize ( ) ;
128
127
this . applyGuides ( ) ;
129
128
this . applyMask ( ) ;
130
- } , 0 )
129
+ } , 0 ) ;
131
130
}
132
131
}
133
132
@@ -173,24 +172,24 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
173
172
174
173
private handleKeypress ( event ) {
175
174
176
- let charInputed = event . key ;
175
+ const charInputed = event . key ;
177
176
if ( charInputed !== 'Enter' && charInputed . length > 0 ) {
178
177
179
- let start = this . input . nativeElement . selectionStart ;
180
- let end = this . input . nativeElement . selectionEnd ;
181
- let inputArray = this . input . nativeElement . value . split ( '' ) ;
178
+ const start = this . input . nativeElement . selectionStart ;
179
+ const end = this . input . nativeElement . selectionEnd ;
180
+ const inputArray = this . input . nativeElement . value . split ( '' ) ;
182
181
183
- if ( this . isValidSymbolMask ( charInputed , this . maskExpression [ end ] ) == false ) {
182
+ if ( this . isValidSymbolMask ( charInputed , this . maskExpression [ end ] ) === false ) {
184
183
event . preventDefault ( ) ;
185
- return
184
+ return ;
186
185
}
187
186
188
187
if ( this . maskGuides ) {
189
188
190
189
this . input . nativeElement . value = this . replaceUndescoreForChar ( inputArray , charInputed , end ) ;
191
190
event . preventDefault ( ) ;
192
191
193
- if ( this . input . nativeElement . value . split ( '' ) [ end + 1 ] == this . maskExpression [ end + 1 ]
192
+ if ( this . input . nativeElement . value . split ( '' ) [ end + 1 ] === this . maskExpression [ end + 1 ]
194
193
|| this . maskSpecialCharacters . indexOf ( this . maskExpression [ end ] ) >= 0 ) {
195
194
this . input . nativeElement . setSelectionRange ( start + 2 , end + 2 ) ;
196
195
} else {
@@ -207,7 +206,7 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
207
206
}
208
207
209
208
private onComplete ( ) {
210
- if ( this . clearMask ( this . maskExpression ) . length == this . clearMask ( this . input . nativeElement . value ) . length ) {
209
+ if ( this . clearMask ( this . maskExpression ) . length === this . clearMask ( this . input . nativeElement . value ) . length ) {
211
210
this . tlinput . toArray ( ) [ 0 ] . validations [ 'validMask' ] = true ;
212
211
} else {
213
212
this . tlinput . toArray ( ) [ 0 ] . validations [ 'validMask' ] = false ;
@@ -236,7 +235,7 @@ export class FieldMaskDirective implements AfterViewInit, OnInit, AfterContentIn
236
235
const self = this ;
237
236
if ( this . maskGuides ) {
238
237
setTimeout ( function ( ) {
239
- if ( self . input . nativeElement . value . length == 0 ) {
238
+ if ( self . input . nativeElement . value . length === 0 ) {
240
239
self . input . nativeElement . value = self . maskGuideExpression ;
241
240
}
242
241
} , 1 ) ;
0 commit comments