r2391 - Added ability to escape mask characters.

r2391 - Added ability to escape mask characters.


Author: powella
Date: Fri Mar 27 11:38:04 2009
New Revision: 2391
Modified:
branches/dev/mask/ui/ui.mask.js
Log:
Added ability to escape mask characters.
Modified: branches/dev/mask/ui/ui.mask.js
==============================================================================
--- branches/dev/mask/ui/ui.mask.js    (original)
+++ branches/dev/mask/ui/ui.mask.js    Fri Mar 27 11:38:04 2009
@@ -19,11 +19,43 @@
    
$.widget("ui.mask", {
+    _escapeMask: function(){
+        var mask = this.options.mask,
+            literals = [],
+            replacements = [];
+        
+        for(var i = 0; i < mask.length; i++){
+            var c, temp = mask[i];
+            if(temp != "\\" || mask[i-1] == "\\"){
+                if(mask[i-1] == "\\"){
+                    c = "\t";
+                    replacements[literals.length] = temp;
+                }
+                else{
+                    c = temp;
+                }
+                literals[literals.length] = c;
+            }
+        }
+        
+        this.options.mask = literals.join('');
+        
+        for(var i = 0; i < literals.length; i++){
+            if(replacements[i] !== undefined){
+                literals[i] = replacements[i];
+            }
+        }
+        
+        this.maskEscaped = literals.join('');
+    },
+    
    _init: function() {
        if(!this.options.mask || !this.options.mask.length) return; //no mask
pattern defined. no point in continuing.
        if(!this.options.placeholder || !this.options.placeholder.length)
this.options.placeholder = '_'; //in case the user decided to nix a
placeholder.
+        this._escapeMask();
+
        var self = this,
            input = this.element,
            options = this.options,
@@ -36,7 +68,7 @@
        //if we're applying the mask to an element which is not an input, it
won't have a val() method. fake one for our purposes.
        if(!input.is(':input')) input.val = input.html;
-            
+
        $.each(mask.split(""), function(i, c) {
            if (c == '?') {
                len--;
@@ -53,12 +85,25 @@
        });
        $.extend(this, {
-            buffer: $.map(mask.split(""), function(c, i) { if (c != '?') return
defs[c] ? options.placeholder : c }),
+            buffer: $.map(mask.split(""), function(c, i){
+                if (c != '?'){
+                    return defs[c] ? options.placeholder : c;
+                }
+            }),
            tests: tests,
            firstNonMaskPos: firstNonMaskPos,
            partialPosition: partialPosition,
            caret: function(begin, end){ return $.ui.mask.caret(input, begin, end);
}
        });
+
+        this.buffer = $.map(this.buffer, function(c, i){
+            if(c == "\t"){
+                return self.maskEscaped[i];
+            }
+            return c;
+        });
+
+        this.options.mask = mask = this.maskEscaped;
        var ignore = false,             //Variable for ignoring control keys
            focusText = input.val();