-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGxMaskRender.js
56 lines (48 loc) · 1.55 KB
/
GxMaskRender.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
54
55
56
function GxMask($)
{
this.AttachControl;
this.Picture;
this.show = function()
{
///UserCodeRegionStart:[show] (do not remove this comment.)
/*
* Author: Daniel San Martin Pascal Filho
* e-mail: daniel.smpf@gmail.com
* Created at: 05/11/2015
*/
var control = this.AttachControl;
this.addMask(control);
///UserCodeRegionEnd: (do not remove this comment.)
}
///UserCodeRegionStart:[User Functions] (do not remove this comment.)
this.addMask = function(el)
{
switch(this.Picture){
case 'telefone':
var telMask = ['(99) 9999-9999', '(99) 99999-9999'];
var tel = document.querySelector('#'+this.AttachControl);
tel.addEventListener('input', inputHandler.bind(undefined, telMask, 14), false);
break;
case 'cpfcnpj':
var docMask = ['999.999.999-99', '99.999.999/9999-99'];
var doc = document.querySelector('#'+this.AttachControl);
doc.addEventListener('input', inputHandler.bind(undefined, docMask, 14), false);
break;
default:
VMasker(document.querySelector('#'+this.AttachControl)).maskPattern(this.Picture);
}
}
function inputHandler(masks, max, event) {
var c = event.target;
var v = c.value.replace(/\D/g, '');
var m = c.value.length > max ? 1 : 0;
VMasker(c).unMask();
VMasker(c).maskPattern(masks[m]);
c.value = VMasker.toPattern(v, masks[m]);
}
this.removeMask = function(el)
{
VMasker(document.querySelector('#'+this.AttachControl)).unMask();
}
///UserCodeRegionEnd: (do not remove this comment.):
}