-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (42 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Inputmask from 'inputmask';
var Settings = {
getInputMaskOptions : function(binding) {
return binding.value;
},
getTargetElement : function(sourceEl) {
if (sourceEl.tagName === 'INPUT') {
return sourceEl;
}
if ( sourceEl.dataset['inputmaskTarget'] ) {
return sourceEl.querySelector(sourceEl.dataset['inputmaskTarget']);
}
return sourceEl.querySelector('input');
}
};
export default {
install : function(Vue) {
Vue.directive('inputmask', {
bind: function (el, binding, vnode) {
var inputEl = Settings.getTargetElement(el);
var maskOptions = Settings.getInputMaskOptions(binding);
Inputmask(maskOptions).mask(inputEl);
},
unbind: function (el, binding, vnode) {
var inputEl = Settings.getTargetElement(el);
if ( inputEl.inputmask ) {
inputEl.inputmask.remove();
}
},
componentUpdated: function(el, binding){
var inputEl = Settings.getTargetElement(el);
var maskOptions = Settings.getInputMaskOptions(binding);
if ( binding.value !== binding.oldValue ) {
if ( inputEl.inputmask ) {
inputEl.inputmask.remove();
}
Inputmask(maskOptions).mask(inputEl);
}
}
});
}
}