\ No newline at end of file
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 8d9736b..bd84c49 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -278,13 +278,13 @@
});
},
- //jQuery 1.7+
autoMask: function() {
return $(this).on("focus", "input:text[data-mask]", function(e) {
- var $this = $(this);
- var mask = $this.data("mask");
- if(mask !== undefined && $this.mask() === undefined) {
- $this.mask(mask);
+ var $input = $(this),
+ dataMask = $input.data("mask");
+
+ if( dataMask !== undefined && $input.mask() === undefined ) {
+ $input.mask(dataMask);
}
});
}
From cf1b36fb0018d0c01d79f9049d3168aad56e4268 Mon Sep 17 00:00:00 2001
From: Fagner Martins
Date: Sun, 17 Jun 2012 01:24:20 -0300
Subject: [PATCH 23/38] Oops, escaping...
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b5979dd..0307eb6 100644
--- a/README.md
+++ b/README.md
@@ -19,5 +19,5 @@ $(function() {
});
-
+<input type="text" data-mask="99/99/9999" />
\ No newline at end of file
From 4083158ebf15a3e9bafed5d2d8fcc1d3a4ad6a08 Mon Sep 17 00:00:00 2001
From: Fagner Martins
Date: Sun, 17 Jun 2012 01:25:49 -0300
Subject: [PATCH 24/38] escaping v2
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 0307eb6..dc89d4b 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,6 @@ $(function() {
$(document).automask();
});
-
+//The mask will be 99/99/9999
<input type="text" data-mask="99/99/9999" />
\ No newline at end of file
From d04be6dad69253526989f9185802f0eca52ff45c Mon Sep 17 00:00:00 2001
From: Ivan Gromov
Date: Mon, 2 Jul 2012 00:10:00 +0400
Subject: [PATCH 25/38] fixed typo in README
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index dc89d4b..92ba6af 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ By calling $(selector).automask() once it reads the data-mask attribute and auto
Example:
$(function() {
- $(document).automask();
+ $(document).autoMask();
});
//The mask will be 99/99/9999
From 9123c66ac331b9b67e68b68c788f92f6f1ce4014 Mon Sep 17 00:00:00 2001
From: Fagner Martins
Date: Mon, 2 Jul 2012 08:58:07 -0300
Subject: [PATCH 26/38] Other typo
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 92ba6af..b414511 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ This is a masked input plugin for the jQuery javascript library. It allows a use
autoMask (jQuery 1.7+)
--------
-By calling $(selector).automask() once it reads the data-mask attribute and automatically set the specified mask to any input:text element inside the selector.
+By calling $(selector).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input:text element inside the selector.
Example:
$(function() {
From d5b0292dcb54b17f97b23954bf6c5a173301b9f3 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Mon, 2 Jul 2012 16:08:04 -0300
Subject: [PATCH 27/38] FF Component returned failure code: 0x80004005 Fix the
error "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMHTMLInputElement.setSelectionRange]" when programatically focusing in
a hidden element
---
spec/Focus.Spec.js | 12 +++++++++++-
src/jquery.maskedinput.js | 1 +
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js
index c59645f..e9cac4b 100644
--- a/spec/Focus.Spec.js
+++ b/spec/Focus.Spec.js
@@ -16,7 +16,17 @@ feature("Focusing A Masked Input",function(){
expect(caret.end).toEqual(0);
});
});
-
+
+ //Could not test this properly since jquery uses $.error() to throw this exception
+ scenario("Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLInputElement.setSelectionRange]",function(){
+ given("a mask in a hidden input",function(){
+ input.hide().mask("9");
+ });
+ when("focusing no error should occur in the console",function(){
+ input.focus();
+ });
+ });
+
scenario("Mask starts with a literal",function(){
given("a mask beginning with a literal",function(){
input.mask("(9)");
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 6b2dbf2..b4ea2d1 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -27,6 +27,7 @@
//Helper Function for Caret positioning
caret: function(begin, end) {
if (this.length == 0) return;
+ if (this.is(":hidden")) return; //setSelectionRange fails if the element is hidden
if (typeof begin == 'number') {
end = (typeof end == 'number') ? end : begin;
return this.each(function() {
From 8e5abadf7371968980dc8e9f5ffed327275965a0 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Mon, 9 Jul 2012 14:06:23 -0300
Subject: [PATCH 28/38] Fix data-mask="99" not setting properly
---
spec/AutoMask.Spec.js | 26 +++++++++++++++++++++-----
src/jquery.maskedinput.js | 2 +-
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index d7ba912..3d27a8a 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -1,12 +1,13 @@
-var container;
+var container, container2;
feature("AutoMask", function() {
beforeEach(function() {
container = $("").appendTo("body");
+ container = $("").appendTo("body");
});
scenario("Valid container", function() {
- var $cont = $("#auto-mask-container");
- var $input = $cont.find("input");
+ var $cont = $("#auto-mask-container"),
+ $input = $cont.find("input");
given("an autoMask", function() {
$cont.autoMask();
@@ -23,8 +24,8 @@ feature("AutoMask", function() {
});
scenario("Invalid container", function() {
- var $cont = $("#no-auto-mask");
- var $input = $cont.find("input");
+ var $cont = $("#no-auto-mask"),
+ $input = $cont.find("input");
when("typing and bluring", function() {
$input.focus().mashKeys("12").blur();
@@ -35,6 +36,21 @@ feature("AutoMask", function() {
});
});
+ scenario("When reading data should treat as string",function(){
+ var $cont = $("#auto-mask-container2"),
+ $input = $cont.find("input");
+
+ given("an autoMask",function(){
+ $cont.autoMask();
+ });
+ when("focusing",function(){
+ $input.focus().mashKeys("99");
+ });
+ then("the mask should be correct",function(){
+ expect($input.mask()).toBe('99');
+ });
+ });
+
afterEach(function() {
container.remove();
container = undefined;
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index b4ea2d1..5167310 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -286,7 +286,7 @@
dataMask = $input.data("mask");
if( dataMask !== undefined && $input.mask() === undefined ) {
- $input.mask(dataMask);
+ $input.mask( String(dataMask) );
}
});
}
From e8f99c075f2efb1817478ffc9d1c23c2bc9973eb Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Tue, 28 Aug 2012 10:35:31 -0300
Subject: [PATCH 29/38] Add IIFE to avoid globals
---
spec/AutoMask.Spec.js | 98 ++++++++++++++++++++++---------------------
1 file changed, 50 insertions(+), 48 deletions(-)
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index 3d27a8a..8c2cc0d 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -1,58 +1,60 @@
-var container, container2;
-feature("AutoMask", function() {
- beforeEach(function() {
- container = $("").appendTo("body");
- container = $("").appendTo("body");
- });
-
- scenario("Valid container", function() {
- var $cont = $("#auto-mask-container"),
- $input = $cont.find("input");
-
- given("an autoMask", function() {
- $cont.autoMask();
+(function() {
+ var container, container2;
+ feature("AutoMask", function() {
+ beforeEach(function() {
+ container = $("").appendTo("body");
+ container = $("").appendTo("body");
});
- when("typing and bluring", function() {
- $input.focus().mashKeys("12").blur();
+ scenario("Valid container", function() {
+ var $cont = $("#auto-mask-container"),
+ $input = $cont.find("input");
+
+ given("an autoMask", function() {
+ $cont.autoMask();
+ });
+
+ when("typing and bluring", function() {
+ $input.focus().mashKeys("12").blur();
+ });
+
+ then("The mask should be correct", function() {
+ expect($input).toHaveValue("1/2");
+ });
+
});
- then("The mask should be correct", function() {
- expect($input).toHaveValue("1/2");
- });
-
- });
-
- scenario("Invalid container", function() {
- var $cont = $("#no-auto-mask"),
- $input = $cont.find("input");
-
- when("typing and bluring", function() {
- $input.focus().mashKeys("12").blur();
+ scenario("Invalid container", function() {
+ var $cont = $("#no-auto-mask"),
+ $input = $cont.find("input");
+
+ when("typing and bluring", function() {
+ $input.focus().mashKeys("12").blur();
+ });
+
+ then("The mask should be correct", function() {
+ expect($input).toHaveValue("12");
+ });
});
- then("The mask should be correct", function() {
- expect($input).toHaveValue("12");
+ scenario("When reading data should treat as string",function(){
+ var $cont = $("#auto-mask-container2"),
+ $input = $cont.find("input");
+
+ given("an autoMask",function(){
+ $cont.autoMask();
+ });
+ when("focusing",function(){
+ $input.focus().mashKeys("99");
+ });
+ then("the mask should be correct",function(){
+ expect($input.mask()).toBe('99');
+ });
});
- });
-
- scenario("When reading data should treat as string",function(){
- var $cont = $("#auto-mask-container2"),
- $input = $cont.find("input");
- given("an autoMask",function(){
- $cont.autoMask();
- });
- when("focusing",function(){
- $input.focus().mashKeys("99");
+ afterEach(function() {
+ container.remove();
+ container = undefined;
});
- then("the mask should be correct",function(){
- expect($input.mask()).toBe('99');
- });
- });
-
- afterEach(function() {
- container.remove();
- container = undefined;
});
-});
\ No newline at end of file
+})();
\ No newline at end of file
From 59b81d2340e1009f0781db75c280b80de43ab062 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Tue, 28 Aug 2012 10:48:57 -0300
Subject: [PATCH 30/38] Passing options
---
README.md | 16 ++++++++++++++-
spec/AutoMask.Spec.js | 41 +++++++++++++++++++++++++++++++--------
src/jquery.maskedinput.js | 4 ++--
3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index b414511..d48b154 100644
--- a/README.md
+++ b/README.md
@@ -20,4 +20,18 @@ $(function() {
//The mask will be 99/99/9999
<input type="text" data-mask="99/99/9999" />
-
\ No newline at end of file
+
+
+You could also pass the options in the first argument. These options will be defined once and be valid to all the masks inside the selector.
+Example:
+
+$(function() {
+ $(document).autoMask({
+ completed: function() {
+ alert("Alert executed after each mask has been completed");
+ }
+ });
+});
+
+
+autoMask does NOT support two or more instance in the same selector or in any of it's contents.
\ No newline at end of file
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index 8c2cc0d..40a4d54 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -2,8 +2,8 @@
var container, container2;
feature("AutoMask", function() {
beforeEach(function() {
- container = $("").appendTo("body");
- container = $("").appendTo("body");
+ container1 = $("").appendTo("body");
+ container2 = $("").appendTo("body");
});
scenario("Valid container", function() {
@@ -37,24 +37,49 @@
});
});
- scenario("When reading data should treat as string",function(){
+ scenario("When reading data should treat as string", function(){
var $cont = $("#auto-mask-container2"),
$input = $cont.find("input");
- given("an autoMask",function(){
+ given("an autoMask", function(){
$cont.autoMask();
});
- when("focusing",function(){
+ when("focusing", function(){
$input.focus().mashKeys("99");
});
- then("the mask should be correct",function(){
+ then("the mask should be correct", function(){
expect($input.mask()).toBe('99');
});
});
+ scenario("When starting should be able to pass custom options for all the masks", function() {
+ var $cont = $("#auto-mask-container"),
+ $input = $cont.find("input"),
+ count = 0;
+
+ given("an autoMask with options", function() {
+ $cont.autoMask({
+ completed: function() {
+ count++;
+ }
+ });
+ });
+
+ when("typing and bluring", function() {
+ $input.focus().mashKeys("12").blur();
+ });
+
+ then("the completed callback should fire once", function() {
+ expect(count).toBe(1);
+ });
+
+ });
+
afterEach(function() {
- container.remove();
- container = undefined;
+ container1.remove();
+ container2.remove();
+ container1 = undefined;
+ container2.remove();
});
});
})();
\ No newline at end of file
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 5167310..6483bc6 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -280,13 +280,13 @@
});
},
- autoMask: function() {
+ autoMask: function( options ) {
return $(this).on("focus", "input:text[data-mask]", function(e) {
var $input = $(this),
dataMask = $input.data("mask");
if( dataMask !== undefined && $input.mask() === undefined ) {
- $input.mask( String(dataMask) );
+ $input.mask( String(dataMask), options );
}
});
}
From 15d38193500286552b9325ba182a0e294c6bd12d Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Tue, 28 Aug 2012 11:32:21 -0300
Subject: [PATCH 31/38] The callback options from autoMask should behave
exactly as the regular mask
---
spec/AutoMask.Spec.js | 26 ++++++++++++++++++++++++++
src/jquery.maskedinput.js | 13 ++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index 40a4d54..4c79311 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -75,6 +75,32 @@
});
+ scenario("The callback options from autoMask should behave exactly as the regular mask", function() {
+ var input1, input2,
+ $cont = $("#auto-mask-container"),
+ $input = $cont.find("input");
+
+ given("an autoMask with callbacks", function() {
+ $cont.autoMask({
+ completed: function() {
+ input1 = this;
+ },
+ afterBlur: function() {
+ input2 = this;
+ }
+ });
+ });
+
+ when("typing and bluring", function() {
+ $input.focus().mashKeys("12").blur();
+ });
+
+ then("this should be correct", function() {
+ expect(input1[0]).toBe($input[0]);
+ expect(input2[0]).toBe($input[0]);
+ });
+ })
+
afterEach(function() {
container1.remove();
container2.remove();
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 6483bc6..c049c1f 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -282,9 +282,20 @@
autoMask: function( options ) {
return $(this).on("focus", "input:text[data-mask]", function(e) {
- var $input = $(this),
+ var completed, afterBlur,
+ $input = $(this),
dataMask = $input.data("mask");
+ if( options ) {
+ (completed = options.completed) && (options.completed = function() {
+ completed.call( $input );
+ });
+
+ (afterBlur = options.afterBlur) && (options.afterBlur = function() {
+ afterBlur.call( $input );
+ });
+ }
+
if( dataMask !== undefined && $input.mask() === undefined ) {
$input.mask( String(dataMask), options );
}
From 582d183d141668ee6edfc6379be580a99898dcc1 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 10:33:15 -0300
Subject: [PATCH 32/38] Aditional test: The callback options from autoMask
should behave exactly as the regular mask
---
src/jquery.maskedinput.js | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index c049c1f..6483bc6 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -282,20 +282,9 @@
autoMask: function( options ) {
return $(this).on("focus", "input:text[data-mask]", function(e) {
- var completed, afterBlur,
- $input = $(this),
+ var $input = $(this),
dataMask = $input.data("mask");
- if( options ) {
- (completed = options.completed) && (options.completed = function() {
- completed.call( $input );
- });
-
- (afterBlur = options.afterBlur) && (options.afterBlur = function() {
- afterBlur.call( $input );
- });
- }
-
if( dataMask !== undefined && $input.mask() === undefined ) {
$input.mask( String(dataMask), options );
}
From d5588254a5a455f4926ef972a72a7d9958faa57e Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 11:17:46 -0300
Subject: [PATCH 33/38] Handling input[type='tel'] and input[type='number']
---
README.md | 12 +++++++++---
spec/AutoMask.Spec.js | 27 ++++++++++++++++++++++-----
src/jquery.maskedinput.js | 7 ++++++-
3 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index d48b154..eca8633 100644
--- a/README.md
+++ b/README.md
@@ -11,22 +11,28 @@ This is a masked input plugin for the jQuery javascript library. It allows a use
autoMask (jQuery 1.7+)
--------
-By calling $(selector).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input:text element inside the selector.
+By calling $( selector ).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input[type='text'], input[type='tel'] or input[type='number'] element inside the selector.
Example:
$(function() {
- $(document).autoMask();
+ $( document ).autoMask();
});
//The mask will be 99/99/9999
<input type="text" data-mask="99/99/9999" />
+
+//The mask will be +99 9999
+<input type="tel" data-mask="+99 9999" />
+
+//The mask will be 99 - 99
+<input type="number" data-mask="99 - 99" />
You could also pass the options in the first argument. These options will be defined once and be valid to all the masks inside the selector.
Example:
$(function() {
- $(document).autoMask({
+ $( document ).autoMask({
completed: function() {
alert("Alert executed after each mask has been completed");
}
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index 4c79311..18524fb 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -1,9 +1,10 @@
-(function() {
- var container, container2;
+(function( $ ) {
+ var container, container2, oldJqueryOn;
feature("AutoMask", function() {
beforeEach(function() {
container1 = $("").appendTo("body");
container2 = $("").appendTo("body");
+ oldJqueryOn = $.fn.on;
});
scenario("Valid container", function() {
@@ -95,17 +96,33 @@
$input.focus().mashKeys("12").blur();
});
- then("this should be correct", function() {
+ then("'this' should be correct", function() {
expect(input1[0]).toBe($input[0]);
expect(input2[0]).toBe($input[0]);
});
- })
+ });
+
+ scenario("Inputs to be handled", function() {
+
+ $.fn.on = function( eventType, selector ) {
+ then("should handle the inputs type='text', type='tel' and type='number'", function() {
+ expect( selector ).toBe("input[type='text'][data-mask], input[type='tel'][data-mask], input[type='number'][data-mask]");
+ });
+ };
+
+ when("calling an autoMask", function() {
+ $("#auto-mask-container").autoMask();
+ });
+
+ });
afterEach(function() {
container1.remove();
container2.remove();
container1 = undefined;
container2.remove();
+
+ $.fn.on = oldJqueryOn;
});
});
-})();
\ No newline at end of file
+})( jQuery );
\ No newline at end of file
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 6483bc6..62258a8 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -281,7 +281,12 @@
},
autoMask: function( options ) {
- return $(this).on("focus", "input:text[data-mask]", function(e) {
+
+ function selector( type ) {
+ return "input[type='" + type + "'][data-mask]";
+ }
+
+ return $(this).on("focus", [ selector("text"), selector("tel"), selector("number") ].join(", "), function(e) {
var $input = $(this),
dataMask = $input.data("mask");
From 044a3d32e4ad5608b1b73c6a53dbbcf6d8088a88 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 11:51:51 -0300
Subject: [PATCH 34/38] Should set the mask for elements with value that
already exists in the page
---
README.md | 1 +
spec/AutoMask.Spec.js | 36 +++++++++++++++++++++++++++++++-----
src/jquery.maskedinput.js | 12 +++++++++---
3 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index eca8633..ee292f6 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,7 @@ This is a masked input plugin for the jQuery javascript library. It allows a use
autoMask (jQuery 1.7+)
--------
By calling $( selector ).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input[type='text'], input[type='tel'] or input[type='number'] element inside the selector.
+By adding new elements with a data-mask attribute and without value autoMask will bind the mask behavior to that element.
Example:
$(function() {
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index 18524fb..a44f80b 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -1,10 +1,17 @@
(function( $ ) {
- var container, container2, oldJqueryOn;
+
+ var container, //one with mask and one without
+ container2, //one with mask
+ container3, //one with mask and value
+ oldJqueryOn, oldMask;
+
feature("AutoMask", function() {
beforeEach(function() {
- container1 = $("").appendTo("body");
- container2 = $("").appendTo("body");
+ container1 = $("").appendTo( document.body );
+ container2 = $("").appendTo( document.body );
+ container3 = $("").appendTo( document.body );
oldJqueryOn = $.fn.on;
+ oldMask = $.fn.mask;
});
scenario("Valid container", function() {
@@ -110,19 +117,38 @@
});
};
+ $.fn.mask = function() {};
+
when("calling an autoMask", function() {
$("#auto-mask-container").autoMask();
});
});
+ scenario("If an input exists", function() {
+
+ var $cont = $("#auto-mask-container3");
+ var $input = $cont.find("input");
+
+ when("calling an autoMask", function() {
+ $cont.autoMask();
+ });
+
+ then("any input with value and data-mask should be masked", function() {
+ expect( $input.val() ).toBe("9/9");
+ });
+
+ });
+
afterEach(function() {
container1.remove();
container2.remove();
- container1 = undefined;
- container2.remove();
+ container3.remove();
+
+ container1 = container2 = container3 = undefined;
$.fn.on = oldJqueryOn;
+ $.fn.mask = oldMask;
});
});
})( jQuery );
\ No newline at end of file
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 62258a8..564ee90 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -282,18 +282,24 @@
autoMask: function( options ) {
- function selector( type ) {
+ var selector = [ getSelector("text"), getSelector("tel"), getSelector("number") ].join(", ");
+ var $context = $( this );
+
+ function getSelector( type ) {
return "input[type='" + type + "'][data-mask]";
}
- return $(this).on("focus", [ selector("text"), selector("tel"), selector("number") ].join(", "), function(e) {
+ function maskIt() {
var $input = $(this),
dataMask = $input.data("mask");
if( dataMask !== undefined && $input.mask() === undefined ) {
$input.mask( String(dataMask), options );
}
- });
+ }
+
+ $context.find( selector ).each( maskIt );
+ return $context.on("focus", selector, maskIt);
}
});
})(jQuery);
From 10697d448de438edeefafee7c662b8914f42f018 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 12:22:56 -0300
Subject: [PATCH 35/38] clear previous mask event upon execution
---
spec/AutoMask.Spec.js | 38 +++++++++++++++++++++++++++++++++++++-
src/jquery.maskedinput.js | 3 ++-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/spec/AutoMask.Spec.js b/spec/AutoMask.Spec.js
index a44f80b..054a7b7 100644
--- a/spec/AutoMask.Spec.js
+++ b/spec/AutoMask.Spec.js
@@ -3,7 +3,7 @@
var container, //one with mask and one without
container2, //one with mask
container3, //one with mask and value
- oldJqueryOn, oldMask;
+ oldJqueryOn, oldJQueryOff, oldMask;
feature("AutoMask", function() {
beforeEach(function() {
@@ -11,6 +11,7 @@
container2 = $("").appendTo( document.body );
container3 = $("").appendTo( document.body );
oldJqueryOn = $.fn.on;
+ oldJQueryOff = $.fn.off;
oldMask = $.fn.mask;
});
@@ -140,6 +141,40 @@
});
+ scenario("autoMask being called twice", function() {
+
+ var $cont = $("#auto-mask-container3");
+ var countOn = 0;
+ var countOff = 0;
+
+ $.fn.on = function( eventType, selector ) {
+ if ( eventType === "focus.automask" ) {
+ countOn++;
+ }
+ };
+
+ $.fn.off = function( eventType, selector ) {
+ if ( eventType === "focus.automask" ) {
+ countOff++;
+ }
+ };
+
+ $.fn.mask = function() {};
+
+ when("calling autoMask", function() {
+ $cont.autoMask();
+ });
+
+ then("on should be called once", function() {
+ expect( countOn++ ).toBe( 1 );
+ });
+
+ then("off should be called once", function() {
+ expect( countOff++ ).toBe( 1 );
+ });
+
+ });
+
afterEach(function() {
container1.remove();
container2.remove();
@@ -148,6 +183,7 @@
container1 = container2 = container3 = undefined;
$.fn.on = oldJqueryOn;
+ $.fn.off = oldJQueryOff;
$.fn.mask = oldMask;
});
});
diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js
index 564ee90..a97fac5 100644
--- a/src/jquery.maskedinput.js
+++ b/src/jquery.maskedinput.js
@@ -299,7 +299,8 @@
}
$context.find( selector ).each( maskIt );
- return $context.on("focus", selector, maskIt);
+ $context.off("focus.automask");
+ return $context.on("focus.automask", selector, maskIt);
}
});
})(jQuery);
From fe1debce5a208e96ebe1021c734827991861434c Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 12:24:13 -0300
Subject: [PATCH 36/38] line break
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index ee292f6..e05d010 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ autoMask (jQuery 1.7+)
--------
By calling $( selector ).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input[type='text'], input[type='tel'] or input[type='number'] element inside the selector.
By adding new elements with a data-mask attribute and without value autoMask will bind the mask behavior to that element.
-Example:
+Example:
$(function() {
$( document ).autoMask();
From 047b95c9bee9410c5c02c0f6876be3ead29278d9 Mon Sep 17 00:00:00 2001
From: Fagner Brack
Date: Fri, 19 Oct 2012 12:25:10 -0300
Subject: [PATCH 37/38] Wrong line...
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e05d010..9c0919c 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,8 @@ This is a masked input plugin for the jQuery javascript library. It allows a use
autoMask (jQuery 1.7+)
--------
By calling $( selector ).autoMask() once it reads the data-mask attribute and automatically set the specified mask to any input[type='text'], input[type='tel'] or input[type='number'] element inside the selector.
-By adding new elements with a data-mask attribute and without value autoMask will bind the mask behavior to that element.
-Example:
+By adding new elements with a data-mask attribute and without value autoMask will bind the mask behavior to that element.
+Example:
$(function() {
$( document ).autoMask();
From 643de96a4a17c0c2ea3ef5ea939ae625acd5e704 Mon Sep 17 00:00:00 2001
From: Oleg Lobach
Date: Wed, 5 Dec 2012 23:53:38 +0400
Subject: [PATCH 38/38] Fixed link to old version of jQuery lib on demo pages
---
demo/datepicker.html | 2 +-
demo/index.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/demo/datepicker.html b/demo/datepicker.html
index 0b7ce77..39d4817 100644
--- a/demo/datepicker.html
+++ b/demo/datepicker.html
@@ -1,7 +1,7 @@
datepicker demo
-
+
diff --git a/demo/index.html b/demo/index.html
index c371c75..8197061 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -1,7 +1,7 @@
jQuery Mask Test
-
+
$(function() {