From 75c27c9f148276ac33ddab079b68e12c103c985e Mon Sep 17 00:00:00 2001 From: Simon Timms Date: Fri, 18 Jan 2013 13:15:57 -0800 Subject: [PATCH 01/47] Create jquery.makedinput.nuspec --- dist/jquery.makedinput.nuspec | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 dist/jquery.makedinput.nuspec diff --git a/dist/jquery.makedinput.nuspec b/dist/jquery.makedinput.nuspec new file mode 100644 index 0000000..632c0c4 --- /dev/null +++ b/dist/jquery.makedinput.nuspec @@ -0,0 +1,17 @@ + + + + jQuery.MaskedInput + 1.3.1.0 + digitalBush + stimms + https://github.com/digitalBush/jquery.maskedinput/blob/master/LICENSE + http://digitalbush.com/projects/masked-input-plugin/ + false + A jQuery plugin which applies a mask to input boxes to provide both a UI hint for users as well as some rudimentary input checking. + jQuery,plugins + + + + + From af38d5128e4cd6946f107cbd2d4328bd3e8cd9a9 Mon Sep 17 00:00:00 2001 From: "Shahrukh A. Khan" Date: Thu, 24 Apr 2014 20:01:39 +0500 Subject: [PATCH 02/47] Usage Updated --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac4c6c0..c43c36a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,65 @@ This is a masked input plugin for the jQuery javascript library. It allows a use * 9 - Represents a numeric character (0-9) * \* - Represents an alphanumeric character (A-Z,a-z,0-9) -If your requirements aren't met by the predefined placeholders, you can always add your own. For example, maybe you need a mask to only allow hexadecimal characters. You can add your own definition for a placeholder, say 'h', like so: `$.mask.definitions['h'] = "[A-Fa-f0-9]";` Then you can use that to mask for something like css colors in hex with a mask "#hhhhhh". +### Usage +First, include the jQuery and masked input javascript files. + +```html + + +``` + +Next, call the mask function for those items you wish to have masked. + +```html +jQuery(function($){ + $("#date").mask("99/99/9999"); + $("#phone").mask("(999) 999-9999"); + $("#tin").mask("99-9999999"); + $("#ssn").mask("999-99-9999"); +}); +``` + +Optionally, if you are not satisfied with the underscore ('_') character as a placeholder, you may pass an optional argument to the maskedinput method. + +```html +jQuery(function($){ + $("#product").mask("99/99/9999",{placeholder:" "}); +}); +``` + +Optionally, if you would like to execute a function once the mask has been completed, you can specify that function as an optional argument to the maskedinput method. + +```html +jQuery(function($){ + $("#product").mask("99/99/9999",{completed:function(){alert("You typed the following: "+this.val());}}); +}); +``` + +You can now supply your own mask definitions. +```html +jQuery(function($){ + $.mask.definitions['~']='[+-]'; + $("#eyescript").mask("~9.99 ~9.99 999"); +}); +``` + +You can have part of your mask be optional. Anything listed after '?' within the mask is considered optional user input. The common example for this is phone number + optional extension. + +```html +jQuery(function($){ + $("#phone").mask("(999) 999-9999? x99999"); +}); +``` + +If your requirements aren't met by the predefined placeholders, you can always add your own. For example, maybe you need a mask to only allow hexadecimal characters. You can add your own definition for a placeholder, say 'h', like so: `$.mask.definitions['h'] = "[A-Fa-f0-9]";` Then you can use that to mask for something like css colors in hex with a `mask "#hhhhhh"`. + +```html +jQuery(function($){ + $("#phone").mask("#hhhhhh"); +}); +``` + By design, this plugin will reject input which doesn't complete the mask. You can bypass this by using a '?' character at the position where you would like to consider input optional. For example, a mask of "(999) 999-9999? x99999" would require only the first 10 digits of a phone number with extension being optional. From 15667fed1400c29a2035ba9b0f00a2c95e1c6ace Mon Sep 17 00:00:00 2001 From: zxyang Date: Sun, 24 Aug 2014 14:36:36 -0400 Subject: [PATCH 03/47] Update jquery.maskedinput.js Add support to Android KitKat WebView. 'keypress' event is deprecated, replace with 'input' event if 'keypress' event is not supported. --- src/jquery.maskedinput.js | 731 +++++++++++++++++++------------------- 1 file changed, 365 insertions(+), 366 deletions(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index ad999e3..33c23a2 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -1,374 +1,373 @@ +/* + Masked Input plugin for jQuery + Copyright (c) 2007-2013 Josh Bush (digitalbush.com) + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) + Version: 1.3.1 + */ (function($) { + function getPasteEvent() { + var el = document.createElement('input'), + name = 'onpaste'; + el.setAttribute(name, ''); + return (typeof el[name] === 'function') ? 'paste' : 'input'; + } + + var pasteEventName = getPasteEvent() + ".mask", + ua = navigator.userAgent, + iPhone = /iphone/i.test(ua), + android = /android/i.test(ua), + caretTimeoutId; + + $.mask = { + //Predefined character definitions + definitions: { + '9': "[0-9]", + 'a': "[A-Za-z]", + '*': "[A-Za-z0-9]" + }, + dataName: "rawMaskFn", + placeholder: '_', + }; + + $.fn.extend({ + //Helper Function for Caret positioning + caret: function(begin, end) { + var range; + + if (this.length === 0 || this.is(":hidden")) { + return; + } + + if (typeof begin == 'number') { + end = (typeof end === 'number') ? end : begin; + return this.each(function() { + if (this.setSelectionRange) { + this.setSelectionRange(begin, end); + } else if (this.createTextRange) { + range = this.createTextRange(); + range.collapse(true); + range.moveEnd('character', end); + range.moveStart('character', begin); + range.select(); + } + }); + } else { + if (this[0].setSelectionRange) { + begin = this[0].selectionStart; + end = this[0].selectionEnd; + } else if (document.selection && document.selection.createRange) { + range = document.selection.createRange(); + begin = 0 - range.duplicate().moveStart('character', -100000); + end = begin + range.text.length; + } + return {begin: begin, end: end}; + } + }, + unmask: function() { + return this.trigger("unmask"); + }, + mask: function(mask, settings) { + var input, + defs, + tests, + partialPosition, + firstNonMaskPos, + len, oldVal, bindInputEvent; + + if (!mask && this.length > 0) { + input = $(this[0]); + return input.data($.mask.dataName)(); + } + settings = $.extend({ + placeholder: $.mask.placeholder, // Load default placeholder + completed: null + }, settings); + + + defs = $.mask.definitions; + tests = []; + partialPosition = len = mask.length; + firstNonMaskPos = null; + + $.each(mask.split(""), function(i, c) { + if (c == '?') { + len--; + partialPosition = i; + } else if (defs[c]) { + tests.push(new RegExp(defs[c])); + if (firstNonMaskPos === null) { + firstNonMaskPos = tests.length - 1; + } + } else { + tests.push(null); + } + }); + + return this.trigger("unmask").each(function() { + var input = $(this), + buffer = $.map( + mask.split(""), + function(c, i) { + if (c != '?') { + return defs[c] ? settings.placeholder : c; + } + }), + focusText = input.val(); + + function seekNext(pos) { + while (++pos < len && !tests[pos]) + ; + return pos; + } + + function seekPrev(pos) { + while (--pos >= 0 && !tests[pos]) + ; + return pos; + } + + function shiftL(begin, end) { + var i, + j; + + if (begin < 0) { + return; + } + + for (i = begin, j = seekNext(end); i < len; i++) { + if (tests[i]) { + if (j < len && tests[i].test(buffer[j])) { + buffer[i] = buffer[j]; + buffer[j] = settings.placeholder; + } else { + break; + } -function getPasteEvent() { - var el = document.createElement('input'), - name = 'onpaste'; - el.setAttribute(name, ''); - return (typeof el[name] === 'function')?'paste':'input'; -} - -var pasteEventName = getPasteEvent() + ".mask", - ua = navigator.userAgent, - iPhone = /iphone/i.test(ua), - chrome = /chrome/i.test(ua), - android=/android/i.test(ua), - caretTimeoutId; - -$.mask = { - //Predefined character definitions - definitions: { - '9': "[0-9]", - 'a': "[A-Za-z]", - '*': "[A-Za-z0-9]" - }, - autoclear: true, - dataName: "rawMaskFn", - placeholder: '_' -}; - -$.fn.extend({ - //Helper Function for Caret positioning - caret: function(begin, end) { - var range; - - if (this.length === 0 || this.is(":hidden")) { - return; - } - - if (typeof begin == 'number') { - end = (typeof end === 'number') ? end : begin; - return this.each(function() { - if (this.setSelectionRange) { - this.setSelectionRange(begin, end); - } else if (this.createTextRange) { - range = this.createTextRange(); - range.collapse(true); - range.moveEnd('character', end); - range.moveStart('character', begin); - range.select(); - } - }); - } else { - if (this[0].setSelectionRange) { - begin = this[0].selectionStart; - end = this[0].selectionEnd; - } else if (document.selection && document.selection.createRange) { - range = document.selection.createRange(); - begin = 0 - range.duplicate().moveStart('character', -100000); - end = begin + range.text.length; - } - return { begin: begin, end: end }; - } - }, - unmask: function() { - return this.trigger("unmask"); - }, - mask: function(mask, settings) { - var input, - defs, - tests, - partialPosition, - firstNonMaskPos, - len; - - if (!mask && this.length > 0) { - input = $(this[0]); - return input.data($.mask.dataName)(); - } - settings = $.extend({ - autoclear: $.mask.autoclear, - placeholder: $.mask.placeholder, // Load default placeholder - completed: null - }, settings); - - - defs = $.mask.definitions; - tests = []; - partialPosition = len = mask.length; - firstNonMaskPos = null; - - $.each(mask.split(""), function(i, c) { - if (c == '?') { - len--; - partialPosition = i; - } else if (defs[c]) { - tests.push(new RegExp(defs[c])); - if (firstNonMaskPos === null) { - firstNonMaskPos = tests.length - 1; - } - } else { - tests.push(null); - } - }); - - return this.trigger("unmask").each(function() { - var input = $(this), - buffer = $.map( - mask.split(""), - function(c, i) { - if (c != '?') { - return defs[c] ? settings.placeholder : c; - } - }), - defaultBuffer = buffer.join(''), - focusText = input.val(); - - function seekNext(pos) { - while (++pos < len && !tests[pos]); - return pos; - } - - function seekPrev(pos) { - while (--pos >= 0 && !tests[pos]); - return pos; - } - - function shiftL(begin,end) { - var i, - j; - - if (begin<0) { - return; - } - - for (i = begin, j = seekNext(end); i < len; i++) { - if (tests[i]) { - if (j < len && tests[i].test(buffer[j])) { - buffer[i] = buffer[j]; - buffer[j] = settings.placeholder; - } else { - break; - } - - j = seekNext(j); - } - } - writeBuffer(); - input.caret(Math.max(firstNonMaskPos, begin)); - } - - function shiftR(pos) { - var i, - c, - j, - t; - - for (i = pos, c = settings.placeholder; i < len; i++) { - if (tests[i]) { - j = seekNext(i); - t = buffer[i]; - buffer[i] = c; - if (j < len && tests[j].test(t)) { - c = t; - } else { - break; - } - } - } - } - - function blurEvent(e) { - checkVal(); - - if (input.val() != focusText) - input.change(); - } - - function keydownEvent(e) { - var k = e.which, - pos, - begin, - end; - - //backspace, delete, and escape get special treatment - if (k === 8 || k === 46 || (iPhone && k === 127)) { - pos = input.caret(); - begin = pos.begin; - end = pos.end; - - if (end - begin === 0) { - begin=k!==46?seekPrev(begin):(end=seekNext(begin-1)); - end=k===46?seekNext(end):end; - } - clearBuffer(begin, end); - shiftL(begin, end - 1); - - e.preventDefault(); - } else if( k === 13 ) { // enter - blurEvent.call(this, e); - } else if (k === 27) { // escape - input.val(focusText); - input.caret(0, checkVal()); - e.preventDefault(); - } - } - - function keypressEvent(e) { - var k = e.which, - pos = input.caret(), - p, - c, - next; - - if (k == 0) { - // unable to detect key pressed. Grab it from pos and adjust - // this is a failsafe for mobile chrome - // which can't detect keypress events - // reliably - if (pos.begin >= len) { - input.val(input.val().substr(0, len)); - e.preventDefault(); - return false; + j = seekNext(j); } - if (pos.begin == pos.end) { - k = input.val().charCodeAt(pos.begin - 1); - pos.begin--; - pos.end--; + } + writeBuffer(); + input.caret(Math.max(firstNonMaskPos, begin)); + } + + function shiftR(pos) { + var i, + c, + j, + t; + + for (i = pos, c = settings.placeholder; i < len; i++) { + if (tests[i]) { + j = seekNext(i); + t = buffer[i]; + buffer[i] = c; + if (j < len && tests[j].test(t)) { + c = t; + } else { + break; + } } } + } - if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore - return; - } else if ( k && k !== 13 ) { - if (pos.end - pos.begin !== 0){ - clearBuffer(pos.begin, pos.end); - shiftL(pos.begin, pos.end-1); - } - - p = seekNext(pos.begin - 1); - if (p < len) { - c = String.fromCharCode(k); - if (tests[p].test(c)) { - shiftR(p); - - buffer[p] = c; - writeBuffer(); - next = seekNext(p); - - if(android){ - //Path for CSP Violation on FireFox OS 1.1 - var proxy = function() { - $.proxy($.fn.caret,input,next)(); - }; - - setTimeout(proxy,0); - }else{ - input.caret(next); - } - - if (settings.completed && next >= len) { - settings.completed.call(input); - } - } - } - e.preventDefault(); - } - } - - function clearBuffer(start, end) { - var i; - for (i = start; i < end && i < len; i++) { - if (tests[i]) { - buffer[i] = settings.placeholder; - } - } - } - - function writeBuffer() { input.val(buffer.join('')); } - - function checkVal(allow) { - //try to place characters where they belong - var test = input.val(), - lastMatch = -1, - i, - c, - pos; - - for (i = 0, pos = 0; i < len; i++) { - if (tests[i]) { - buffer[i] = settings.placeholder; - while (pos++ < test.length) { - c = test.charAt(pos - 1); - if (tests[i].test(c)) { - buffer[i] = c; - lastMatch = i; - break; - } - } - if (pos > test.length) { - break; - } - } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { - pos++; - lastMatch = i; - } - } - if (allow) { - writeBuffer(); - } else if (lastMatch + 1 < partialPosition) { - if (settings.autoclear || buffer.join('') === defaultBuffer) { - // Invalid value. Remove it and replace it with the - // mask, which is the default behavior. - if(input.val()) input.val(""); - clearBuffer(0, len); - } else { - // Invalid value, but we opt to show the value to the - // user and allow them to correct their mistake. - writeBuffer(); - } - } else { - writeBuffer(); - input.val(input.val().substring(0, lastMatch + 1)); - } - return (partialPosition ? i : firstNonMaskPos); - } - - input.data($.mask.dataName,function(){ - return $.map(buffer, function(c, i) { - return tests[i]&&c!=settings.placeholder ? c : null; - }).join(''); - }); - - if (!input.attr("readonly")) - input - .one("unmask", function() { - input - .off(".mask") - .removeData($.mask.dataName); - }) - .on("focus.mask", function() { - clearTimeout(caretTimeoutId); - var pos; - - focusText = input.val(); - - pos = checkVal(); - - caretTimeoutId = setTimeout(function(){ - writeBuffer(); - if (pos == mask.replace("?","").length) { - input.caret(0, pos); - } else { - input.caret(pos); - } - }, 10); - }) - .on("blur.mask", blurEvent) - .on("keydown.mask", keydownEvent) - .on("keypress.mask", keypressEvent) - .on(pasteEventName, function() { - setTimeout(function() { - var pos=checkVal(true); - input.caret(pos); - if (settings.completed && pos == input.val().length) - settings.completed.call(input); - }, 0); - }); - if (chrome && android) { - input.on("keyup.mask", keypressEvent); + function inputEvent(e) { + var curVal = input.val(); + var pos = input.caret(); + if (curVal.length < oldVal.length) { + // a deletion or backspace happened + checkVal(true); + pos.begin = seekPrev(pos.begin + 1); + input.caret(pos.begin, pos.begin); + } else { + pos = checkVal(true); + input.caret(pos); + } + if (settings.completed && pos == input.val().length) + settings.completed.call(input); } - checkVal(); //Perform initial check for existing values - }); - } -}); + + function keydownEvent(e) { + var k = e.which, + pos, + begin, + end; + oldVal = input.val(); + //backspace, delete, and escape get special treatment + if (k === 8 || k === 46 || (iPhone && k === 127)) { + pos = input.caret(); + begin = pos.begin; + end = pos.end; + + if (end - begin === 0) { + begin = k !== 46 ? seekPrev(begin) : (end = seekNext(begin - 1)); + end = k === 46 ? seekNext(end) : end; + } + clearBuffer(begin, end); + shiftL(begin, end - 1); + + e.preventDefault(); + } else if (k == 27) {//escape + input.val(focusText); + input.caret(0, checkVal()); + e.preventDefault(); + } + } + + function keypressEvent(e) { + + if (bindInputEvent) + { + bindInputEvent = false; + input.unbind('input.mask'); + } + ; + var k = e.which, + pos = input.caret(), + p, + c, + next; + + if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore + return; + } else if (k) { + if (pos.end - pos.begin !== 0) { + clearBuffer(pos.begin, pos.end); + shiftL(pos.begin, pos.end - 1); + } + + p = seekNext(pos.begin - 1); + if (p < len) { + c = String.fromCharCode(k); + if (tests[p].test(c)) { + shiftR(p); + + buffer[p] = c; + writeBuffer(); + next = seekNext(p); + + if (android) { + setTimeout($.proxy($.fn.caret, input, next), 0); + } else { + input.caret(next); + } + + if (settings.completed && next >= len) { + settings.completed.call(input); + } + } + } + e.preventDefault(); + } + } + + function clearBuffer(start, end) { + var i; + for (i = start; i < end && i < len; i++) { + if (tests[i]) { + buffer[i] = settings.placeholder; + } + } + } + + function writeBuffer() { + input.val(buffer.join('')); + } + + function checkVal(allow) { + //try to place characters where they belong + var test = input.val(), + lastMatch = -1, + i, + c; + + for (i = 0, pos = 0; i < len; i++) { + if (tests[i]) { + buffer[i] = settings.placeholder; + while (pos++ < test.length) { + c = test.charAt(pos - 1); + if (tests[i].test(c)) { + buffer[i] = c; + lastMatch = i; + break; + } + } + if (pos > test.length) { + break; + } + } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { + pos++; + lastMatch = i; + } + } + if (allow) { + writeBuffer(); + } else if (lastMatch + 1 < partialPosition) { + input.val(""); + clearBuffer(0, len); + } else { + writeBuffer(); + input.val(input.val().substring(0, lastMatch + 1)); + } + return (partialPosition ? i : firstNonMaskPos); + } + + input.data($.mask.dataName, function() { + return $.map(buffer, function(c, i) { + return tests[i] && c != settings.placeholder ? c : null; + }).join(''); + }); + + if (!input.attr("readonly")) + input + .one("unmask", function() { + input + .unbind(".mask") + .removeData($.mask.dataName); + }) + .bind("focus.mask", function() { + clearTimeout(caretTimeoutId); + var pos, + moveCaret; + + focusText = input.val(); + pos = checkVal(); + + caretTimeoutId = setTimeout(function() { + writeBuffer(); + if (pos == mask.length) { + input.caret(0, pos); + } else { + input.caret(pos); + } + }, 10); + }) + .bind("blur.mask", function() { + checkVal(); + if (input.val() != focusText) + input.change(); + }) + .bind("keydown.mask", keydownEvent) + .bind("keypress.mask", keypressEvent) + .bind(pasteEventName, function() { + setTimeout(function() { + var pos = checkVal(true); + input.caret(pos); + if (settings.completed && pos == input.val().length) + settings.completed.call(input); + }, 0); + }); + if (android) // bind with input event + { + bindInputEvent = true; + input.bind('input.mask', inputEvent); + } else + { + bindInputEvent = false; + } + checkVal(); //Perform initial check for existing values + }); + } + }); + + })(jQuery); From 482b0a6b02adeabcd6d0cc633596411120c819e4 Mon Sep 17 00:00:00 2001 From: zxyang Date: Sun, 24 Aug 2014 16:13:10 -0400 Subject: [PATCH 04/47] Update jquery.maskedinput.js fix caret positions --- src/jquery.maskedinput.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 33c23a2..c4eef73 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -176,11 +176,20 @@ if (curVal.length < oldVal.length) { // a deletion or backspace happened checkVal(true); - pos.begin = seekPrev(pos.begin + 1); - input.caret(pos.begin, pos.begin); + while (pos.begin > 0 && !tests[pos.begin-1]) + pos.begin--; + if (pos.begin === 0) + { + while (pos.begin < firstNonMaskPos && !tests[pos.begin]) + pos.begin++; + } + input.caret(pos.begin,pos.begin); } else { - pos = checkVal(true); - input.caret(pos); + var pos2 = checkVal(true); + while (pos.begin < len && !tests[pos.begin]) + pos.begin++; + + input.caret(pos.begin,pos.begin); } if (settings.completed && pos == input.val().length) settings.completed.call(input); From bf7f7afd91956af4972f144f3aa93d02ecd1134b Mon Sep 17 00:00:00 2001 From: zxyang Date: Sun, 24 Aug 2014 16:22:45 -0400 Subject: [PATCH 05/47] Update jquery.maskedinput.js From 2d79c1b4601f0f1fc8ad3d99277c6f09e62128cd Mon Sep 17 00:00:00 2001 From: zxyang Date: Sun, 24 Aug 2014 16:54:28 -0400 Subject: [PATCH 06/47] Update jquery.maskedinput.js Merged with the latest on the main project. --- src/jquery.maskedinput.js | 700 ++++++++++++++++++++------------------ 1 file changed, 363 insertions(+), 337 deletions(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index c4eef73..5117780 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -1,175 +1,171 @@ -/* - Masked Input plugin for jQuery - Copyright (c) 2007-2013 Josh Bush (digitalbush.com) - Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) - Version: 1.3.1 - */ (function($) { - function getPasteEvent() { - var el = document.createElement('input'), - name = 'onpaste'; - el.setAttribute(name, ''); - return (typeof el[name] === 'function') ? 'paste' : 'input'; - } - - var pasteEventName = getPasteEvent() + ".mask", - ua = navigator.userAgent, - iPhone = /iphone/i.test(ua), - android = /android/i.test(ua), - caretTimeoutId; - - $.mask = { - //Predefined character definitions - definitions: { - '9': "[0-9]", - 'a': "[A-Za-z]", - '*': "[A-Za-z0-9]" - }, - dataName: "rawMaskFn", - placeholder: '_', - }; - - $.fn.extend({ - //Helper Function for Caret positioning - caret: function(begin, end) { - var range; - - if (this.length === 0 || this.is(":hidden")) { - return; - } - - if (typeof begin == 'number') { - end = (typeof end === 'number') ? end : begin; - return this.each(function() { - if (this.setSelectionRange) { - this.setSelectionRange(begin, end); - } else if (this.createTextRange) { - range = this.createTextRange(); - range.collapse(true); - range.moveEnd('character', end); - range.moveStart('character', begin); - range.select(); - } - }); - } else { - if (this[0].setSelectionRange) { - begin = this[0].selectionStart; - end = this[0].selectionEnd; - } else if (document.selection && document.selection.createRange) { - range = document.selection.createRange(); - begin = 0 - range.duplicate().moveStart('character', -100000); - end = begin + range.text.length; - } - return {begin: begin, end: end}; - } - }, - unmask: function() { - return this.trigger("unmask"); - }, - mask: function(mask, settings) { - var input, - defs, - tests, - partialPosition, - firstNonMaskPos, - len, oldVal, bindInputEvent; - - if (!mask && this.length > 0) { - input = $(this[0]); - return input.data($.mask.dataName)(); - } - settings = $.extend({ - placeholder: $.mask.placeholder, // Load default placeholder - completed: null - }, settings); - - - defs = $.mask.definitions; - tests = []; - partialPosition = len = mask.length; - firstNonMaskPos = null; - - $.each(mask.split(""), function(i, c) { - if (c == '?') { - len--; - partialPosition = i; - } else if (defs[c]) { - tests.push(new RegExp(defs[c])); - if (firstNonMaskPos === null) { - firstNonMaskPos = tests.length - 1; - } - } else { - tests.push(null); - } - }); - - return this.trigger("unmask").each(function() { - var input = $(this), - buffer = $.map( - mask.split(""), - function(c, i) { - if (c != '?') { - return defs[c] ? settings.placeholder : c; - } - }), - focusText = input.val(); - - function seekNext(pos) { - while (++pos < len && !tests[pos]) - ; - return pos; - } - - function seekPrev(pos) { - while (--pos >= 0 && !tests[pos]) - ; - return pos; - } - - function shiftL(begin, end) { - var i, - j; - - if (begin < 0) { - return; - } - - for (i = begin, j = seekNext(end); i < len; i++) { - if (tests[i]) { - if (j < len && tests[i].test(buffer[j])) { - buffer[i] = buffer[j]; - buffer[j] = settings.placeholder; - } else { - break; - } - - j = seekNext(j); - } - } - writeBuffer(); - input.caret(Math.max(firstNonMaskPos, begin)); - } - function shiftR(pos) { - var i, - c, - j, - t; - - for (i = pos, c = settings.placeholder; i < len; i++) { - if (tests[i]) { - j = seekNext(i); - t = buffer[i]; - buffer[i] = c; - if (j < len && tests[j].test(t)) { - c = t; - } else { - break; - } - } - } - } +function getPasteEvent() { + var el = document.createElement('input'), + name = 'onpaste'; + el.setAttribute(name, ''); + return (typeof el[name] === 'function')?'paste':'input'; +} + +var pasteEventName = getPasteEvent() + ".mask", + ua = navigator.userAgent, + iPhone = /iphone/i.test(ua), + chrome = /chrome/i.test(ua), + android=/android/i.test(ua), + caretTimeoutId; + +$.mask = { + //Predefined character definitions + definitions: { + '9': "[0-9]", + 'a': "[A-Za-z]", + '*': "[A-Za-z0-9]" + }, + autoclear: true, + dataName: "rawMaskFn", + placeholder: '_' +}; + +$.fn.extend({ + //Helper Function for Caret positioning + caret: function(begin, end) { + var range; + + if (this.length === 0 || this.is(":hidden")) { + return; + } + + if (typeof begin == 'number') { + end = (typeof end === 'number') ? end : begin; + return this.each(function() { + if (this.setSelectionRange) { + this.setSelectionRange(begin, end); + } else if (this.createTextRange) { + range = this.createTextRange(); + range.collapse(true); + range.moveEnd('character', end); + range.moveStart('character', begin); + range.select(); + } + }); + } else { + if (this[0].setSelectionRange) { + begin = this[0].selectionStart; + end = this[0].selectionEnd; + } else if (document.selection && document.selection.createRange) { + range = document.selection.createRange(); + begin = 0 - range.duplicate().moveStart('character', -100000); + end = begin + range.text.length; + } + return { begin: begin, end: end }; + } + }, + unmask: function() { + return this.trigger("unmask"); + }, + mask: function(mask, settings) { + var input, + defs, + tests, + partialPosition, + firstNonMaskPos, + len, oldVal, bindInputEvent; + if (!mask && this.length > 0) { + input = $(this[0]); + return input.data($.mask.dataName)(); + } + settings = $.extend({ + autoclear: $.mask.autoclear, + placeholder: $.mask.placeholder, // Load default placeholder + completed: null + }, settings); + + + defs = $.mask.definitions; + tests = []; + partialPosition = len = mask.length; + firstNonMaskPos = null; + + $.each(mask.split(""), function(i, c) { + if (c == '?') { + len--; + partialPosition = i; + } else if (defs[c]) { + tests.push(new RegExp(defs[c])); + if (firstNonMaskPos === null) { + firstNonMaskPos = tests.length - 1; + } + } else { + tests.push(null); + } + }); + + return this.trigger("unmask").each(function() { + var input = $(this), + buffer = $.map( + mask.split(""), + function(c, i) { + if (c != '?') { + return defs[c] ? settings.placeholder : c; + } + }), + defaultBuffer = buffer.join(''), + focusText = input.val(); + + function seekNext(pos) { + while (++pos < len && !tests[pos]); + return pos; + } + + function seekPrev(pos) { + while (--pos >= 0 && !tests[pos]); + return pos; + } + + function shiftL(begin,end) { + var i, + j; + + if (begin<0) { + return; + } + + for (i = begin, j = seekNext(end); i < len; i++) { + if (tests[i]) { + if (j < len && tests[i].test(buffer[j])) { + buffer[i] = buffer[j]; + buffer[j] = settings.placeholder; + } else { + break; + } + + j = seekNext(j); + } + } + writeBuffer(); + input.caret(Math.max(firstNonMaskPos, begin)); + } + + function shiftR(pos) { + var i, + c, + j, + t; + + for (i = pos, c = settings.placeholder; i < len; i++) { + if (tests[i]) { + j = seekNext(i); + t = buffer[i]; + buffer[i] = c; + if (j < len && tests[j].test(t)) { + c = t; + } else { + break; + } + } + } + } function inputEvent(e) { var curVal = input.val(); var pos = input.caret(); @@ -194,178 +190,210 @@ if (settings.completed && pos == input.val().length) settings.completed.call(input); } - - function keydownEvent(e) { - var k = e.which, - pos, - begin, - end; + function blurEvent(e) { + checkVal(); + + if (input.val() != focusText) + input.change(); + } + + function keydownEvent(e) { + var k = e.which, + pos, + begin, + end; oldVal = input.val(); - //backspace, delete, and escape get special treatment - if (k === 8 || k === 46 || (iPhone && k === 127)) { - pos = input.caret(); - begin = pos.begin; - end = pos.end; - - if (end - begin === 0) { - begin = k !== 46 ? seekPrev(begin) : (end = seekNext(begin - 1)); - end = k === 46 ? seekNext(end) : end; - } - clearBuffer(begin, end); - shiftL(begin, end - 1); - - e.preventDefault(); - } else if (k == 27) {//escape - input.val(focusText); - input.caret(0, checkVal()); - e.preventDefault(); - } - } - - function keypressEvent(e) { - + //backspace, delete, and escape get special treatment + if (k === 8 || k === 46 || (iPhone && k === 127)) { + pos = input.caret(); + begin = pos.begin; + end = pos.end; + + if (end - begin === 0) { + begin=k!==46?seekPrev(begin):(end=seekNext(begin-1)); + end=k===46?seekNext(end):end; + } + clearBuffer(begin, end); + shiftL(begin, end - 1); + + e.preventDefault(); + } else if( k === 13 ) { // enter + blurEvent.call(this, e); + } else if (k === 27) { // escape + input.val(focusText); + input.caret(0, checkVal()); + e.preventDefault(); + } + } + + function keypressEvent(e) { if (bindInputEvent) { bindInputEvent = false; - input.unbind('input.mask'); + input.off('input.mask'); } ; - var k = e.which, - pos = input.caret(), - p, - c, - next; - - if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore - return; - } else if (k) { - if (pos.end - pos.begin !== 0) { - clearBuffer(pos.begin, pos.end); - shiftL(pos.begin, pos.end - 1); + var k = e.which, + pos = input.caret(), + p, + c, + next; + + if (k == 0) { + // unable to detect key pressed. Grab it from pos and adjust + // this is a failsafe for mobile chrome + // which can't detect keypress events + // reliably + if (pos.begin >= len) { + input.val(input.val().substr(0, len)); + e.preventDefault(); + return false; } - - p = seekNext(pos.begin - 1); - if (p < len) { - c = String.fromCharCode(k); - if (tests[p].test(c)) { - shiftR(p); - - buffer[p] = c; - writeBuffer(); - next = seekNext(p); - - if (android) { - setTimeout($.proxy($.fn.caret, input, next), 0); - } else { - input.caret(next); - } - - if (settings.completed && next >= len) { - settings.completed.call(input); - } - } + if (pos.begin == pos.end) { + k = input.val().charCodeAt(pos.begin - 1); + pos.begin--; + pos.end--; } - e.preventDefault(); } - } - - function clearBuffer(start, end) { - var i; - for (i = start; i < end && i < len; i++) { - if (tests[i]) { - buffer[i] = settings.placeholder; - } - } - } - function writeBuffer() { - input.val(buffer.join('')); - } - - function checkVal(allow) { - //try to place characters where they belong - var test = input.val(), - lastMatch = -1, - i, - c; - - for (i = 0, pos = 0; i < len; i++) { - if (tests[i]) { - buffer[i] = settings.placeholder; - while (pos++ < test.length) { - c = test.charAt(pos - 1); - if (tests[i].test(c)) { - buffer[i] = c; - lastMatch = i; - break; - } - } - if (pos > test.length) { - break; - } - } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { - pos++; - lastMatch = i; - } - } - if (allow) { - writeBuffer(); - } else if (lastMatch + 1 < partialPosition) { - input.val(""); - clearBuffer(0, len); - } else { - writeBuffer(); - input.val(input.val().substring(0, lastMatch + 1)); - } - return (partialPosition ? i : firstNonMaskPos); - } - - input.data($.mask.dataName, function() { - return $.map(buffer, function(c, i) { - return tests[i] && c != settings.placeholder ? c : null; - }).join(''); - }); - - if (!input.attr("readonly")) - input - .one("unmask", function() { - input - .unbind(".mask") - .removeData($.mask.dataName); - }) - .bind("focus.mask", function() { - clearTimeout(caretTimeoutId); - var pos, - moveCaret; - - focusText = input.val(); - pos = checkVal(); - - caretTimeoutId = setTimeout(function() { - writeBuffer(); - if (pos == mask.length) { - input.caret(0, pos); - } else { - input.caret(pos); - } - }, 10); - }) - .bind("blur.mask", function() { - checkVal(); - if (input.val() != focusText) - input.change(); - }) - .bind("keydown.mask", keydownEvent) - .bind("keypress.mask", keypressEvent) - .bind(pasteEventName, function() { - setTimeout(function() { - var pos = checkVal(true); - input.caret(pos); - if (settings.completed && pos == input.val().length) - settings.completed.call(input); - }, 0); - }); - if (android) // bind with input event + if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore + return; + } else if ( k && k !== 13 ) { + if (pos.end - pos.begin !== 0){ + clearBuffer(pos.begin, pos.end); + shiftL(pos.begin, pos.end-1); + } + + p = seekNext(pos.begin - 1); + if (p < len) { + c = String.fromCharCode(k); + if (tests[p].test(c)) { + shiftR(p); + + buffer[p] = c; + writeBuffer(); + next = seekNext(p); + + if(android){ + //Path for CSP Violation on FireFox OS 1.1 + var proxy = function() { + $.proxy($.fn.caret,input,next)(); + }; + + setTimeout(proxy,0); + }else{ + input.caret(next); + } + + if (settings.completed && next >= len) { + settings.completed.call(input); + } + } + } + e.preventDefault(); + } + } + + function clearBuffer(start, end) { + var i; + for (i = start; i < end && i < len; i++) { + if (tests[i]) { + buffer[i] = settings.placeholder; + } + } + } + + function writeBuffer() { input.val(buffer.join('')); } + + function checkVal(allow) { + //try to place characters where they belong + var test = input.val(), + lastMatch = -1, + i, + c, + pos; + + for (i = 0, pos = 0; i < len; i++) { + if (tests[i]) { + buffer[i] = settings.placeholder; + while (pos++ < test.length) { + c = test.charAt(pos - 1); + if (tests[i].test(c)) { + buffer[i] = c; + lastMatch = i; + break; + } + } + if (pos > test.length) { + break; + } + } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { + pos++; + lastMatch = i; + } + } + if (allow) { + writeBuffer(); + } else if (lastMatch + 1 < partialPosition) { + if (settings.autoclear || buffer.join('') === defaultBuffer) { + // Invalid value. Remove it and replace it with the + // mask, which is the default behavior. + if(input.val()) input.val(""); + clearBuffer(0, len); + } else { + // Invalid value, but we opt to show the value to the + // user and allow them to correct their mistake. + writeBuffer(); + } + } else { + writeBuffer(); + input.val(input.val().substring(0, lastMatch + 1)); + } + return (partialPosition ? i : firstNonMaskPos); + } + + input.data($.mask.dataName,function(){ + return $.map(buffer, function(c, i) { + return tests[i]&&c!=settings.placeholder ? c : null; + }).join(''); + }); + + if (!input.attr("readonly")) + input + .one("unmask", function() { + input + .off(".mask") + .removeData($.mask.dataName); + }) + .on("focus.mask", function() { + clearTimeout(caretTimeoutId); + var pos; + + focusText = input.val(); + + pos = checkVal(); + + caretTimeoutId = setTimeout(function(){ + writeBuffer(); + if (pos == mask.replace("?","").length) { + input.caret(0, pos); + } else { + input.caret(pos); + } + }, 10); + }) + .on("blur.mask", blurEvent) + .on("keydown.mask", keydownEvent) + .on("keypress.mask", keypressEvent) + .on(pasteEventName, function() { + setTimeout(function() { + var pos=checkVal(true); + input.caret(pos); + if (settings.completed && pos == input.val().length) + settings.completed.call(input); + }, 0); + }); + if (chrome && android) // bind with input event { bindInputEvent = true; input.bind('input.mask', inputEvent); @@ -373,10 +401,8 @@ { bindInputEvent = false; } - checkVal(); //Perform initial check for existing values - }); - } - }); - - + checkVal(); //Perform initial check for existing values + }); + } +}); })(jQuery); From adecd78d322773c845a77e2ba2addd279dad5467 Mon Sep 17 00:00:00 2001 From: Mohnish Thallavajhula Date: Mon, 25 Aug 2014 11:22:58 -0700 Subject: [PATCH 07/47] :heart: 2014 --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 8f4ccae..d66f9f9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2007-2013 Josh Bush (digitalbush.com) +Copyright (c) 2007-2014 Josh Bush (digitalbush.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +OTHER DEALINGS IN THE SOFTWARE. From c836559765d2334064daae3ebe18291dbaa136df Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sun, 28 Sep 2014 21:30:35 -0500 Subject: [PATCH 08/47] Bit of cleanup for #245 --- dist/jquery.maskedinput.js | 60 +++++++++++++++++++--------- dist/jquery.maskedinput.min.js | 4 +- src/jquery.maskedinput.js | 73 ++++++++++++++++------------------ 3 files changed, 77 insertions(+), 60 deletions(-) diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index 65ead0f..e0eeeb4 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -1,6 +1,6 @@ /* jQuery Masked Input Plugin - Copyright (c) 2007 - 2013 Josh Bush (digitalbush.com) + Copyright (c) 2007 - 2014 Josh Bush (digitalbush.com) Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ @@ -38,7 +38,7 @@ return this.trigger("unmask"); }, mask: function(mask, settings) { - var input, defs, tests, partialPosition, firstNonMaskPos, len; + var input, defs, tests, partialPosition, firstNonMaskPos, len, oldVal; return !mask && this.length > 0 ? (input = $(this[0]), input.data($.mask.dataName)()) : (settings = $.extend({ autoclear: $.mask.autoclear, placeholder: $.mask.placeholder, @@ -73,13 +73,28 @@ c = t; } } + function androidInputEvent() { + var curVal = input.val(), pos = input.caret(); + if (curVal.length < oldVal.length) { + for (checkVal(!0); pos.begin > 0 && !tests[pos.begin - 1]; ) pos.begin--; + if (0 === pos.begin) for (;pos.begin < firstNonMaskPos && !tests[pos.begin]; ) pos.begin++; + input.caret(pos.begin, pos.begin); + } else { + for (checkVal(!0); pos.begin < len && !tests[pos.begin]; ) pos.begin++; + input.caret(pos.begin, pos.begin); + } + settings.completed && pos == input.val().length && settings.completed.call(input); + } + function blurEvent() { + checkVal(), input.val() != focusText && input.change(); + } function keydownEvent(e) { var pos, begin, end, k = e.which; - 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(), begin = pos.begin, - end = pos.end, 0 === end - begin && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1), + oldVal = input.val(), 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(), + begin = pos.begin, end = pos.end, end - begin === 0 && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1), end = 46 === k ? seekNext(end) : end), clearBuffer(begin, end), shiftL(begin, end - 1), - e.preventDefault()) : 27 == k && (input.val(focusText), input.caret(0, checkVal()), - e.preventDefault()); + e.preventDefault()) : 13 === k ? blurEvent.call(this, e) : 27 === k && (input.val(focusText), + input.caret(0, checkVal()), e.preventDefault()); } function keypressEvent(e) { var p, c, next, k = e.which, pos = input.caret(); @@ -89,11 +104,19 @@ pos.begin == pos.end && (k = input.val().charCodeAt(pos.begin - 1), pos.begin--, pos.end--); } - e.ctrlKey || e.altKey || e.metaKey || 32 > k || k && (0 !== pos.end - pos.begin && (clearBuffer(pos.begin, pos.end), - shiftL(pos.begin, pos.end - 1)), p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), - tests[p].test(c) && (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), - android ? setTimeout($.proxy($.fn.caret, input, next), 0) : input.caret(next), settings.completed && next >= len && settings.completed.call(input))), - e.preventDefault()); + if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) { + if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)), + p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) { + if (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), android) { + var proxy = function() { + $.proxy($.fn.caret, input, next)(); + }; + setTimeout(proxy, 0); + } else input.caret(next); + settings.completed && next >= len && settings.completed.call(input); + } + e.preventDefault(); + } } function clearBuffer(start, end) { var i; @@ -112,7 +135,7 @@ } if (pos > test.length) break; } else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, lastMatch = i); - return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val(""), + return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""), clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))), partialPosition ? i : firstNonMaskPos; } @@ -124,21 +147,20 @@ return tests[i] && c != settings.placeholder ? c : null; }).join(""); }), input.attr("readonly") || input.one("unmask", function() { - input.unbind(".mask").removeData($.mask.dataName); - }).bind("focus.mask", function() { + input.off(".mask").removeData($.mask.dataName); + }).on("focus.mask", function() { clearTimeout(caretTimeoutId); var pos; focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() { - writeBuffer(), pos == mask.length ? input.caret(0, pos) : input.caret(pos); + writeBuffer(), pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos); }, 10); - }).bind("blur.mask", function() { - checkVal(), input.val() != focusText && input.change(); - }).bind("keydown.mask", keydownEvent).bind("keypress.mask", keypressEvent).bind(pasteEventName, function() { + }).on("blur.mask", blurEvent).on("keydown.mask", keydownEvent).on("keypress.mask", keypressEvent).on(pasteEventName, function() { setTimeout(function() { var pos = checkVal(!0); input.caret(pos), settings.completed && pos == input.val().length && settings.completed.call(input); }, 0); - }), chrome && android && input.bind("keyup.mask", keypressEvent), checkVal(); + }), chrome && android && input.off("input.mask").on("input.mask", androidInputEvent), + checkVal(); })); } }); diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index ff8a5e5..67889ad 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -1,7 +1,7 @@ /* jQuery Masked Input Plugin - Copyright (c) 2007 - 2013 Josh Bush (digitalbush.com) + Copyright (c) 2007 - 2014 Josh Bush (digitalbush.com) Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=n=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(n--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(a){for(;++a=0&&!k[a];);return a}function p(a,b){var c,d;if(!(0>a)){for(c=a,d=i(b);n>c;c++)if(k[c]){if(!(n>d&&k[c].test(x[d])))break;x[c]=x[d],x[d]=e.placeholder,d=i(d)}u(),w.caret(Math.max(m,a))}}function q(a){var b,c,d,f;for(b=a,c=e.placeholder;n>b;b++)if(k[b]){if(d=i(b),f=x[b],x[b]=c,!(n>d&&k[d].test(f)))break;c=f}}function r(a){var b,c,d,e=a.which;8===e||46===e||f&&127===e?(b=w.caret(),c=b.begin,d=b.end,0===d-c&&(c=46!==e?o(c):d=i(c-1),d=46===e?i(d):d),t(c,d),p(c,d-1),a.preventDefault()):27==e&&(w.val(z),w.caret(0,v()),a.preventDefault())}function s(b){var c,d,f,g=b.which,j=w.caret();if(0==g){if(j.begin>=n)return w.val(w.val().substr(0,n)),b.preventDefault(),!1;j.begin==j.end&&(g=w.val().charCodeAt(j.begin-1),j.begin--,j.end--)}b.ctrlKey||b.altKey||b.metaKey||32>g||g&&(0!==j.end-j.begin&&(t(j.begin,j.end),p(j.begin,j.end-1)),c=i(j.begin-1),n>c&&(d=String.fromCharCode(g),k[c].test(d)&&(q(c),x[c]=d,u(),f=i(c),h?setTimeout(a.proxy(a.fn.caret,w,f),0):w.caret(f),e.completed&&f>=n&&e.completed.call(w))),b.preventDefault())}function t(a,b){var c;for(c=a;b>c&&n>c;c++)k[c]&&(x[c]=e.placeholder)}function u(){w.val(x.join(""))}function v(a){var b,c,d,f=w.val(),g=-1;for(b=0,d=0;n>b;b++)if(k[b]){for(x[b]=e.placeholder;d++f.length)break}else x[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?u():l>g+1?e.autoclear||x.join("")===y?(w.val(""),t(0,n)):u():(u(),w.val(w.val().substring(0,g+1))),l?b:m}var w=a(this),x=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),y=x.join(""),z=w.val();w.data(a.mask.dataName,function(){return a.map(x,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),w.attr("readonly")||w.one("unmask",function(){w.unbind(".mask").removeData(a.mask.dataName)}).bind("focus.mask",function(){clearTimeout(c);var a;z=w.val(),a=v(),c=setTimeout(function(){u(),a==b.length?w.caret(0,a):w.caret(a)},10)}).bind("blur.mask",function(){v(),w.val()!=z&&w.change()}).bind("keydown.mask",r).bind("keypress.mask",s).bind(d,function(){setTimeout(function(){var a=v(!0);w.caret(a),e.completed&&a==w.val().length&&e.completed.call(w)},0)}),g&&h&&w.bind("keyup.mask",s),v()}))}})}(jQuery); \ No newline at end of file +!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=n=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(n--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(a){for(;++a=0&&!k[a];);return a}function q(a,b){var c,d;if(!(0>a)){for(c=a,d=i(b);n>c;c++)if(k[c]){if(!(n>d&&k[c].test(A[d])))break;A[c]=A[d],A[d]=e.placeholder,d=i(d)}x(),z.caret(Math.max(m,a))}}function r(a){var b,c,d,f;for(b=a,c=e.placeholder;n>b;b++)if(k[b]){if(d=i(b),f=A[b],A[b]=c,!(n>d&&k[d].test(f)))break;c=f}}function s(){var a=z.val(),b=z.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.begin=n)return z.val(z.val().substr(0,n)),b.preventDefault(),!1;j.begin==j.end&&(g=z.val().charCodeAt(j.begin-1),j.begin--,j.end--)}if(!(b.ctrlKey||b.altKey||b.metaKey||32>g)&&g&&13!==g){if(j.end-j.begin!==0&&(w(j.begin,j.end),q(j.begin,j.end-1)),c=i(j.begin-1),n>c&&(d=String.fromCharCode(g),k[c].test(d))){if(r(c),A[c]=d,x(),f=i(c),h){var l=function(){a.proxy(a.fn.caret,z,f)()};setTimeout(l,0)}else z.caret(f);e.completed&&f>=n&&e.completed.call(z)}b.preventDefault()}}function w(a,b){var c;for(c=a;b>c&&n>c;c++)k[c]&&(A[c]=e.placeholder)}function x(){z.val(A.join(""))}function y(a){var b,c,d,f=z.val(),g=-1;for(b=0,d=0;n>b;b++)if(k[b]){for(A[b]=e.placeholder;d++f.length)break}else A[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?x():l>g+1?e.autoclear||A.join("")===B?(z.val()&&z.val(""),w(0,n)):x():(x(),z.val(z.val().substring(0,g+1))),l?b:m}var z=a(this),A=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),B=A.join(""),C=z.val();z.data(a.mask.dataName,function(){return a.map(A,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),z.attr("readonly")||z.one("unmask",function(){z.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;C=z.val(),a=y(),c=setTimeout(function(){x(),a==b.replace("?","").length?z.caret(0,a):z.caret(a)},10)}).on("blur.mask",t).on("keydown.mask",u).on("keypress.mask",v).on(d,function(){setTimeout(function(){var a=y(!0);z.caret(a),e.completed&&a==z.val().length&&e.completed.call(z)},0)}),g&&h&&z.off("input.mask").on("input.mask",s),y()}))}})}(jQuery); \ No newline at end of file diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 5117780..d2d10d7 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -69,7 +69,8 @@ $.fn.extend({ tests, partialPosition, firstNonMaskPos, - len, oldVal, bindInputEvent; + len, + oldVal; if (!mask && this.length > 0) { input = $(this[0]); @@ -166,36 +167,38 @@ $.fn.extend({ } } } - function inputEvent(e) { - var curVal = input.val(); - var pos = input.caret(); - if (curVal.length < oldVal.length) { - // a deletion or backspace happened - checkVal(true); - while (pos.begin > 0 && !tests[pos.begin-1]) - pos.begin--; - if (pos.begin === 0) - { - while (pos.begin < firstNonMaskPos && !tests[pos.begin]) - pos.begin++; - } - input.caret(pos.begin,pos.begin); - } else { - var pos2 = checkVal(true); - while (pos.begin < len && !tests[pos.begin]) - pos.begin++; - input.caret(pos.begin,pos.begin); + function androidInputEvent(e) { + var curVal = input.val(); + var pos = input.caret(); + if (curVal.length < oldVal.length) { + // a deletion or backspace happened + checkVal(true); + while (pos.begin > 0 && !tests[pos.begin-1]) + pos.begin--; + if (pos.begin === 0) + { + while (pos.begin < firstNonMaskPos && !tests[pos.begin]) + pos.begin++; } - if (settings.completed && pos == input.val().length) - settings.completed.call(input); + input.caret(pos.begin,pos.begin); + } else { + var pos2 = checkVal(true); + while (pos.begin < len && !tests[pos.begin]) + pos.begin++; + + input.caret(pos.begin,pos.begin); } - function blurEvent(e) { - checkVal(); + if (settings.completed && pos == input.val().length) + settings.completed.call(input); + } + + function blurEvent(e) { + checkVal(); - if (input.val() != focusText) - input.change(); - } + if (input.val() != focusText) + input.change(); + } function keydownEvent(e) { var k = e.which, @@ -227,12 +230,6 @@ $.fn.extend({ } function keypressEvent(e) { - if (bindInputEvent) - { - bindInputEvent = false; - input.off('input.mask'); - } - ; var k = e.which, pos = input.caret(), p, @@ -393,13 +390,11 @@ $.fn.extend({ settings.completed.call(input); }, 0); }); - if (chrome && android) // bind with input event - { - bindInputEvent = true; - input.bind('input.mask', inputEvent); - } else + if (chrome && android) { - bindInputEvent = false; + input + .off('input.mask') + .on('input.mask', androidInputEvent); } checkVal(); //Perform initial check for existing values }); From 179d895ede3d366fe3c479ff1b7072d4359e2272 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sun, 28 Sep 2014 21:33:14 -0500 Subject: [PATCH 09/47] Shouldn't need this android keypress workaround now. --- dist/jquery.maskedinput.js | 6 ------ dist/jquery.maskedinput.min.js | 2 +- src/jquery.maskedinput.js | 17 ----------------- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index e0eeeb4..6b689a1 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -98,12 +98,6 @@ } function keypressEvent(e) { var p, c, next, k = e.which, pos = input.caret(); - if (0 == k) { - if (pos.begin >= len) return input.val(input.val().substr(0, len)), e.preventDefault(), - !1; - pos.begin == pos.end && (k = input.val().charCodeAt(pos.begin - 1), pos.begin--, - pos.end--); - } if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) { if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)), p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) { diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 67889ad..895a33b 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=n=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(n--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(a){for(;++a=0&&!k[a];);return a}function q(a,b){var c,d;if(!(0>a)){for(c=a,d=i(b);n>c;c++)if(k[c]){if(!(n>d&&k[c].test(A[d])))break;A[c]=A[d],A[d]=e.placeholder,d=i(d)}x(),z.caret(Math.max(m,a))}}function r(a){var b,c,d,f;for(b=a,c=e.placeholder;n>b;b++)if(k[b]){if(d=i(b),f=A[b],A[b]=c,!(n>d&&k[d].test(f)))break;c=f}}function s(){var a=z.val(),b=z.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.begin=n)return z.val(z.val().substr(0,n)),b.preventDefault(),!1;j.begin==j.end&&(g=z.val().charCodeAt(j.begin-1),j.begin--,j.end--)}if(!(b.ctrlKey||b.altKey||b.metaKey||32>g)&&g&&13!==g){if(j.end-j.begin!==0&&(w(j.begin,j.end),q(j.begin,j.end-1)),c=i(j.begin-1),n>c&&(d=String.fromCharCode(g),k[c].test(d))){if(r(c),A[c]=d,x(),f=i(c),h){var l=function(){a.proxy(a.fn.caret,z,f)()};setTimeout(l,0)}else z.caret(f);e.completed&&f>=n&&e.completed.call(z)}b.preventDefault()}}function w(a,b){var c;for(c=a;b>c&&n>c;c++)k[c]&&(A[c]=e.placeholder)}function x(){z.val(A.join(""))}function y(a){var b,c,d,f=z.val(),g=-1;for(b=0,d=0;n>b;b++)if(k[b]){for(A[b]=e.placeholder;d++f.length)break}else A[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?x():l>g+1?e.autoclear||A.join("")===B?(z.val()&&z.val(""),w(0,n)):x():(x(),z.val(z.val().substring(0,g+1))),l?b:m}var z=a(this),A=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),B=A.join(""),C=z.val();z.data(a.mask.dataName,function(){return a.map(A,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),z.attr("readonly")||z.one("unmask",function(){z.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;C=z.val(),a=y(),c=setTimeout(function(){x(),a==b.replace("?","").length?z.caret(0,a):z.caret(a)},10)}).on("blur.mask",t).on("keydown.mask",u).on("keypress.mask",v).on(d,function(){setTimeout(function(){var a=y(!0);z.caret(a),e.completed&&a==z.val().length&&e.completed.call(z)},0)}),g&&h&&z.off("input.mask").on("input.mask",s),y()}))}})}(jQuery); \ No newline at end of file +!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=n=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(n--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(a){for(;++a=0&&!k[a];);return a}function q(a,b){var c,d;if(!(0>a)){for(c=a,d=i(b);n>c;c++)if(k[c]){if(!(n>d&&k[c].test(A[d])))break;A[c]=A[d],A[d]=e.placeholder,d=i(d)}x(),z.caret(Math.max(m,a))}}function r(a){var b,c,d,f;for(b=a,c=e.placeholder;n>b;b++)if(k[b]){if(d=i(b),f=A[b],A[b]=c,!(n>d&&k[d].test(f)))break;c=f}}function s(){var a=z.val(),b=z.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(j.end-j.begin!==0&&(w(j.begin,j.end),q(j.begin,j.end-1)),c=i(j.begin-1),n>c&&(d=String.fromCharCode(g),k[c].test(d))){if(r(c),A[c]=d,x(),f=i(c),h){var l=function(){a.proxy(a.fn.caret,z,f)()};setTimeout(l,0)}else z.caret(f);e.completed&&f>=n&&e.completed.call(z)}b.preventDefault()}}function w(a,b){var c;for(c=a;b>c&&n>c;c++)k[c]&&(A[c]=e.placeholder)}function x(){z.val(A.join(""))}function y(a){var b,c,d,f=z.val(),g=-1;for(b=0,d=0;n>b;b++)if(k[b]){for(A[b]=e.placeholder;d++f.length)break}else A[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?x():l>g+1?e.autoclear||A.join("")===B?(z.val()&&z.val(""),w(0,n)):x():(x(),z.val(z.val().substring(0,g+1))),l?b:m}var z=a(this),A=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),B=A.join(""),C=z.val();z.data(a.mask.dataName,function(){return a.map(A,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),z.attr("readonly")||z.one("unmask",function(){z.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;C=z.val(),a=y(),c=setTimeout(function(){x(),a==b.replace("?","").length?z.caret(0,a):z.caret(a)},10)}).on("blur.mask",t).on("keydown.mask",u).on("keypress.mask",v).on(d,function(){setTimeout(function(){var a=y(!0);z.caret(a),e.completed&&a==z.val().length&&e.completed.call(z)},0)}),g&&h&&z.off("input.mask").on("input.mask",s),y()}))}})}(jQuery); \ No newline at end of file diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index d2d10d7..dd388f1 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -236,23 +236,6 @@ $.fn.extend({ c, next; - if (k == 0) { - // unable to detect key pressed. Grab it from pos and adjust - // this is a failsafe for mobile chrome - // which can't detect keypress events - // reliably - if (pos.begin >= len) { - input.val(input.val().substr(0, len)); - e.preventDefault(); - return false; - } - if (pos.begin == pos.end) { - k = input.val().charCodeAt(pos.begin - 1); - pos.begin--; - pos.end--; - } - } - if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore return; } else if ( k && k !== 13 ) { From ed5ab64ef32ae47dff5967aba7a092abe1a911b6 Mon Sep 17 00:00:00 2001 From: Jared Barboza Date: Mon, 6 Oct 2014 22:06:09 -0400 Subject: [PATCH 10/47] add bower.json --- bower.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..e8d3bcd --- /dev/null +++ b/bower.json @@ -0,0 +1,29 @@ +{ + "name": "jquery.maskedinput", + "version": "1.3.1", + "homepage": "http://digitalbush.com/projects/masked-input-plugin/", + "authors": [ + "Josh Bush (digitalbush.com)" + ], + "description": "jQuery Masked Input Plugin", + "moduleType": [ + "es6" + ], + "keywords": [ + "input", + "form", + "mask", + "jquery" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "spec", + "lib" + ], + "dependencies": { + "jquery": ">=1.8.3 <2.0" + } +} From fbf77453fe7c42c8d92d99b0833dd4af8cc94562 Mon Sep 17 00:00:00 2001 From: Jared Barboza Date: Mon, 6 Oct 2014 22:06:17 -0400 Subject: [PATCH 11/47] ignore bower_components/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3175dd7..ae2f59e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea/* node_modules/ +bower_components/ From 0b2f909f38f6762a933039440b4b50d413076b8d Mon Sep 17 00:00:00 2001 From: Jared Barboza Date: Mon, 6 Oct 2014 22:16:00 -0400 Subject: [PATCH 12/47] fix formatting of cmds, add bower instructions --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac4c6c0..1637dd8 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,21 @@ If your requirements aren't met by the predefined placeholders, you can always a By design, this plugin will reject input which doesn't complete the mask. You can bypass this by using a '?' character at the position where you would like to consider input optional. For example, a mask of "(999) 999-9999? x99999" would require only the first 10 digits of a phone number with extension being optional. + +Getting the bits +---------------- +We generally recommend that you use [bower](http://bower.io) to install jquery.maskedinput plugin, however you can download a copy of the latest release by clicking [this link right here.](https://github.com/digitalBush/jquery.maskedinput/archive/1.3.1.zip) + + $ bower install --save jquery.maskedinput + + Setting up your Developer Environment ------------------------------------- jQuery Masked Input uses [NodeJS](http://www.nodejs.org) and [GruntJS](http://www.gruntjs.com) as it's developer platform and build automation tool. To get your environment setup correctly, you'll need nodejs version 0.8.25 or greater installed. You'll also need to install the grunt command line tool: - $ sudo npm install -g grunt-cli + $ sudo npm install -g grunt-cli Once node is installed on your system all that you need to do is install the developer dependencies and run the grunt build: From a006b22a6a617e95edb187173641ee53210dc4f5 Mon Sep 17 00:00:00 2001 From: Angela Nicholas Date: Tue, 7 Oct 2014 14:10:24 -0700 Subject: [PATCH 13/47] clear buffer when shifting characters to the left --- spec/Focus.Spec.js | 17 +++++++++++++++++ src/jquery.maskedinput.js | 1 + 2 files changed, 18 insertions(+) diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index 9964893..de3976c 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -126,6 +126,23 @@ feature("Leaving A Masked Input",function(){ expect(input).toHaveValue("1_"); }); }); + + scenario("Shifts characters left on blur with autoclear false",function(){ + given("a mask with 10 placeholders",function(){ + input.mask("(999) 999-9999", { autoclear: false }); + }); + when("focusing input",function(){ + input.focus(); + }); + waits(20); + when("typing characters at the end of the mask and blurring",function(){ + input.caret(12); + input.mashKeys("44").blur(); + }); + then("characters should shift left to beginning of mask",function(){ + expect(input).toHaveValue("(44_) ___-____"); + }); + }); }); feature("Optional marker",function(){ diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index dd388f1..1350673 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -305,6 +305,7 @@ $.fn.extend({ } } if (pos > test.length) { + clearBuffer(i + 1, len); break; } } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { From 43739da3f73e5ed3e839110bc9b692be4fa4abc7 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Thu, 9 Oct 2014 21:00:10 -0500 Subject: [PATCH 14/47] Fire completed callback when user types in middle of input. Closes #254 Closes #214 Closes #174 Closes #126 Closes #88 --- dist/jquery.maskedinput.js | 21 +++++-- dist/jquery.maskedinput.min.js | 2 +- spec/Completed.Spec.js | 102 +++++++++++++++++++++++++++++++++ src/jquery.maskedinput.js | 43 +++++++++----- 4 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 spec/Completed.Spec.js diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index 6b689a1..e4b1ae2 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -38,7 +38,7 @@ return this.trigger("unmask"); }, mask: function(mask, settings) { - var input, defs, tests, partialPosition, firstNonMaskPos, len, oldVal; + var input, defs, tests, partialPosition, firstNonMaskPos, lastRequiredNonMaskPos, len, oldVal; return !mask && this.length > 0 ? (input = $(this[0]), input.data($.mask.dataName)()) : (settings = $.extend({ autoclear: $.mask.autoclear, placeholder: $.mask.placeholder, @@ -46,8 +46,14 @@ }, settings), defs = $.mask.definitions, tests = [], partialPosition = len = mask.length, firstNonMaskPos = null, $.each(mask.split(""), function(i, c) { "?" == c ? (len--, partialPosition = i) : defs[c] ? (tests.push(new RegExp(defs[c])), - null === firstNonMaskPos && (firstNonMaskPos = tests.length - 1)) : tests.push(null); + null === firstNonMaskPos && (firstNonMaskPos = tests.length - 1), partialPosition > i && (lastRequiredNonMaskPos = tests.length - 1)) : tests.push(null); }), this.trigger("unmask").each(function() { + function tryFireCompleted() { + if (settings.completed) { + for (var i = firstNonMaskPos; lastRequiredNonMaskPos >= i; i++) if (tests[i] && buffer[i] === settings.placeholder) return; + settings.completed.call(input); + } + } function seekNext(pos) { for (;++pos < len && !tests[pos]; ) ; return pos; @@ -83,7 +89,7 @@ for (checkVal(!0); pos.begin < len && !tests[pos.begin]; ) pos.begin++; input.caret(pos.begin, pos.begin); } - settings.completed && pos == input.val().length && settings.completed.call(input); + tryFireCompleted(); } function blurEvent() { checkVal(), input.val() != focusText && input.change(); @@ -107,7 +113,7 @@ }; setTimeout(proxy, 0); } else input.caret(next); - settings.completed && next >= len && settings.completed.call(input); + pos.begin <= lastRequiredNonMaskPos && tryFireCompleted(); } e.preventDefault(); } @@ -127,7 +133,10 @@ buffer[i] = c, lastMatch = i; break; } - if (pos > test.length) break; + if (pos > test.length) { + clearBuffer(i + 1, len); + break; + } } else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, lastMatch = i); return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""), clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))), @@ -151,7 +160,7 @@ }).on("blur.mask", blurEvent).on("keydown.mask", keydownEvent).on("keypress.mask", keypressEvent).on(pasteEventName, function() { setTimeout(function() { var pos = checkVal(!0); - input.caret(pos), settings.completed && pos == input.val().length && settings.completed.call(input); + input.caret(pos), tryFireCompleted(); }, 0); }), chrome && android && input.off("input.mask").on("input.mask", androidInputEvent), checkVal(); diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 895a33b..5b54bdb 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=n=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(n--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(a){for(;++a=0&&!k[a];);return a}function q(a,b){var c,d;if(!(0>a)){for(c=a,d=i(b);n>c;c++)if(k[c]){if(!(n>d&&k[c].test(A[d])))break;A[c]=A[d],A[d]=e.placeholder,d=i(d)}x(),z.caret(Math.max(m,a))}}function r(a){var b,c,d,f;for(b=a,c=e.placeholder;n>b;b++)if(k[b]){if(d=i(b),f=A[b],A[b]=c,!(n>d&&k[d].test(f)))break;c=f}}function s(){var a=z.val(),b=z.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(j.end-j.begin!==0&&(w(j.begin,j.end),q(j.begin,j.end-1)),c=i(j.begin-1),n>c&&(d=String.fromCharCode(g),k[c].test(d))){if(r(c),A[c]=d,x(),f=i(c),h){var l=function(){a.proxy(a.fn.caret,z,f)()};setTimeout(l,0)}else z.caret(f);e.completed&&f>=n&&e.completed.call(z)}b.preventDefault()}}function w(a,b){var c;for(c=a;b>c&&n>c;c++)k[c]&&(A[c]=e.placeholder)}function x(){z.val(A.join(""))}function y(a){var b,c,d,f=z.val(),g=-1;for(b=0,d=0;n>b;b++)if(k[b]){for(A[b]=e.placeholder;d++f.length)break}else A[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?x():l>g+1?e.autoclear||A.join("")===B?(z.val()&&z.val(""),w(0,n)):x():(x(),z.val(z.val().substring(0,g+1))),l?b:m}var z=a(this),A=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),B=A.join(""),C=z.val();z.data(a.mask.dataName,function(){return a.map(A,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),z.attr("readonly")||z.one("unmask",function(){z.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;C=z.val(),a=y(),c=setTimeout(function(){x(),a==b.replace("?","").length?z.caret(0,a):z.caret(a)},10)}).on("blur.mask",t).on("keydown.mask",u).on("keypress.mask",v).on(d,function(){setTimeout(function(){var a=y(!0);z.caret(a),e.completed&&a==z.val().length&&e.completed.call(z)},0)}),g&&h&&z.off("input.mask").on("input.mask",s),y()}))}})}(jQuery); \ No newline at end of file +!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.attr("readonly")||B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}(jQuery); \ No newline at end of file diff --git a/spec/Completed.Spec.js b/spec/Completed.Spec.js new file mode 100644 index 0000000..34a5b8a --- /dev/null +++ b/spec/Completed.Spec.js @@ -0,0 +1,102 @@ +feature("Completed callback", function() { + scenario('Completing mask by typing last character',function(){ + var completed=false; + given("an input with a completed callback", function(){ + input.mask("99",{completed:function(){completed=true;}}); + }); + + when("typing left to right",function(){ + input.mashKeys("12"); + }); + + then("completed callback should be called",function(){ + expect(completed).toBeTruthy(); + }); + then("value should be correct",function(){ + expect(input).toHaveValue('12'); + }); + }); + + scenario('Completing mask by typing first character',function(){ + var completed=false; + given("an input with a completed callback", function(){ + input.val("12").mask("99",{completed:function(){completed=true;}}); + }); + + when("replacing first character value",function(){ + input + .caret(1) + .mashKeys(function(keys){keys.type(keys.backspace)}) + .mashKeys("3"); + }); + + then("completed callback should be called",function(){ + expect(completed).toBeTruthy(); + }); + + then("value should be correct",function(){ + expect(input).toHaveValue('32'); + }); + }); + + scenario('Typing last character of incomplete mask',function(){ + var completed=false; + given("an input with a completed callback", function(){ + input + .mask("99",{completed:function(){completed=true;}}) + .mashKeys("1") + .mashKeys(function(keys){keys.type(keys.backspace)}); + }); + + when("moving cursor to last position and typing",function(){ + input.caret(1).mashKeys("5"); + }); + + then("completed callback should not be called",function(){ + expect(completed).toBeFalsy(); + }); + + then("value should be correct",function(){ + expect(input).toHaveValue('_5'); + }); + + }); + + scenario('Typing last character of required portion of mask containing optional',function(){ + var completed=false; + given("an input with a completed callback", function(){ + input.mask("99?99",{completed:function(){completed=true;}}); + }); + + when("typing left to right",function(){ + input.mashKeys("12"); + }); + + then("completed callback should be called",function(){ + expect(completed).toBeTruthy(); + }); + + then("value should be correct",function(){ + expect(input).toHaveValue('12__'); + }); + }); + + scenario('Typing all characters of required portion of mask containing optional',function(){ + var completedCount=0; + given("an input with a completed callback", function(){ + input.mask("99?99",{completed:function(){completedCount++;}}); + }); + + when("typing left to right",function(){ + input.mashKeys("1234"); + }); + + then("completed callback should be called",function(){ + expect(completedCount).toEqual(1); + }); + + then("value should be correct",function(){ + expect(input).toHaveValue('1234'); + }); + }); +}); diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 1350673..1b7b9f9 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -69,6 +69,7 @@ $.fn.extend({ tests, partialPosition, firstNonMaskPos, + lastRequiredNonMaskPos, len, oldVal; @@ -97,6 +98,9 @@ $.fn.extend({ if (firstNonMaskPos === null) { firstNonMaskPos = tests.length - 1; } + if(i < partialPosition){ + lastRequiredNonMaskPos = tests.length - 1; + } } else { tests.push(null); } @@ -105,15 +109,28 @@ $.fn.extend({ return this.trigger("unmask").each(function() { var input = $(this), buffer = $.map( - mask.split(""), - function(c, i) { - if (c != '?') { - return defs[c] ? settings.placeholder : c; - } - }), + mask.split(""), + function(c, i) { + if (c != '?') { + return defs[c] ? settings.placeholder : c; + } + }), defaultBuffer = buffer.join(''), focusText = input.val(); + function tryFireCompleted(){ + if (!settings.completed) { + return; + } + + for (var i = firstNonMaskPos; i <= lastRequiredNonMaskPos; i++) { + if (tests[i] && buffer[i] === settings.placeholder) { + return; + } + } + settings.completed.call(input); + } + function seekNext(pos) { while (++pos < len && !tests[pos]); return pos; @@ -189,8 +206,8 @@ $.fn.extend({ input.caret(pos.begin,pos.begin); } - if (settings.completed && pos == input.val().length) - settings.completed.call(input); + + tryFireCompleted(); } function blurEvent(e) { @@ -264,10 +281,9 @@ $.fn.extend({ }else{ input.caret(next); } - - if (settings.completed && next >= len) { - settings.completed.call(input); - } + if(pos.begin <= lastRequiredNonMaskPos){ + tryFireCompleted(); + } } } e.preventDefault(); @@ -370,8 +386,7 @@ $.fn.extend({ setTimeout(function() { var pos=checkVal(true); input.caret(pos); - if (settings.completed && pos == input.val().length) - settings.completed.call(input); + tryFireCompleted(); }, 0); }); if (chrome && android) From e91b438f8d4e9a729f519f1c974ff5d8a286a406 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sun, 12 Oct 2014 22:42:58 -0500 Subject: [PATCH 15/47] Moving readonly checks into handlers. Fixes #253 Fixes #157 --- demo/index.html | 5 +-- dist/jquery.maskedinput.js | 56 +++++++++++++++++++--------------- dist/jquery.maskedinput.min.js | 2 +- spec/Readonly.Spec.js | 16 ++++++++++ spec/lib/jquery.keymasher.js | 38 +++++++++++------------ src/jquery.maskedinput.js | 20 ++++++++++-- 6 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 spec/Readonly.Spec.js diff --git a/demo/index.html b/demo/index.html index d297b1e..055b774 100644 --- a/demo/index.html +++ b/demo/index.html @@ -7,7 +7,7 @@ $(function() { $.mask.definitions['~'] = "[+-]"; $("#date").mask("99/99/9999",{completed:function(){alert("completed!");}}); - $("#phone").mask("(999) 999-9999"); + $(".phone").mask("(999) 999-9999"); $("#phoneExt").mask("(999) 999-9999? x99999"); $("#iphone").mask("+33 999 999 999"); $("#tin").mask("99-9999999"); @@ -31,7 +31,8 @@ - + + diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index e4b1ae2..5e57b0f 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -95,27 +95,31 @@ checkVal(), input.val() != focusText && input.change(); } function keydownEvent(e) { - var pos, begin, end, k = e.which; - oldVal = input.val(), 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(), - begin = pos.begin, end = pos.end, end - begin === 0 && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1), - end = 46 === k ? seekNext(end) : end), clearBuffer(begin, end), shiftL(begin, end - 1), - e.preventDefault()) : 13 === k ? blurEvent.call(this, e) : 27 === k && (input.val(focusText), - input.caret(0, checkVal()), e.preventDefault()); + if (!input.prop("readonly")) { + var pos, begin, end, k = e.which; + oldVal = input.val(), 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(), + begin = pos.begin, end = pos.end, end - begin === 0 && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1), + end = 46 === k ? seekNext(end) : end), clearBuffer(begin, end), shiftL(begin, end - 1), + e.preventDefault()) : 13 === k ? blurEvent.call(this, e) : 27 === k && (input.val(focusText), + input.caret(0, checkVal()), e.preventDefault()); + } } function keypressEvent(e) { - var p, c, next, k = e.which, pos = input.caret(); - if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) { - if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)), - p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) { - if (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), android) { - var proxy = function() { - $.proxy($.fn.caret, input, next)(); - }; - setTimeout(proxy, 0); - } else input.caret(next); - pos.begin <= lastRequiredNonMaskPos && tryFireCompleted(); + if (!input.prop("readonly")) { + var p, c, next, k = e.which, pos = input.caret(); + if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) { + if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)), + p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) { + if (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), android) { + var proxy = function() { + $.proxy($.fn.caret, input, next)(); + }; + setTimeout(proxy, 0); + } else input.caret(next); + pos.begin <= lastRequiredNonMaskPos && tryFireCompleted(); + } + e.preventDefault(); } - e.preventDefault(); } } function clearBuffer(start, end) { @@ -149,16 +153,18 @@ return $.map(buffer, function(c, i) { return tests[i] && c != settings.placeholder ? c : null; }).join(""); - }), input.attr("readonly") || input.one("unmask", function() { + }), input.one("unmask", function() { input.off(".mask").removeData($.mask.dataName); }).on("focus.mask", function() { - clearTimeout(caretTimeoutId); - var pos; - focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() { - writeBuffer(), pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos); - }, 10); + if (!input.prop("readonly")) { + clearTimeout(caretTimeoutId); + var pos; + focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() { + writeBuffer(), pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos); + }, 10); + } }).on("blur.mask", blurEvent).on("keydown.mask", keydownEvent).on("keypress.mask", keypressEvent).on(pasteEventName, function() { - setTimeout(function() { + input.prop("readonly") || setTimeout(function() { var pos = checkVal(!0); input.caret(pos), tryFireCompleted(); }, 0); diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 5b54bdb..4093f44 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.attr("readonly")||B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}(jQuery); \ No newline at end of file +!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}(jQuery); \ No newline at end of file diff --git a/spec/Readonly.Spec.js b/spec/Readonly.Spec.js new file mode 100644 index 0000000..6f37d1f --- /dev/null +++ b/spec/Readonly.Spec.js @@ -0,0 +1,16 @@ +feature("Readonly Inputs", function() { + scenario('Typing',function(){ + + given("a input with readonly added after mask", function(){ + input.mask("99").attr("readonly",true); + }); + + when("typing left to right",function(){ + input.mashKeys("12"); + }); + + then("Input should be ignored",function(){ + expect(input).toHaveValue(""); + }); + }); +}); diff --git a/spec/lib/jquery.keymasher.js b/spec/lib/jquery.keymasher.js index d8d9df5..bb430f6 100644 --- a/spec/lib/jquery.keymasher.js +++ b/spec/lib/jquery.keymasher.js @@ -1,23 +1,23 @@ /* Key Masher plugin for jQuery (https://github.com/digitalBush/jquery.keymasher) - Copyright (c) 2010-2013 Josh Bush (digitalbush.com) + Copyright (c) 2010-2014 Josh Bush (digitalbush.com) Licensed under the MIT license - Version: 0.3 + Version: 0.4 */ (function($,undefined){ //numberPad={'0':96,'1':97,'2':98,'3':99,'4':100,'5':101,'6':102,'7':103,'8':104,'9':105,'*':106,'+':107,'-':109,'.':110,'/':111}, - + var keys=(function(){ var defs={}, - keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`-=[]\\;',./ \t\n", + keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`-=[]\\;',./ \t\n\r", shifted = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()~_+{}|:\"<>?", noprint={shift:16,ctrl:17,meta:91,alt:18,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123, capslock:20,numlock:144,scrolllock:145,pageup:33,pagedown:34,end:35,home:36,backspace:8, insert:45, 'delete':46,pause:19,esc:27,left:37,up:38,right:39,down:40,printscreen:44}; $.each(keys.split(''),function(index,value){ - var keyCode=value.charCodeAt(0),shift=shifted[index]; + var keyCode=value.charCodeAt(0),shift=shifted[index]; defs[value]={keyCode:keyCode,charCode:keyCode,shift:shift}; if(shift) defs[shift]={keyCode:keyCode,charCode:shift.charCodeAt(0),shift:value,requiresShift:index>=26}; @@ -29,39 +29,39 @@ var KeyMasher=function(elm){ var modifierState={alt: false, ctrl: false, meta: false, shift: false}, forced={}; - + var queueModifierEvent=function(direction,modifier,isForced){ forced[modifier]=isForced; - modifierState[modifier]=(direction=='down'); + modifierState[modifier]=(direction=='down'); var event=$.extend($.Event(), modifierState, {type:'key'+direction, keyCode: keys[modifier].keyCode, charCode: 0}); elm.trigger(event); }; - + var queueStroke=function(key){ if($.type(key)==='string') - key=keys[key]; + key=keys[key]; if(key.requiresShift && !modifierState.shift) queueModifierEvent('down','shift',true); else if(modifierState.shift && key.shift) key=keys[key.shift]; - + var ignore = !key.charCode || modifierState.alt || modifierState.ctrl || modifierState.meta, down = $.extend($.Event('keydown'), modifierState, {keyCode: key.keyCode, charCode: 0, which:key.keyCode}), press = $.extend($.Event('keypress'), modifierState, {keyCode: key.charCode, charCode: key.charCode, which: key.charCode}), - up = $.extend($.Event('keyup'), modifierState, {keyCode: key.keyCode, charCode: 0, which:key.keyCode}); - + up = $.extend($.Event('keyup'), modifierState, {keyCode: key.keyCode, charCode: 0, which:key.keyCode}); + elm.trigger(down); if(!down.isDefaultPrevented() && !ignore){ elm.trigger(press); - if(!press.isDefaultPrevented()){ + if(!press.isDefaultPrevented() && !elm.prop("readonly")){ //need to do caret positioning elm.val(elm.val()+String.fromCharCode(key.charCode)); } } elm.trigger(up); - + if(forced.shift) - queueModifierEvent('up','shift'); + queueModifierEvent('up','shift'); }; var public={ @@ -71,13 +71,13 @@ public.type(typing); $.each(toks,function(index,value){queueModifierEvent('up',value);}); return public; - }, + }, type:function(){ $.each(arguments,function(index,typing){ if($.type(typing)==='string') $.each(typing.split(''),function(index,value){queueStroke(value);}); else - queueStroke(typing); + queueStroke(typing); }); return public; } @@ -91,7 +91,7 @@ fn=function(keys){keys.type(typing)}; } return this.each(function(){ - fn(KeyMasher($(this))); + fn(KeyMasher($(this))); }); }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 1b7b9f9..b93820a 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -218,6 +218,10 @@ $.fn.extend({ } function keydownEvent(e) { + if (input.prop("readonly")){ + return; + } + var k = e.which, pos, begin, @@ -247,6 +251,10 @@ $.fn.extend({ } function keypressEvent(e) { + if (input.prop("readonly")){ + return; + } + var k = e.which, pos = input.caret(), p, @@ -355,14 +363,18 @@ $.fn.extend({ }).join(''); }); - if (!input.attr("readonly")) - input + + input .one("unmask", function() { input .off(".mask") .removeData($.mask.dataName); }) .on("focus.mask", function() { + if (input.prop("readonly")){ + return; + } + clearTimeout(caretTimeoutId); var pos; @@ -383,6 +395,10 @@ $.fn.extend({ .on("keydown.mask", keydownEvent) .on("keypress.mask", keypressEvent) .on(pasteEventName, function() { + if (input.prop("readonly")){ + return; + } + setTimeout(function() { var pos=checkVal(true); input.caret(pos); From 08b4ac995ecffe9b10cf0bfb8f732d9dde30e81e Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Wed, 15 Oct 2014 21:48:19 -0500 Subject: [PATCH 16/47] Adding UMD wrapper https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js Thanks for the nudge @AndrewEastwood and @jd-boyd Closes #65 Closes #241 --- dist/jquery.maskedinput.js | 6 ++++-- dist/jquery.maskedinput.min.js | 2 +- src/jquery.maskedinput.js | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index 5e57b0f..5cfad94 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -4,7 +4,9 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function($) { +!function(factory) { + "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory("object" == typeof exports ? require("jquery") : jQuery); +}(function($) { function getPasteEvent() { var el = document.createElement("input"), name = "onpaste"; return el.setAttribute(name, ""), "function" == typeof el[name] ? "paste" : "input"; @@ -173,4 +175,4 @@ })); } }); -}(jQuery); \ No newline at end of file +}); \ No newline at end of file diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 4093f44..6d1edc7 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}(jQuery); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index b93820a..ccf496d 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -1,4 +1,15 @@ -(function($) { +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node/CommonJS + factory(require('jquery')); + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { function getPasteEvent() { var el = document.createElement('input'), @@ -415,4 +426,4 @@ $.fn.extend({ }); } }); -})(jQuery); +})); From f7c9cba70c79657a74eef1bcfae5c01e3fc22991 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Wed, 15 Oct 2014 22:31:12 -0500 Subject: [PATCH 17/47] Making sure we only show optional portion of input when we've filled a placeholder Fixes #63 --- dist/jquery.maskedinput.js | 2 +- dist/jquery.maskedinput.min.js | 2 +- spec/Focus.Spec.js | 74 ----------------------------- spec/Optional.Spec.js | 85 ++++++++++++++++++++++++++++++++++ src/jquery.maskedinput.js | 4 +- 5 files changed, 90 insertions(+), 77 deletions(-) create mode 100644 spec/Optional.Spec.js diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index 5cfad94..df5bb31 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -143,7 +143,7 @@ clearBuffer(i + 1, len); break; } - } else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, lastMatch = i); + } else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, partialPosition > i && (lastMatch = i)); return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""), clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))), partialPosition ? i : firstNonMaskPos; diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 6d1edc7..0aa3247 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,l>b&&(g=b));return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index de3976c..deb9c91 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -144,77 +144,3 @@ feature("Leaving A Masked Input",function(){ }); }); }); - -feature("Optional marker",function(){ - scenario("Placeholders not filled to marker",function(){ - given("a mask with an optional marker",function(){ - input.mask("99?99"); - }); - when("typing one character and leaving",function(){ - input.mashKeys("1").blur(); - }); - then("value should be empty",function(){ - expect(input).toHaveValue(""); - }); - }); - - scenario("Placeholders not filled to marker and autoclear = false", function() { - given("a mask with an optional marker",function(){ - input.mask("99?99", { autoclear: false }); - }); - when("typing one character and leaving",function(){ - input.mashKeys("1").blur(); - }); - then("value should be empty",function(){ - expect(input).toHaveValue("1___"); - }); - }); - - scenario("Placeholders filled to marker",function(){ - given("a mask with an optional marker",function(){ - input.mask("99?99"); - }); - when("typing two characters and leaving",function(){ - input.mashKeys("12").blur(); - }); - then("value should remain",function(){ - expect(input).toHaveValue("12"); - }); - }); - - scenario("Placeholders filled to marker and autoclear = false", function() { - given("a mask with an optional marker",function(){ - input.mask("99?99", { autoclear: false }); - }); - when("typing two characters and leaving",function(){ - input.mashKeys("12").blur(); - }); - then("value should remain",function(){ - expect(input).toHaveValue("12"); - }); - }); - - scenario("Placeholders filled, one marker filled, and autoclear = false", function() { - given("a mask with an optional marker",function(){ - input.mask("99?99", { autoclear: false }); - }); - when("typing three characters and leaving",function(){ - input.mashKeys("123").blur(); - }); - then("value should remain",function(){ - expect(input).toHaveValue("123"); - }); - }); - - scenario("Placeholders and markers filled, and autoclear = false", function() { - given("a mask with an optional marker",function(){ - input.mask("99?99", { autoclear: false }); - }); - when("typing four characters and leaving",function(){ - input.mashKeys("1234").blur(); - }); - then("value should remain",function(){ - expect(input).toHaveValue("1234"); - }); - }); -}); diff --git a/spec/Optional.Spec.js b/spec/Optional.Spec.js new file mode 100644 index 0000000..83e14ae --- /dev/null +++ b/spec/Optional.Spec.js @@ -0,0 +1,85 @@ +feature("Optional marker",function(){ + scenario("Placeholders not filled to marker",function(){ + given("a mask with an optional marker",function(){ + input.mask("99?99"); + }); + when("typing one character and leaving",function(){ + input.mashKeys("1").blur(); + }); + then("value should be empty",function(){ + expect(input).toHaveValue(""); + }); + }); + + scenario("Placeholders not filled to marker and autoclear = false", function() { + given("a mask with an optional marker",function(){ + input.mask("99?99", { autoclear: false }); + }); + when("typing one character and leaving",function(){ + input.mashKeys("1").blur(); + }); + then("value should be empty",function(){ + expect(input).toHaveValue("1___"); + }); + }); + + scenario("Placeholders filled to marker",function(){ + given("a mask with an optional marker",function(){ + input.mask("99?99"); + }); + when("typing two characters and leaving",function(){ + input.mashKeys("12").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("12"); + }); + }); + + scenario("Placeholders filled to marker with literals after",function(){ + given("a mask with an optional marker and literals",function(){ + input.mask("99!? x 99"); + }); + when("typing two characters and leaving",function(){ + input.mashKeys("12").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("12!"); + }); + }); + + scenario("Placeholders filled to marker and autoclear = false", function() { + given("a mask with an optional marker",function(){ + input.mask("99?99", { autoclear: false }); + }); + when("typing two characters and leaving",function(){ + input.mashKeys("12").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("12"); + }); + }); + + scenario("Placeholders filled, one marker filled, and autoclear = false", function() { + given("a mask with an optional marker",function(){ + input.mask("99?99", { autoclear: false }); + }); + when("typing three characters and leaving",function(){ + input.mashKeys("123").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("123"); + }); + }); + + scenario("Placeholders and markers filled, and autoclear = false", function() { + given("a mask with an optional marker",function(){ + input.mask("99?99", { autoclear: false }); + }); + when("typing four characters and leaving",function(){ + input.mashKeys("1234").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("1234"); + }); + }); +}); diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index ccf496d..f35803e 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -345,7 +345,9 @@ $.fn.extend({ } } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { pos++; - lastMatch = i; + if( i < partialPosition){ + lastMatch = i; + } } } if (allow) { From ea2c78e7b77cd41a93916a21effec07d86bad093 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Wed, 15 Oct 2014 22:32:44 -0500 Subject: [PATCH 18/47] Adding a few specs around masks ending in a literal --- spec/Completed.Spec.js | 20 ++++++++++++++++++++ spec/Focus.Spec.js | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/spec/Completed.Spec.js b/spec/Completed.Spec.js index 34a5b8a..be71e62 100644 --- a/spec/Completed.Spec.js +++ b/spec/Completed.Spec.js @@ -99,4 +99,24 @@ feature("Completed callback", function() { expect(input).toHaveValue('1234'); }); }); + + scenario('Completing mask by typing last character with literal to right',function(){ + var completed=false; + given("an input with a completed callback", function(){ + input.mask("99!",{completed:function(){completed=true;}}); + }); + + when("typing left to right",function(){ + input.mashKeys("12"); + }); + + then("completed callback should be called",function(){ + expect(completed).toBeTruthy(); + }); + then("value should be correct",function(){ + expect(input).toHaveValue('12!'); + }); + }); + + }); diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index deb9c91..e77b19d 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -113,6 +113,18 @@ feature("Leaving A Masked Input",function(){ }); }); + scenario("Mask ending in literal",function(){ + given("a mask ending in a literal",function(){ + input.mask("99!"); + }); + when("typing two characters and blurring",function(){ + input.mashKeys("12").blur(); + }); + then("value should remain",function(){ + expect(input).toHaveValue("12!"); + }); + }); + scenario("Empty placeholders remaining with autoclear set to false",function(){ given("a mask with two placeholders",function(){ input.mask("99", { autoclear: false }); From 8abb18bdf5b427cfb39c22ae0ed44a19aef46bfd Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Wed, 15 Oct 2014 23:12:49 -0500 Subject: [PATCH 19/47] Fix issue applying mask with trailing literal to input with initial value Fixes #86 --- dist/jquery.maskedinput.js | 2 +- dist/jquery.maskedinput.min.js | 2 +- spec/Init.Spec.js | 12 ++++++++++++ src/jquery.maskedinput.js | 6 ++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index df5bb31..9a71c02 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -143,7 +143,7 @@ clearBuffer(i + 1, len); break; } - } else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, partialPosition > i && (lastMatch = i)); + } else buffer[i] === test.charAt(pos) && pos++, partialPosition > i && (lastMatch = i); return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""), clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))), partialPosition ? i : firstNonMaskPos; diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 0aa3247..357e809 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&b!==l&&(d++,l>b&&(g=b));return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&d++,l>b&&(g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file diff --git a/spec/Init.Spec.js b/spec/Init.Spec.js index 0bd7dea..e53cfe8 100644 --- a/spec/Init.Spec.js +++ b/spec/Init.Spec.js @@ -23,6 +23,18 @@ feature("Initializing a Mask",function(){ }); }); + scenario("An input with a valid value ending in a literal",function(){ + given("an input with a valid value",function(){ + input.val("12"); + }); + when("setting a mask",function(){ + input.mask("(99)"); + }); + then("the value should be intact",function(){ + expect(input).toHaveValue("(12)"); + }); + }); + scenario("An input with an invalid value and placeholders remaining",function(){ given("an invalid input value",function(){ input.val("55555555"); diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index f35803e..452ef94 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -343,8 +343,10 @@ $.fn.extend({ clearBuffer(i + 1, len); break; } - } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { - pos++; + } else { + if (buffer[i] === test.charAt(pos)) { + pos++; + } if( i < partialPosition){ lastMatch = i; } From 73bd7ec1d863d811f15fe78a9cf33e78c385a573 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Thu, 16 Oct 2014 22:00:21 -0500 Subject: [PATCH 20/47] Adding specs for bug that repeated mask literals when they match placeholders Closes #68 Closes #123 --- spec/Focus.Spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index e77b19d..4e5743e 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -35,6 +35,34 @@ feature("Focusing A Masked Input",function(){ }); }); + scenario("Mask starts with a literal that fits first placeholder",function(){ + given("a mask beginning with a literal",function(){ + input.mask("19").focus(); + }); + waits(20); + when("blurring",function(){ + input.blur(); + }); + waits(20); + then("input value should be correct",function(){ + expect(input).toHaveValue(''); + }); + }); + + scenario("Mask starts with a literal that fits first placeholder and autoclear set to false",function(){ + given("a mask beginning with a literal",function(){ + input.mask("?19",{autoclear: false}).focus(); + }); + waits(20); + when("blurring",function(){ + input.blur(); + }); + waits(20); + then("input value should be correct",function(){ + expect(input).toHaveValue(''); + }); + }); + scenario("Masking a hidden input",function(){ var error; $(window).on("error.test",function(err){error=err;}) From 90faa7b9675c30e078998782676de99374605eeb Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Thu, 16 Oct 2014 22:55:31 -0500 Subject: [PATCH 21/47] Calling mask() to get raw value shouldn't error when mask not applied #107 Thank for the spec @FagnerMartinsBrack! --- dist/jquery.maskedinput.js | 9 +++++++-- dist/jquery.maskedinput.min.js | 2 +- spec/Raw.Spec.js | 13 ++++++++++++- src/jquery.maskedinput.js | 4 +++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js index 9a71c02..b8bc88a 100644 --- a/dist/jquery.maskedinput.js +++ b/dist/jquery.maskedinput.js @@ -41,7 +41,12 @@ }, mask: function(mask, settings) { var input, defs, tests, partialPosition, firstNonMaskPos, lastRequiredNonMaskPos, len, oldVal; - return !mask && this.length > 0 ? (input = $(this[0]), input.data($.mask.dataName)()) : (settings = $.extend({ + if (!mask && this.length > 0) { + input = $(this[0]); + var fn = input.data($.mask.dataName); + return fn ? fn() : void 0; + } + return settings = $.extend({ autoclear: $.mask.autoclear, placeholder: $.mask.placeholder, completed: null @@ -172,7 +177,7 @@ }, 0); }), chrome && android && input.off("input.mask").on("input.mask", androidInputEvent), checkVal(); - })); + }); } }); }); \ No newline at end of file diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js index 357e809..99a704b 100644 --- a/dist/jquery.maskedinput.min.js +++ b/dist/jquery.maskedinput.min.js @@ -4,4 +4,4 @@ Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) Version: 1.3.1 */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;return!b&&this.length>0?(i=a(this[0]),i.data(a.mask.dataName)()):(e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&d++,l>b&&(g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()}))}})}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(){var a=document.createElement("input"),b="onpaste";return a.setAttribute(b,""),"function"==typeof a[b]?"paste":"input"}var c,d=b()+".mask",e=navigator.userAgent,f=/iphone/i.test(e),g=/chrome/i.test(e),h=/android/i.test(e);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(b,e){var i,j,k,l,m,n,o,p;if(!b&&this.length>0){i=a(this[0]);var q=i.data(a.mask.dataName);return q?q():void 0}return e=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},e),j=a.mask.definitions,k=[],l=o=b.length,m=null,a.each(b.split(""),function(a,b){"?"==b?(o--,l=a):j[b]?(k.push(new RegExp(j[b])),null===m&&(m=k.length-1),l>a&&(n=k.length-1)):k.push(null)}),this.trigger("unmask").each(function(){function i(){if(e.completed){for(var a=m;n>=a;a++)if(k[a]&&C[a]===e.placeholder)return;e.completed.call(B)}}function q(a){for(;++a=0&&!k[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);o>c;c++)if(k[c]){if(!(o>d&&k[c].test(C[d])))break;C[c]=C[d],C[d]=e.placeholder,d=q(d)}z(),B.caret(Math.max(m,a))}}function t(a){var b,c,d,f;for(b=a,c=e.placeholder;o>b;b++)if(k[b]){if(d=q(b),f=C[b],C[b]=c,!(o>d&&k[d].test(f)))break;c=f}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!k[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beginf)&&f&&13!==f){if(g.end-g.begin!==0&&(y(g.begin,g.end),s(g.begin,g.end-1)),c=q(g.begin-1),o>c&&(d=String.fromCharCode(f),k[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),h){var j=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(j,0)}else B.caret(e);g.begin<=n&&i()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&o>c;c++)k[c]&&(C[c]=e.placeholder)}function z(){B.val(C.join(""))}function A(a){var b,c,d,f=B.val(),g=-1;for(b=0,d=0;o>b;b++)if(k[b]){for(C[b]=e.placeholder;d++f.length){y(b+1,o);break}}else C[b]===f.charAt(d)&&d++,l>b&&(g=b);return a?z():l>g+1?e.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,o)):z():(z(),B.val(B.val().substring(0,g+1))),l?b:m}var B=a(this),C=a.map(b.split(""),function(a){return"?"!=a?j[a]?e.placeholder:a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return k[b]&&a!=e.placeholder?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(c);var a;E=B.val(),a=A(),c=setTimeout(function(){z(),a==b.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on(d,function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),i()},0)}),g&&h&&B.off("input.mask").on("input.mask",u),A()})}})}); \ No newline at end of file diff --git a/spec/Raw.Spec.js b/spec/Raw.Spec.js index 97be1f8..52a3ed7 100644 --- a/spec/Raw.Spec.js +++ b/spec/Raw.Spec.js @@ -54,6 +54,17 @@ feature("Getting raw value",function(){ expect(input.mask()).toEqual("12"); }); }); + + scenario("Verify if the input hasn't the mask bound through the raw value", function() { + given("an input without a mask", function() { + input + .mask("9/9-9_9").unmask(); + }); + + then("The raw value should be undefined and no error must occur", function() { + expect(input.mask()).toBe(undefined); + }); + }); }); feature("Getting raw value with autoclear set to false", function() { @@ -136,4 +147,4 @@ feature("Getting raw value with autoclear set to false", function() { expect(input.mask()).toEqual("1"); }); }); -}); \ No newline at end of file +}); diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 452ef94..3c449ad 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -86,8 +86,10 @@ $.fn.extend({ if (!mask && this.length > 0) { input = $(this[0]); - return input.data($.mask.dataName)(); + var fn = input.data($.mask.dataName) + return fn?fn():undefined; } + settings = $.extend({ autoclear: $.mask.autoclear, placeholder: $.mask.placeholder, // Load default placeholder From 79b032919bb284d2b3f557ff437afa099334a4f9 Mon Sep 17 00:00:00 2001 From: Simon Timms Date: Thu, 16 Oct 2014 21:56:02 -0600 Subject: [PATCH 22/47] Updating and renaming nuspec file --- dist/{jquery.makedinput.nuspec => jquery.maskedinput.nuspec} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename dist/{jquery.makedinput.nuspec => jquery.maskedinput.nuspec} (94%) diff --git a/dist/jquery.makedinput.nuspec b/dist/jquery.maskedinput.nuspec similarity index 94% rename from dist/jquery.makedinput.nuspec rename to dist/jquery.maskedinput.nuspec index 632c0c4..eb59bb1 100644 --- a/dist/jquery.makedinput.nuspec +++ b/dist/jquery.maskedinput.nuspec @@ -11,7 +11,7 @@ A jQuery plugin which applies a mask to input boxes to provide both a UI hint for users as well as some rudimentary input checking. jQuery,plugins - + From c1f485dbb56eb243e6a9ec1b68bae047563dd9c7 Mon Sep 17 00:00:00 2001 From: Patrick Kettner Date: Fri, 17 Oct 2014 01:48:41 -0400 Subject: [PATCH 23/47] Fallback to event.keyCode for firefox fixes #199 --- src/jquery.maskedinput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 3c449ad..32dbd35 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -235,7 +235,7 @@ $.fn.extend({ return; } - var k = e.which, + var k = e.which || e.keyCode, pos, begin, end; @@ -268,7 +268,7 @@ $.fn.extend({ return; } - var k = e.which, + var k = e.which || e.keyCode, pos = input.caret(), p, c, From 085c49ca9b3525882b3e9e4fb89b5b715c7dc849 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sun, 19 Oct 2014 22:16:05 -0500 Subject: [PATCH 24/47] Adding support for multi character placeholders Fixes #120 Fixes #237 Closes #56 Closes #149 Closes #252 --- demo/index.html | 2 +- dist/jquery.maskedinput.js | 23 +++++++++++++---------- dist/jquery.maskedinput.min.js | 2 +- spec/Placeholder.spec.js | 27 +++++++++++++++++++++++++++ src/jquery.maskedinput.js | 20 +++++++++++++------- 5 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 spec/Placeholder.spec.js diff --git a/demo/index.html b/demo/index.html index 055b774..eafcc82 100644 --- a/demo/index.html +++ b/demo/index.html @@ -6,7 +6,7 @@ - + $(function() { $.mask.definitions['~'] = "[+-]"; From 9333fdce00ec2422b1a0a5aa8872f5a99b7b6033 Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sat, 31 Jan 2015 20:32:04 -0600 Subject: [PATCH 38/47] Removing upper jQuery limit. Closes #291 --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 6f0399b..346209a 100644 --- a/bower.json +++ b/bower.json @@ -25,6 +25,6 @@ "lib" ], "dependencies": { - "jquery": ">=1.8.3 <2.0" + "jquery": ">=1.8.3" } } From 24c3bfaec10c043b408f4f2bc94e5926c0059927 Mon Sep 17 00:00:00 2001 From: Dimitrios Kanellopoulos Date: Mon, 9 Feb 2015 23:50:02 +0100 Subject: [PATCH 39/47] Fix oldVal not beeing set --- src/jquery.maskedinput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 9b38bd9..8adcc4f 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -199,7 +199,7 @@ $.fn.extend({ function androidInputEvent(e) { var curVal = input.val(); var pos = input.caret(); - if (curVal.length < oldVal.length) { + if (oldVal && oldVal.length && oldVal.length > curVal.length ) { // a deletion or backspace happened checkVal(true); while (pos.begin > 0 && !tests[pos.begin-1]) From f19728180c604c1b0c62d6aa97af262c0c04d71c Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Tue, 10 Feb 2015 21:17:34 -0600 Subject: [PATCH 40/47] 1.4.1 --- bower.json | 2 +- dist/jquery.maskedinput.js | 182 +++++++++++++++++++++++++++++++++ dist/jquery.maskedinput.min.js | 7 ++ jquery.maskedinput.nuspec | 2 +- package.json | 2 +- 5 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 dist/jquery.maskedinput.js create mode 100644 dist/jquery.maskedinput.min.js diff --git a/bower.json b/bower.json index 346209a..63e7ab7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.maskedinput", - "version": "1.4.0", + "version": "1.4.1", "homepage": "http://digitalbush.com/projects/masked-input-plugin/", "authors": [ "Josh Bush (digitalbush.com)" diff --git a/dist/jquery.maskedinput.js b/dist/jquery.maskedinput.js new file mode 100644 index 0000000..4ac3cfc --- /dev/null +++ b/dist/jquery.maskedinput.js @@ -0,0 +1,182 @@ +/* + jQuery Masked Input Plugin + Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com) + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) + Version: 1.4.1 +*/ +!function(factory) { + "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory("object" == typeof exports ? require("jquery") : jQuery); +}(function($) { + var caretTimeoutId, ua = navigator.userAgent, iPhone = /iphone/i.test(ua), chrome = /chrome/i.test(ua), android = /android/i.test(ua); + $.mask = { + definitions: { + "9": "[0-9]", + a: "[A-Za-z]", + "*": "[A-Za-z0-9]" + }, + autoclear: !0, + dataName: "rawMaskFn", + placeholder: "_" + }, $.fn.extend({ + caret: function(begin, end) { + var range; + if (0 !== this.length && !this.is(":hidden")) return "number" == typeof begin ? (end = "number" == typeof end ? end : begin, + this.each(function() { + this.setSelectionRange ? this.setSelectionRange(begin, end) : this.createTextRange && (range = this.createTextRange(), + range.collapse(!0), range.moveEnd("character", end), range.moveStart("character", begin), + range.select()); + })) : (this[0].setSelectionRange ? (begin = this[0].selectionStart, end = this[0].selectionEnd) : document.selection && document.selection.createRange && (range = document.selection.createRange(), + begin = 0 - range.duplicate().moveStart("character", -1e5), end = begin + range.text.length), + { + begin: begin, + end: end + }); + }, + unmask: function() { + return this.trigger("unmask"); + }, + mask: function(mask, settings) { + var input, defs, tests, partialPosition, firstNonMaskPos, lastRequiredNonMaskPos, len, oldVal; + if (!mask && this.length > 0) { + input = $(this[0]); + var fn = input.data($.mask.dataName); + return fn ? fn() : void 0; + } + return settings = $.extend({ + autoclear: $.mask.autoclear, + placeholder: $.mask.placeholder, + completed: null + }, settings), defs = $.mask.definitions, tests = [], partialPosition = len = mask.length, + firstNonMaskPos = null, $.each(mask.split(""), function(i, c) { + "?" == c ? (len--, partialPosition = i) : defs[c] ? (tests.push(new RegExp(defs[c])), + null === firstNonMaskPos && (firstNonMaskPos = tests.length - 1), partialPosition > i && (lastRequiredNonMaskPos = tests.length - 1)) : tests.push(null); + }), this.trigger("unmask").each(function() { + function tryFireCompleted() { + if (settings.completed) { + for (var i = firstNonMaskPos; lastRequiredNonMaskPos >= i; i++) if (tests[i] && buffer[i] === getPlaceholder(i)) return; + settings.completed.call(input); + } + } + function getPlaceholder(i) { + return settings.placeholder.charAt(i < settings.placeholder.length ? i : 0); + } + function seekNext(pos) { + for (;++pos < len && !tests[pos]; ) ; + return pos; + } + function seekPrev(pos) { + for (;--pos >= 0 && !tests[pos]; ) ; + return pos; + } + function shiftL(begin, end) { + var i, j; + if (!(0 > begin)) { + for (i = begin, j = seekNext(end); len > i; i++) if (tests[i]) { + if (!(len > j && tests[i].test(buffer[j]))) break; + buffer[i] = buffer[j], buffer[j] = getPlaceholder(j), j = seekNext(j); + } + writeBuffer(), input.caret(Math.max(firstNonMaskPos, begin)); + } + } + function shiftR(pos) { + var i, c, j, t; + for (i = pos, c = getPlaceholder(pos); len > i; i++) if (tests[i]) { + if (j = seekNext(i), t = buffer[i], buffer[i] = c, !(len > j && tests[j].test(t))) break; + c = t; + } + } + function androidInputEvent() { + var curVal = input.val(), pos = input.caret(); + if (oldVal && oldVal.length && oldVal.length > curVal.length) { + for (checkVal(!0); pos.begin > 0 && !tests[pos.begin - 1]; ) pos.begin--; + if (0 === pos.begin) for (;pos.begin < firstNonMaskPos && !tests[pos.begin]; ) pos.begin++; + input.caret(pos.begin, pos.begin); + } else { + for (checkVal(!0); pos.begin < len && !tests[pos.begin]; ) pos.begin++; + input.caret(pos.begin, pos.begin); + } + tryFireCompleted(); + } + function blurEvent() { + checkVal(), input.val() != focusText && input.change(); + } + function keydownEvent(e) { + if (!input.prop("readonly")) { + var pos, begin, end, k = e.which || e.keyCode; + oldVal = input.val(), 8 === k || 46 === k || iPhone && 127 === k ? (pos = input.caret(), + begin = pos.begin, end = pos.end, end - begin === 0 && (begin = 46 !== k ? seekPrev(begin) : end = seekNext(begin - 1), + end = 46 === k ? seekNext(end) : end), clearBuffer(begin, end), shiftL(begin, end - 1), + e.preventDefault()) : 13 === k ? blurEvent.call(this, e) : 27 === k && (input.val(focusText), + input.caret(0, checkVal()), e.preventDefault()); + } + } + function keypressEvent(e) { + if (!input.prop("readonly")) { + var p, c, next, k = e.which || e.keyCode, pos = input.caret(); + if (!(e.ctrlKey || e.altKey || e.metaKey || 32 > k) && k && 13 !== k) { + if (pos.end - pos.begin !== 0 && (clearBuffer(pos.begin, pos.end), shiftL(pos.begin, pos.end - 1)), + p = seekNext(pos.begin - 1), len > p && (c = String.fromCharCode(k), tests[p].test(c))) { + if (shiftR(p), buffer[p] = c, writeBuffer(), next = seekNext(p), android) { + var proxy = function() { + $.proxy($.fn.caret, input, next)(); + }; + setTimeout(proxy, 0); + } else input.caret(next); + pos.begin <= lastRequiredNonMaskPos && tryFireCompleted(); + } + e.preventDefault(); + } + } + } + function clearBuffer(start, end) { + var i; + for (i = start; end > i && len > i; i++) tests[i] && (buffer[i] = getPlaceholder(i)); + } + function writeBuffer() { + input.val(buffer.join("")); + } + function checkVal(allow) { + var i, c, pos, test = input.val(), lastMatch = -1; + for (i = 0, pos = 0; len > i; i++) if (tests[i]) { + for (buffer[i] = getPlaceholder(i); pos++ < test.length; ) if (c = test.charAt(pos - 1), + tests[i].test(c)) { + buffer[i] = c, lastMatch = i; + break; + } + if (pos > test.length) { + clearBuffer(i + 1, len); + break; + } + } else buffer[i] === test.charAt(pos) && pos++, partialPosition > i && (lastMatch = i); + return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""), + clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))), + partialPosition ? i : firstNonMaskPos; + } + var input = $(this), buffer = $.map(mask.split(""), function(c, i) { + return "?" != c ? defs[c] ? getPlaceholder(i) : c : void 0; + }), defaultBuffer = buffer.join(""), focusText = input.val(); + input.data($.mask.dataName, function() { + return $.map(buffer, function(c, i) { + return tests[i] && c != getPlaceholder(i) ? c : null; + }).join(""); + }), input.one("unmask", function() { + input.off(".mask").removeData($.mask.dataName); + }).on("focus.mask", function() { + if (!input.prop("readonly")) { + clearTimeout(caretTimeoutId); + var pos; + focusText = input.val(), pos = checkVal(), caretTimeoutId = setTimeout(function() { + input.get(0) === document.activeElement && (writeBuffer(), pos == mask.replace("?", "").length ? input.caret(0, pos) : input.caret(pos)); + }, 10); + } + }).on("blur.mask", blurEvent).on("keydown.mask", keydownEvent).on("keypress.mask", keypressEvent).on("input.mask paste.mask", function() { + input.prop("readonly") || setTimeout(function() { + var pos = checkVal(!0); + input.caret(pos), tryFireCompleted(); + }, 0); + }), chrome && android && input.off("input.mask").on("input.mask", androidInputEvent), + checkVal(); + }); + } + }); +}); \ No newline at end of file diff --git a/dist/jquery.maskedinput.min.js b/dist/jquery.maskedinput.min.js new file mode 100644 index 0000000..d4dfd01 --- /dev/null +++ b/dist/jquery.maskedinput.min.js @@ -0,0 +1,7 @@ +/* + jQuery Masked Input Plugin + Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com) + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) + Version: 1.4.1 +*/ +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})}); \ No newline at end of file diff --git a/jquery.maskedinput.nuspec b/jquery.maskedinput.nuspec index 0271931..9e88140 100644 --- a/jquery.maskedinput.nuspec +++ b/jquery.maskedinput.nuspec @@ -2,7 +2,7 @@ jQuery.MaskedInput - 1.4.0.0 + 1.4.1.0 digitalBush stimms https://github.com/digitalBush/jquery.maskedinput/blob/master/LICENSE diff --git a/package.json b/package.json index 8bd604c..8c65c9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.maskedinput", - "version": "1.4.0", + "version": "1.4.1", "author": "Josh Bush (digitalbush.com)", "description": "jQuery Masked Input Plugin", "devDependencies": { From 0d017f402fefac2dae427654f9ba74b23d2b93a3 Mon Sep 17 00:00:00 2001 From: Ben Cooley Date: Mon, 11 May 2015 10:39:55 -0400 Subject: [PATCH 41/47] Ensuring caret does not execute if the element does not have focus. This fixes an issue in IE11 where the user may not be able to move to another input element --- src/jquery.maskedinput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 8adcc4f..ee6d1ab 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -34,7 +34,7 @@ $.fn.extend({ caret: function(begin, end) { var range; - if (this.length === 0 || this.is(":hidden")) { + if (this.length === 0 || this.is(":hidden") || this.get(0) !== document.activeElement) { return; } From 7ae3485fccf9b408f81b4f7f0645a6b74dbe66b8 Mon Sep 17 00:00:00 2001 From: Mike Bobrov Date: Tue, 12 May 2015 11:10:55 +0300 Subject: [PATCH 42/47] A little update to the documentation Of course it can be easily found from the source code, but it would be very convenient to see it in the documentation --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 97c7745..825533a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,13 @@ jQuery(function($){ }); ``` +Optionally, if you would like to disable the automatic discarding of the uncomplete input, you may pass an optional argument to the maskedinput method +```html +jQuery(function($){ + $("#product").mask("99/99/9999",{autoclear: false}); +}); +``` + You can now supply your own mask definitions. ```html jQuery(function($){ From b21979c52c3146cc3e9e33f8d93ee8e49e1f8617 Mon Sep 17 00:00:00 2001 From: Allan Maia Fernandes Date: Mon, 18 May 2015 16:07:48 -0300 Subject: [PATCH 43/47] Forcing mask to string This code: $('[data-masked]').each(function() { $(this).mask($(this).data('masked')); }); Will give an error, when data-masked="99999" ... the $(this).data returns a number object, not string. --- src/jquery.maskedinput.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 8adcc4f..9106d5e 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -94,6 +94,8 @@ $.fn.extend({ partialPosition = len = mask.length; firstNonMaskPos = null; + mask = String(mask); + $.each(mask.split(""), function(i, c) { if (c == '?') { len--; From 89aa9d33d41f2cbcc27ab6afe3c8c9fa4d5df99a Mon Sep 17 00:00:00 2001 From: Matt Sich Date: Thu, 11 Jun 2015 11:48:47 -0400 Subject: [PATCH 44/47] fixed android issue where cursor would not move and input would be typed backwards --- src/jquery.maskedinput.js | 59 +++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 8adcc4f..64f961d 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -196,32 +196,43 @@ $.fn.extend({ } } - function androidInputEvent(e) { - var curVal = input.val(); - var pos = input.caret(); - if (oldVal && oldVal.length && oldVal.length > curVal.length ) { - // a deletion or backspace happened - checkVal(true); - while (pos.begin > 0 && !tests[pos.begin-1]) - pos.begin--; - if (pos.begin === 0) - { - while (pos.begin < firstNonMaskPos && !tests[pos.begin]) - pos.begin++; - } - input.caret(pos.begin,pos.begin); - } else { - var pos2 = checkVal(true); - while (pos.begin < len && !tests[pos.begin]) - pos.begin++; - - input.caret(pos.begin,pos.begin); - } + function androidInputEvent(e) { + console.log(input); + var curVal = input.val(); + var pos = input.caret(); + if (oldVal && oldVal.length && oldVal.length > curVal.length ) { + // a deletion or backspace happened + checkVal(true); + while (pos.begin > 0 && !tests[pos.begin-1]) + pos.begin--; + if (pos.begin === 0) + { + while (pos.begin < firstNonMaskPos && !tests[pos.begin]) + pos.begin++; + } + input.caret(pos.begin,pos.begin); + } else { + var pos2 = checkVal(true); + var lastEnteredValue = curVal.charAt(pos.begin); + if (pos.begin < len){ + if(!tests[pos.begin]){ + pos.begin++; + if(tests[pos.begin].test(lastEnteredValue)){ + pos.begin++; + } + }else{ + if(tests[pos.begin].test(lastEnteredValue)){ + pos.begin++; + } + } + } + input.caret(pos.begin,pos.begin); + } + tryFireCompleted(); + } - tryFireCompleted(); - } - function blurEvent(e) { + function blurEvent(e) { checkVal(); if (input.val() != focusText) From e0708d76794a26b2516dc615cc0b7307001172f2 Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Thu, 11 Jun 2015 22:53:23 -0400 Subject: [PATCH 45/47] Remove moot `version` property from bower.json Per bower/bower.json-spec@a325da3 Also their maintainer says they probably won't ever use it: http://stackoverflow.com/questions/24844901/bowers-bower-json-file-version-property --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index 63e7ab7..e6368cb 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "jquery.maskedinput", - "version": "1.4.1", "homepage": "http://digitalbush.com/projects/masked-input-plugin/", "authors": [ "Josh Bush (digitalbush.com)" From 2d5e1e2827aeed48c4fd6a680191e8b89e94c4b1 Mon Sep 17 00:00:00 2001 From: MattSich Date: Thu, 18 Jun 2015 20:58:57 -0400 Subject: [PATCH 46/47] Update jquery.maskedinput.js Removed log --- src/jquery.maskedinput.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index 64f961d..df85c09 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -197,7 +197,6 @@ $.fn.extend({ } function androidInputEvent(e) { - console.log(input); var curVal = input.val(); var pos = input.caret(); if (oldVal && oldVal.length && oldVal.length > curVal.length ) { From 4a146e61b83e756446ce17f67f934abd644dafbb Mon Sep 17 00:00:00 2001 From: Josh Bush Date: Sun, 10 Dec 2017 13:57:16 -0600 Subject: [PATCH 47/47] =?UTF-8?q?=F0=9F=91=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 825533a..87889b9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ Masked Input Plugin for jQuery ============================== -[![Build Status](https://travis-ci.org/digitalBush/jquery.maskedinput.png)](https://travis-ci.org/digitalBush/jquery.maskedinput) +**Notice: This project is no longer being maintained.** + +I started this project [over 10 years ago](https://forum.jquery.com/topic/jquery-introduction-and-masked-input-plugin) to fill a need for a side project I was working on at the time. Nothing ever became of that side project, but this little plugin lived on. Over the years it brought me joy to stumble on sites using this thing. It was super encouraging to hear from people using it in their own products. I tried for a while to maintain it, even after I had moved away from front end web development. + +The time has come to officially call it quits. The web has changed(**A LOT**) and there are better things out there like [Cleave.js](https://nosir.github.io/cleave.js/). I'll leave this repo up for posterity in an archived state. Thank you to everyone who contributed to or used this plugin over the years. + + Overview -------- This is a masked input plugin for the jQuery javascript library. It allows a user to more easily enter fixed width input where you would like them to enter the data in a certain format (dates,phone numbers, etc). It has been tested on Internet Explorer, Firefox, Safari, Opera, and Chrome. A mask is defined by a format made up of mask literals and mask definitions. Any character not in the definitions list below is considered a mask literal. Mask literals will be automatically entered for the user as they type and will not be able to be removed by the user.The following mask definitions are predefined:
Date99/99/9999
Phone(999) 999-9999
Phone(999) 999-9999
Phone(Readonly)(999) 999-9999
Phone + Ext(999) 999-9999? x99999
Int'l Phone+33 999 999 999
Tax ID99-9999999