ソースを参照

avoid needless checking of the value

Robin Herbots 15 年 前
コミット
0074c61587
1 ファイル変更19 行追加18 行削除
  1. 19 18
      jquery.inputmask.js

+ 19 - 18
jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.2.0
+Version: 0.2.1
    
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -70,20 +70,20 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
         var _val = $.inputmask.val;
         if (opts.patch_val && $.fn.val.inputmaskpatch != true) {
             $.fn.val = function() {
-            	if(this.data('inputmask')){
-               	 	if (this.data('autounmask') && arguments.length == 0) {
-                    	return this.inputmask('unmaskedvalue');
-                	}
-                	else {
-                    	var result = _val.apply(this, arguments);
-                    	if (arguments.length > 0) {
-                        	this.triggerHandler('setvalue.inputmask');
-                    	}
-                    	return result;
-                	}
+                if (this.data('inputmask')) {
+                    if (this.data('autounmask') && arguments.length == 0) {
+                        return this.inputmask('unmaskedvalue');
+                    }
+                    else {
+                        var result = _val.apply(this, arguments);
+                        if (arguments.length > 0) {
+                            this.triggerHandler('setvalue.inputmask');
+                        }
+                        return result;
+                    }
                 }
                 else {
-               		 return _val.apply(this, arguments);
+                    return _val.apply(this, arguments);
                 }
             };
             $.extend($.fn.val, {
@@ -291,10 +291,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             var undoBuffer = _val.call(input);
             var ignore = false;              //Variable for ignoring control keys
 
-			//unbind all events - to make sure that no other mask will interfere when re-masking
-			input.unbind(".inputmask");
-        	input.removeClass('focus.inputmask');
-                //bind events
+            //unbind all events - to make sure that no other mask will interfere when re-masking
+            input.unbind(".inputmask");
+            input.removeClass('focus.inputmask');
+            //bind events
             if (!input.attr("readonly")) {
                 input.bind("mouseenter.inputmask", function() {
                     if (!input.hasClass('focus.inputmask') && _val.call(input).length == 0) {
@@ -304,7 +304,6 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 }).bind("blur.inputmask", function() {
                     input.removeClass('focus.inputmask');
                     setTimeout(function() {
-                        checkVal(input, buffer, true);
                         if (_val.call(input) == _buffer.join(''))
                             _val.call(input, '');
                         else if (_val.call(input) != undoBuffer) {
@@ -356,6 +355,8 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             break;
                     }
                 }
+                buffer = buffer.join('').replace(new RegExp("(" + _buffer.join('') + ")*$"), "").split('');
+                if (buffer.length == 0) buffer = _buffer.slice();
                 writeBuffer(input, buffer);
                 caret(input, pos);
             };