@@ -2,13 +2,13 @@ import masker from './masker'
2
2
import tokens from './tokens'
3
3
4
4
// https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events#The_old-fashioned_way
5
- function event ( name ) {
5
+ function event ( name ) {
6
6
var evt = document . createEvent ( 'Event' )
7
7
evt . initEvent ( name , true , true )
8
8
return evt
9
9
}
10
10
11
- export default function ( el , binding ) {
11
+ export default function ( el , binding ) {
12
12
var config = binding . value || { }
13
13
if ( Array . isArray ( config ) || typeof config === 'string' ) {
14
14
config = {
@@ -21,20 +21,20 @@ export default function (el, binding) {
21
21
if ( el . tagName . toLocaleUpperCase ( ) !== 'INPUT' ) {
22
22
var els = el . getElementsByTagName ( 'input' )
23
23
if ( els . length !== 1 ) {
24
- throw new Error ( " v-mask directive requires 1 input, found " + els . length )
24
+ throw new Error ( ' v-mask directive requires 1 input, found ' + els . length )
25
25
} else {
26
26
el = els [ 0 ]
27
27
}
28
28
}
29
29
30
- el . oninput = function ( { isTrusted, data} ) {
30
+ el . oninput = function ( { isTrusted, data } ) {
31
31
if ( ! isTrusted ) return // avoid infinite loop
32
32
33
33
// by default, keep cursor at same position as before the mask
34
34
var position = el . selectionEnd
35
35
let cursorAtEnd = data && position == el . value . length
36
36
// save the character just inserted
37
- var digit = el . value [ position - 1 ]
37
+ var digit = el . value [ position - 1 ]
38
38
el . value = masker ( el . value , config . mask , config . masked , config . tokens )
39
39
40
40
if ( el === document . activeElement ) {
@@ -43,15 +43,15 @@ export default function (el, binding) {
43
43
} else if ( digit ) {
44
44
let newPosition = position
45
45
// if the digit was changed, increment position until find the digit again
46
- while ( newPosition <= el . value . length && el . value . charAt ( newPosition - 1 ) !== digit ) {
46
+ while ( newPosition <= el . value . length && el . value . charAt ( newPosition - 1 ) !== digit ) {
47
47
newPosition ++
48
48
}
49
49
// if we didnt find the digit must be a bad digit, leave the cursor where it was
50
50
position = newPosition <= el . value . length ? newPosition : position - 1
51
51
}
52
52
53
53
el . setSelectionRange ( position , position )
54
- setTimeout ( function ( ) {
54
+ setTimeout ( function ( ) {
55
55
el . setSelectionRange ( position , position )
56
56
} , 0 )
57
57
}
0 commit comments