Permalink
Browse files

release 2.0.1 that fixes a bug with inputs that had pre defined values

  • Loading branch information...
1 parent 1da6086 commit fa76e4da98b1806eb1d817dcdebc2869611004f1 @fabiomcosta committed Nov 27, 2010
Showing with 26 additions and 22 deletions.
  1. +24 −20 Build/Meio.Mask.js
  2. +1 −1 Build/Meio.Mask.min.js
  3. +1 −1 package.yml
View
@@ -81,7 +81,7 @@ provides: [Meio.Mask]
},
unlink: function(){
- return this.dettach();
+ return this.detach();
},
attach: function(){
@@ -205,8 +205,6 @@ provides: [Meio.Mask]
});
- Meio.Mask.implement('dettach', Meio.Mask.prototype.detach);
-
Meio.Mask.extend({
matchRules: '',
@@ -357,9 +355,10 @@ Meio.Mask.Fixed = new Class({
initialize: function(options){
this.parent(options);
+ this.slice = Array.prototype.slice;
this.maskArray = this.options.mask.split('');
- this.maskMold = this.options.mask.replace(Meio.Mask.rulesRegex, this.options.placeholder);
- this.maskMoldArray = this.maskMold.split('');
+ this.maskMold = this.options.mask.replace(Meio.Mask.rulesRegex, this.options.placeholder).split('');
+ this.maskMoldEmpty = this.slice.call(this.maskMold);
this.validIndexes = [];
this.maskArray.each(function(c, i){
if (!this.isFixedChar(c)) this.validIndexes.push(i);
@@ -370,13 +369,18 @@ Meio.Mask.Fixed = new Class({
link: function(element){
this.parent(element);
var elementValue = this.element.get('value');
- if (elementValue != '') this.maskMoldArray = this.mask(elementValue).split('');
+ if (elementValue != ''){
+ var maskedValue = this.mask(elementValue);
+ for (var i = maskedValue.length; i--;){
+ this.maskMold[i] = maskedValue.charAt(i);
+ }
+ }
if (this.options.autoSetSize) this.setSize();
return this;
},
focus: function(e, o){
- this.element.set('value', this.maskMoldArray.join(''));
+ this.element.set('value', this.maskMold.join(''));
if (this.options.selectOnFocus && this.element.select) this.element.select();
this.parent(e, o);
},
@@ -386,7 +390,7 @@ Meio.Mask.Fixed = new Class({
var elementValue = this.element.get('value');
if (this.options.removeIfInvalid){
if (elementValue.contains(this.options.placeholder)){
- this.maskMoldArray = this.maskMold.split('');
+ this.maskMold = this.split.call(this.maskMoldEmpty);
this.element.set('value', '');
}
return true;
@@ -402,7 +406,7 @@ Meio.Mask.Fixed = new Class({
var c = String.fromCharCode(e.code),
maskArray = this.maskArray,
start, i, returnFromTestEntry;
-
+
if(!o.isSelection){
// no text selected
var finalRangePosition;
@@ -415,16 +419,16 @@ Meio.Mask.Fixed = new Class({
do {
start = this.validIndexes.indexOf(o.range.start++);
} while (start == -1 && o.range.start < maskArray.length);
- finalRangePosition = (start == -1) ? this.maskMoldArray.length : this.validIndexes[start + 1];
+ finalRangePosition = (start == -1) ? this.maskMold.length : this.validIndexes[start + 1];
}
i = this.validIndexes[start];
if (!(returnFromTestEntry = this.testEvents(i, c, e.code, o.isRemoveKey))) return true;
if (typeof returnFromTestEntry == 'string') c = returnFromTestEntry;
- this.maskMoldArray[i] = (o.isRemoveKey) ? this.options.placeholder : c;
+ this.maskMold[i] = (o.isRemoveKey) ? this.options.placeholder : c;
- var newCarretPosition = (finalRangePosition == null) ? this.maskMoldArray.length : finalRangePosition;
- this.element.set('value', this.maskMoldArray.join(''))
+ var newCarretPosition = (finalRangePosition == null) ? this.maskMold.length : finalRangePosition;
+ this.element.set('value', this.maskMold.join(''))
.setCaretPosition(newCarretPosition);
} else {
@@ -446,27 +450,27 @@ Meio.Mask.Fixed = new Class({
// removes all the chars into the range
for (i=rstart; i<rend; i++){
- this.maskMoldArray[i] = this.maskMold.charAt(i);
+ this.maskMold[i] = this.maskMoldEmpty[i];
}
if (!o.isRemoveKey){
i = this.validIndexes[start];
if (!(returnFromTestEntry = this.testEvents(i, c, e.code, o.isRemoveKey))) return true;
if (typeof returnFromTestEntry == 'string') c = returnFromTestEntry;
- this.maskMoldArray[i] = c;
+ this.maskMold[i] = c;
start++;
}
- this.element.set('value', this.maskMoldArray.join(''));
+ this.element.set('value', this.maskMold.join(''));
this.element.setCaretPosition(this.validIndexes[start]);
}
return this.parent();
},
paste: function(e, o){
var retApply = this.applyMask(this.element.get('value'), o.range.start);
- this.maskMoldArray = retApply.value;
- this.element.set('value', this.maskMoldArray.join(''))
+ this.maskMold = retApply.value;
+ this.element.set('value', this.maskMold.join(''))
.setCaretPosition(retApply.rangeStart);
return true;
},
@@ -528,7 +532,7 @@ Meio.Mask.Fixed = new Class({
applyMask: function(str, newRangeStart){
var strArray = str.split(''),
maskArray = this.maskArray,
- maskMold = this.maskMoldArray,
+ maskMold = this.maskMold,
rules = Meio.Mask.rules,
eli = 0,
returnFromTestEntry;
@@ -552,7 +556,7 @@ Meio.Mask.Fixed = new Class({
eli++;
}
- return {value: strArray.slice(0, this.maskMold.length), rangeStart: newRangeStart + 1};
+ return {value: strArray.slice(0, this.maskMoldEmpty.length), rangeStart: newRangeStart + 1};
},
mask: function(str){
Oops, something went wrong.

0 comments on commit fa76e4d

Please sign in to comment.