From 98af1628ac1fb9e33dfdab618ed6e524e7914595 Mon Sep 17 00:00:00 2001 From: galaban Date: Thu, 14 Jul 2011 05:24:54 -0700 Subject: [PATCH] Edited src/jquery.maskedinput.js via GitHub --- src/jquery.maskedinput.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index af67604..ad755d2 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -221,7 +221,42 @@ }).join(''); }) + function applyMask(rawData) { + var out = []; + for (var i = 0, pos = 0; i < len; i++) { + if (tests[i] && pos < rawData.length) { + out[i] = settings.placeholder; + while (pos < rawData.length) { + pos++; + var c = rawData.charAt(pos - 1); + if (tests[i].test(c)) { + out[i] = c; + break; + } + } + if (pos >= rawData.length) + out[i] = buffer[i]; + } else + out[i] = buffer[i]; + } + return out.join(""); + }; + + function stripMask(rawData) { + var outVals = $.map(rawData.split(""), function(c,i) { + if (tests[i]) + return c; + }); + return outVals.join(""); + }; + + // Intialize the buffer with whatever was given to us. + if (focusText.length > 0) + buffer = applyMask(focusText).split(""); + if (!input.attr("readonly")) + // remove the mask from the buffer and store it + input.val(stripMask(buffer.join(''))); input .one("unmask", function() { input