Skip to content

Commit

Permalink
Adding test case, fixing .trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Kahn committed Aug 5, 2011
1 parent 46f4262 commit c2a15dd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
3 changes: 0 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ $('#input').iMask({
- Numeric Masking
- Control currency symbol, decimal & thousands seperator, # of digits
- Events
- onFocus
- onBlur
- onValid
- onInvalid
- onKeyDown
The core code for the iMask plugin was originally created for MooTools by Fabio Zendhi Nagao (http://zendold.lojcomm.com.br/imask/)
26 changes: 10 additions & 16 deletions lib/jquery.imask.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
validAlphas : "abcdefghijklmnopqrstuvwxyz",
validAlphaNums : "abcdefghijklmnopqrstuvwxyz1234567890",

onFocus : function(){},
onBlur : function(){},
onValid : function(){},
onInvalid : function(){},
onKeyDown : function(){},

groupDigits : 3,
decDigits : 2,
currencySymbol : '',
Expand Down Expand Up @@ -138,16 +132,16 @@
{this.updSelection(p, chr.toUpperCase());}
else
{this.updSelection(p, chr);}
this.trigger("onValid", [ev, obj], 20);
this.node.trigger("valid", ev, this.node);
this.selectNext();
} else {
this.trigger("onInvalid", [ev, obj], 20);
this.node.trigger("invalid", ev, this.node);
}
break;
}
} else if(this.options.type == "number") {
switch(ev.which) {
case 8: // backspace
case 8: // backspace
case 46: // delete
this.popNumber();
break;
Expand All @@ -158,9 +152,9 @@
if(val !== false){
this.pushNumber(chr);
}
this.trigger("onValid", [ev, obj], 20);
this.node.trigger("valid", ev, this.node);
} else {
this.trigger("onInvalid", [ev, obj], 20);
this.node.trigger("invalid", ev, this.node);
}
break;
}
Expand Down Expand Up @@ -188,11 +182,11 @@
this.options.showMask && (this.domNode.value = this.wearMask(this.domNode.value));
this.sanityTest(this.domNode.value);

if(this.options.type == "fixed"){
this.selectFirst.bind(this).defer(1);
} else {
this.setEnd.bind(this).defer(1);
}
var self = this;

setTimeout( function(){
self[ self.options.type === "fixed" ? 'selectFirst' : 'setEnd' ]();
}, 1 );
},

onBlur: function(ev) {
Expand Down
32 changes: 32 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../lib/jquery.imask.js"></script>
<script type="text/javascript">
$(function(){
$('#inp1').iMask({
type : 'number'
});

$('#inp2').iMask({
type : 'fixed'
, mask : '99/99/99'
})
});
</script>

<style>
label {
min-width : 100px;
display : inline-block;
}
</style>

</head>
<body>
<label>Number: </label><input id="inp1">
<br />
<label>Date: </label><input id="inp2">
</body>
</html>

0 comments on commit c2a15dd

Please sign in to comment.