From 42df7d2f6225cc68e9110d832e305a9b7258df23 Mon Sep 17 00:00:00 2001
From: Rob Ballou
Date: Thu, 20 Oct 2011 13:48:14 -0500
Subject: [PATCH 01/31] Fixed an issue where numeric throws errors if the field
is empty.
---
numeric/jquery.numeric.js | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 3ce51cf..7811c14 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -75,10 +75,11 @@ $.fn.numeric.keypress = function(e)
// if a number was not pressed
if(key < 48 || key > 57)
{
+ var value = $(this).val();
/* '-' only allowed at start and if negative numbers allowed */
- if(this.value.indexOf("-") != 0 && negative && key == 45 && (this.value.length == 0 || ($.fn.getSelectionStart(this)) == 0)) return true;
+ if(value.indexOf("-") != 0 && negative && key == 45 && (value.length == 0 || ($.fn.getSelectionStart(this)) == 0)) return true;
/* only one decimal separator allowed */
- if(decimal && key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1)
+ if(decimal && key == decimal.charCodeAt(0) && value.indexOf(decimal) != -1)
{
allow = false;
}
@@ -119,7 +120,7 @@ $.fn.numeric.keypress = function(e)
// if key pressed is the decimal and it is not already in the field
if(decimal && key == decimal.charCodeAt(0))
{
- if(this.value.indexOf(decimal) == -1)
+ if(value.indexOf(decimal) == -1)
{
allow = true;
}
@@ -138,8 +139,8 @@ $.fn.numeric.keypress = function(e)
$.fn.numeric.keyup = function(e)
{
- var val = this.value;
- if(val.length > 0)
+ var val = $(this).value;
+ if(val && val.length > 0)
{
// get carat (cursor) position
var carat = $.fn.getSelectionStart(this);
From 3720cc651ecd43d6f79549fe7d4a8ac52ce50f6c Mon Sep 17 00:00:00 2001
From: Syamsundar Bhimavarapu
Date: Tue, 25 Oct 2011 16:35:56 -0700
Subject: [PATCH 02/31] Declaring and initializing startindex to '0'. It is
throwing a not-defined error.
---
selectboxes/jquery.selectboxes.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/selectboxes/jquery.selectboxes.js b/selectboxes/jquery.selectboxes.js
index 033b7a5..8f99105 100644
--- a/selectboxes/jquery.selectboxes.js
+++ b/selectboxes/jquery.selectboxes.js
@@ -74,7 +74,7 @@ $.fn.addOption = function()
// multiple items
var m = false;
// other variables
- var items, v, t;
+ var items, v, t, startindex = 0;
if(typeof(a[0]) == "object")
{
m = true;
From f0e0dde6340f75be91068e4c4b4467db88b745fb Mon Sep 17 00:00:00 2001
From: SamWM
Date: Thu, 3 Nov 2011 13:54:18 +0000
Subject: [PATCH 03/31] Updating version number for selectboxes
---
selectboxes/jquery.selectboxes.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/selectboxes/jquery.selectboxes.js b/selectboxes/jquery.selectboxes.js
index 8f99105..d98f01e 100644
--- a/selectboxes/jquery.selectboxes.js
+++ b/selectboxes/jquery.selectboxes.js
@@ -4,7 +4,7 @@
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
- * Version 2.2.5
+ * Version 2.2.6
* Demo: http://www.texotela.co.uk/code/jquery/select/
*
*
From 0a5ee8e78122a6dba4034ab0f1d6c568a9f1dd65 Mon Sep 17 00:00:00 2001
From: SamWM
Date: Thu, 3 Nov 2011 13:56:09 +0000
Subject: [PATCH 04/31] Updating version number for numeric plugin, to indicate
a bug has been fixed
---
numeric/jquery.numeric.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 7811c14..400f935 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -4,7 +4,7 @@
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
- * Version 1.3
+ * Version 1.3.1
* Demo: http://www.texotela.co.uk/code/jquery/numeric/
*
*/
From 72335dc52932c19175b9b3b50cc76b1c52b373e3 Mon Sep 17 00:00:00 2001
From: Anthony Accioly
Date: Fri, 30 Mar 2012 18:17:46 -0300
Subject: [PATCH 05/31] Fixed the regex for numeric plugin onblur validation
---
numeric/jquery.numeric.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 400f935..0a448ec 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -228,7 +228,7 @@ $.fn.numeric.blur = function()
var val = this.value;
if(val != "")
{
- var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+");
+ var re = new RegExp("^\\d+$|^\\d*" + decimal + "\\d+$");
if(!re.exec(val))
{
callback.apply(this);
@@ -277,4 +277,4 @@ $.fn.setSelection = function(o, p)
}
}
-})(jQuery);
\ No newline at end of file
+})(jQuery);
From d0b8625f375153e7afc463caa65b5d155579e4d9 Mon Sep 17 00:00:00 2001
From: Igor Rzegocki
Date: Mon, 7 May 2012 13:45:44 +0200
Subject: [PATCH 06/31] Small fixes, to make JSLint complain less
---
numeric/jquery.numeric.js | 64 +++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 32 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 0a448ec..d07520f 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -19,7 +19,7 @@
* @param callback A function that runs if the number is not valid (fires onblur)
* @author Sam Collett (http://www.texotela.co.uk)
* @example $(".numeric").numeric();
- * @example $(".numeric").numeric(","); // use , as separater
+ * @example $(".numeric").numeric(","); // use , as separator
* @example $(".numeric").numeric({ decimal : "," }); // use , as separator
* @example $(".numeric").numeric({ negative : false }); // do not allow negative values
* @example $(".numeric").numeric(null, callback); // use default values, pass on the 'callback' function
@@ -33,16 +33,16 @@ $.fn.numeric = function(config, callback)
}
config = config || {};
// if config.negative undefined, set to true (default is to allow negative numbers)
- if(typeof config.negative == "undefined") config.negative = true;
+ if(typeof config.negative == "undefined") { config.negative = true; }
// set decimal point
var decimal = (config.decimal === false) ? "" : config.decimal || ".";
// allow negatives
var negative = (config.negative === true) ? true : false;
// callback function
- var callback = typeof callback == "function" ? callback : function(){};
+ callback = (typeof(callback) == "function" ? callback : function() {});
// set data and methods
return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur);
-}
+};
$.fn.numeric.keypress = function(e)
{
@@ -62,22 +62,22 @@ $.fn.numeric.keypress = function(e)
}
var allow = false;
// allow Ctrl+A
- if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) return true;
+ if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) { return true; }
// allow Ctrl+X (cut)
- if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) return true;
+ if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) { return true; }
// allow Ctrl+C (copy)
- if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) return true;
+ if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) { return true; }
// allow Ctrl+Z (undo)
- if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) return true;
+ if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) { return true; }
// allow or deny Ctrl+V (paste), Shift+Ins
- if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */
- || (e.shiftKey && key == 45)) return true;
+ if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */ ||
+ (e.shiftKey && key == 45)) { return true; }
// if a number was not pressed
if(key < 48 || key > 57)
{
var value = $(this).val();
/* '-' only allowed at start and if negative numbers allowed */
- if(value.indexOf("-") != 0 && negative && key == 45 && (value.length == 0 || ($.fn.getSelectionStart(this)) == 0)) return true;
+ if(value.indexOf("-") !== 0 && negative && key == 45 && (value.length === 0 || parseInt($.fn.getSelectionStart(this), 10) === 0)) { return true; }
/* only one decimal separator allowed */
if(decimal && key == decimal.charCodeAt(0) && value.indexOf(decimal) != -1)
{
@@ -104,14 +104,14 @@ $.fn.numeric.keypress = function(e)
if(typeof e.charCode != "undefined")
{
// special keys have 'keyCode' and 'which' the same (e.g. backspace)
- if(e.keyCode == e.which && e.which != 0)
+ if(e.keyCode == e.which && e.which !== 0)
{
allow = true;
// . and delete share the same code, don't allow . (will be set to true later if it is the decimal point)
- if(e.which == 46) allow = false;
+ if(e.which == 46) { allow = false; }
}
// or keyCode != 0 and 'charCode'/'which' = 0
- else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0)
+ else if(e.keyCode !== 0 && e.charCode === 0 && e.which === 0)
{
allow = true;
}
@@ -135,7 +135,7 @@ $.fn.numeric.keypress = function(e)
allow = true;
}
return allow;
-}
+};
$.fn.numeric.keyup = function(e)
{
@@ -149,12 +149,12 @@ $.fn.numeric.keyup = function(e)
var negative = $.data(this, "numeric.negative");
// prepend a 0 if necessary
- if(decimal != "")
+ if(decimal !== "" && decimal !== null)
{
// find decimal point
var dot = val.indexOf(decimal);
// if dot at start, add 0 before
- if(dot == 0)
+ if(dot === 0)
{
this.value = "0" + val;
}
@@ -175,12 +175,12 @@ $.fn.numeric.keyup = function(e)
{
var ch = val.charAt(i);
// remove '-' if it is in the wrong place
- if(i != 0 && ch == "-")
+ if(i !== 0 && ch == "-")
{
val = val.substring(0, i) + val.substring(i + 1);
}
// remove character if it is at the start, a '-' and negatives aren't allowed
- else if(i == 0 && !negative && ch == "-")
+ else if(i === 0 && !negative && ch == "-")
{
val = val.substring(1);
}
@@ -205,13 +205,13 @@ $.fn.numeric.keyup = function(e)
var firstDecimal = val.indexOf(decimal);
if(firstDecimal > 0)
{
- for(var i = length - 1; i > firstDecimal; i--)
+ for(var k = length - 1; k > firstDecimal; k--)
{
- var ch = val.charAt(i);
+ var chch = val.charAt(k);
// remove decimal character
- if(ch == decimal)
+ if(chch == decimal)
{
- val = val.substring(0, i) + val.substring(i + 1);
+ val = val.substring(0, k) + val.substring(k + 1);
}
}
}
@@ -219,14 +219,14 @@ $.fn.numeric.keyup = function(e)
this.value = val;
$.fn.setSelection(this, carat);
}
-}
+};
$.fn.numeric.blur = function()
{
var decimal = $.data(this, "numeric.decimal");
var callback = $.data(this, "numeric.callback");
var val = this.value;
- if(val != "")
+ if(val !== "")
{
var re = new RegExp("^\\d+$|^\\d*" + decimal + "\\d+$");
if(!re.exec(val))
@@ -234,12 +234,12 @@ $.fn.numeric.blur = function()
callback.apply(this);
}
}
-}
+};
$.fn.removeNumeric = function()
{
return this.data("numeric.decimal", null).data("numeric.negative", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).unbind("blur", $.fn.numeric.blur);
-}
+};
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
$.fn.getSelectionStart = function(o)
@@ -248,16 +248,16 @@ $.fn.getSelectionStart = function(o)
{
var r = document.selection.createRange().duplicate();
r.moveEnd('character', o.value.length);
- if (r.text == '') return o.value.length;
+ if (r.text === '') { return o.value.length; }
return o.value.lastIndexOf(r.text);
- } else return o.selectionStart;
-}
+ } else { return o.selectionStart; }
+};
// set the selection, o is the object (input), p is the position ([start, end] or just start)
$.fn.setSelection = function(o, p)
{
// if p is number, start and end are the same
- if(typeof p == "number") p = [p, p];
+ if(typeof p == "number") { p = [p, p]; }
// only set if p is an array of length 2
if(p && p.constructor == Array && p.length == 2)
{
@@ -275,6 +275,6 @@ $.fn.setSelection = function(o, p)
o.setSelectionRange(p[0], p[1]);
}
}
-}
+};
})(jQuery);
From 5f669df5c1f55bc98fb750dd87e0b6df5bbd2e57 Mon Sep 17 00:00:00 2001
From: Mikhail Savkin
Date: Thu, 1 Nov 2012 16:30:51 +0400
Subject: [PATCH 07/31] Fix a typo in call to jQuery val() function
---
numeric/jquery.numeric.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index d07520f..417f26c 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -139,7 +139,7 @@ $.fn.numeric.keypress = function(e)
$.fn.numeric.keyup = function(e)
{
- var val = $(this).value;
+ var val = $(this).val();
if(val && val.length > 0)
{
// get carat (cursor) position
From 105681f13e69b317fbcebe4992ddc395bbcfaa40 Mon Sep 17 00:00:00 2001
From: Tybearius
Date: Thu, 11 Apr 2013 11:13:56 -0300
Subject: [PATCH 08/31] Update jquery.selectboxes.js
Fixed for in loop in addOption for use with a prototype based library.
---
selectboxes/jquery.selectboxes.js | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/selectboxes/jquery.selectboxes.js b/selectboxes/jquery.selectboxes.js
index d98f01e..37cc6b7 100644
--- a/selectboxes/jquery.selectboxes.js
+++ b/selectboxes/jquery.selectboxes.js
@@ -110,8 +110,10 @@ $.fn.addOption = function()
{
for(var item in items)
{
- add(this, item, items[item], sO, startindex);
- startindex += 1;
+ if(items.hasOwnProperty(item)){
+ add(this, item, items[item], sO, startindex);
+ startindex += 1;
+ }
}
}
else
@@ -550,4 +552,4 @@ $.fn.selectedOptions = function()
return this.find("option:selected");
};
-})(jQuery);
\ No newline at end of file
+})(jQuery);
From 8d1b3289569fcaeff09e5c0effdef6d294259077 Mon Sep 17 00:00:00 2001
From: qeny
Date: Sat, 25 May 2013 15:03:57 -0600
Subject: [PATCH 09/31] Update jquery.numeric.js, saving selection end,
allowing keyboard ctrl+A and keyboard selection
---
numeric/jquery.numeric.js | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 417f26c..bfc79c1 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -144,6 +144,7 @@ $.fn.numeric.keyup = function(e)
{
// get carat (cursor) position
var carat = $.fn.getSelectionStart(this);
+ var selectionEnd = $.fn.getSelectionEnd(this);
// get decimal character and determine if negatives are allowed
var decimal = $.data(this, "numeric.decimal");
var negative = $.data(this, "numeric.negative");
@@ -217,7 +218,7 @@ $.fn.numeric.keyup = function(e)
}
// set the value and prevent the cursor moving to the end
this.value = val;
- $.fn.setSelection(this, carat);
+ $.fn.setSelection(this, [carat, selectionEnd]);
}
};
@@ -253,6 +254,16 @@ $.fn.getSelectionStart = function(o)
} else { return o.selectionStart; }
};
+// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
+$.fn.getSelectionEnd = function(o)
+{
+ if (o.createTextRange) {
+ var r = document.selection.createRange().duplicate()
+ r.moveStart('character', -o.value.length)
+ return r.text.length
+ } else return o.selectionEnd
+}
+
// set the selection, o is the object (input), p is the position ([start, end] or just start)
$.fn.setSelection = function(o, p)
{
From d2c1e6d718d670bc58a647c295770be8299acce3 Mon Sep 17 00:00:00 2001
From: Tyler Sanborn
Date: Fri, 23 Aug 2013 15:17:53 -0400
Subject: [PATCH 10/31] Modified addOption to work with an array of
{"val":"text"} objects
This will allow for options to be kept in order when returned in an AJAX request. Chrome organizes objects by their keys.
---
selectboxes/jquery.selectboxes.js | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/selectboxes/jquery.selectboxes.js b/selectboxes/jquery.selectboxes.js
index 37cc6b7..5262238 100644
--- a/selectboxes/jquery.selectboxes.js
+++ b/selectboxes/jquery.selectboxes.js
@@ -108,13 +108,17 @@ $.fn.addOption = function()
if(this.nodeName.toLowerCase() != "select") return;
if(m)
{
- for(var item in items)
- {
- if(items.hasOwnProperty(item)){
- add(this, item, items[item], sO, startindex);
- startindex += 1;
- }
- }
+ var sel = this;
+ jQuery.each(items, function(val, text){
+ if(typeof(text) == "object"){
+ jQuery.each(text, function(k,v){
+ val = k;
+ text = v;
+ });
+ }
+ add(sel, val, text, sO, startindex);
+ startindex += 1;
+ });
}
else
{
From 4864cc800ebc912f122fe2647e1fab8fe886229d Mon Sep 17 00:00:00 2001
From: Tyler Sanborn
Date: Fri, 23 Aug 2013 15:18:29 -0400
Subject: [PATCH 11/31] Update jquery.selectboxes.js
---
selectboxes/jquery.selectboxes.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/selectboxes/jquery.selectboxes.js b/selectboxes/jquery.selectboxes.js
index 5262238..4efe832 100644
--- a/selectboxes/jquery.selectboxes.js
+++ b/selectboxes/jquery.selectboxes.js
@@ -110,14 +110,14 @@ $.fn.addOption = function()
{
var sel = this;
jQuery.each(items, function(val, text){
- if(typeof(text) == "object"){
- jQuery.each(text, function(k,v){
- val = k;
- text = v;
- });
- }
- add(sel, val, text, sO, startindex);
- startindex += 1;
+ if(typeof(text) == "object"){
+ jQuery.each(text, function(k,v){
+ val = k;
+ text = v;
+ });
+ }
+ add(sel, val, text, sO, startindex);
+ startindex += 1;
});
}
else
From 5a977105ad883e147d8572c9d4636c0492d50a4b Mon Sep 17 00:00:00 2001
From: nmatpt
Date: Mon, 7 Oct 2013 23:48:27 +0100
Subject: [PATCH 12/31] Update jquery.numeric.js
Fixes compatibility with IE<9: replaces indexOf with inArray
---
numeric/jquery.numeric.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index bfc79c1..fb25ed8 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -77,9 +77,9 @@ $.fn.numeric.keypress = function(e)
{
var value = $(this).val();
/* '-' only allowed at start and if negative numbers allowed */
- if(value.indexOf("-") !== 0 && negative && key == 45 && (value.length === 0 || parseInt($.fn.getSelectionStart(this), 10) === 0)) { return true; }
+ if($.inArray('-', value.split('')) !== 0 && negative && key == 45 && (value.length === 0 || parseInt($.fn.getSelectionStart(this), 10) === 0)) { return true; }
/* only one decimal separator allowed */
- if(decimal && key == decimal.charCodeAt(0) && value.indexOf(decimal) != -1)
+ if(decimal && key == decimal.charCodeAt(0) && $.inArray(decimal, value.split('')) != -1)
{
allow = false;
}
@@ -120,7 +120,7 @@ $.fn.numeric.keypress = function(e)
// if key pressed is the decimal and it is not already in the field
if(decimal && key == decimal.charCodeAt(0))
{
- if(value.indexOf(decimal) == -1)
+ if($.inArray(decimal, value.split('')) == -1)
{
allow = true;
}
@@ -153,7 +153,7 @@ $.fn.numeric.keyup = function(e)
if(decimal !== "" && decimal !== null)
{
// find decimal point
- var dot = val.indexOf(decimal);
+ var dot = $.inArray(decimal, val.split(''));
// if dot at start, add 0 before
if(dot === 0)
{
@@ -203,7 +203,7 @@ $.fn.numeric.keyup = function(e)
}
}
// remove extra decimal characters
- var firstDecimal = val.indexOf(decimal);
+ var firstDecimal = $.inArray(decimal, val.split(''));
if(firstDecimal > 0)
{
for(var k = length - 1; k > firstDecimal; k--)
From c48f0ac367bc97cb1eb91ac3d59ad9683f1826e3 Mon Sep 17 00:00:00 2001
From: adam brill
Date: Wed, 12 Mar 2014 15:49:29 -0700
Subject: [PATCH 13/31] fix error with numeric inputs
---
numeric/jquery.numeric.js | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index bfc79c1..f153c42 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -245,7 +245,10 @@ $.fn.removeNumeric = function()
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
$.fn.getSelectionStart = function(o)
{
- if (o.createTextRange)
+ if(o.type === "number"){
+ return undefined;
+ }
+ else if (o.createTextRange)
{
var r = document.selection.createRange().duplicate();
r.moveEnd('character', o.value.length);
@@ -257,7 +260,10 @@ $.fn.getSelectionStart = function(o)
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
$.fn.getSelectionEnd = function(o)
{
- if (o.createTextRange) {
+ if(o.type === "number"){
+ return undefined;
+ }
+ else if (o.createTextRange) {
var r = document.selection.createRange().duplicate()
r.moveStart('character', -o.value.length)
return r.text.length
@@ -272,7 +278,10 @@ $.fn.setSelection = function(o, p)
// only set if p is an array of length 2
if(p && p.constructor == Array && p.length == 2)
{
- if (o.createTextRange)
+ if(o.type === "number") {
+ o.focus();
+ }
+ else if (o.createTextRange)
{
var r = o.createTextRange();
r.collapse(true);
@@ -288,4 +297,4 @@ $.fn.setSelection = function(o, p)
}
};
-})(jQuery);
+})(jQuery);
\ No newline at end of file
From a53f82044759d29ff30bac698b09e3202b456545 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joaqu=C3=ADn=20Gatica?=
Date: Fri, 21 Mar 2014 17:09:27 -0300
Subject: [PATCH 14/31] Catch errors in selectionStart and setSelectionRange in
latest Chrome for input types which doesn't support them
---
numeric/jquery.numeric.js | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index bfc79c1..07d32a4 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -251,7 +251,10 @@ $.fn.getSelectionStart = function(o)
r.moveEnd('character', o.value.length);
if (r.text === '') { return o.value.length; }
return o.value.lastIndexOf(r.text);
- } else { return o.selectionStart; }
+ } else {
+ try { return o.selectionStart; }
+ catch(e) { return 0; }
+ }
};
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
@@ -280,11 +283,16 @@ $.fn.setSelection = function(o, p)
r.moveEnd('character', p[1]);
r.select();
}
- else if(o.setSelectionRange)
- {
- o.focus();
- o.setSelectionRange(p[0], p[1]);
- }
+ else {
+ o.focus();
+ try{
+ if(o.setSelectionRange)
+ {
+ o.setSelectionRange(p[0], p[1]);
+ }
+ } catch(e) {
+ }
+ }
}
};
From dc6f09f2723032cd8994a09e0eda3dcf5d0aec15 Mon Sep 17 00:00:00 2001
From: damintsew
Date: Mon, 9 Jun 2014 10:53:15 +0400
Subject: [PATCH 15/31] Fixed bun in IE 11. Where document.selection is
deprecated
---
numeric/jquery.numeric.js | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index bfc79c1..4b5366d 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -247,12 +247,20 @@ $.fn.getSelectionStart = function(o)
{
if (o.createTextRange)
{
- var r = document.selection.createRange().duplicate();
- r.moveEnd('character', o.value.length);
- if (r.text === '') { return o.value.length; }
+ var r;
+ if(typeof document.selection == "undefined") {
+ //On IE < 9 && IE >= 11 : "document.selection" is deprecated and you should use "document.getSelection()"
+ //https://github.com/SamWM/jQuery-Plugins/issues/62
+ r = document.getSelection();
+ } else {
+ r = document.selection.createRange().duplicate();
+ r.moveEnd('character', o.value.length);
+ }
+ if (r.text == '') return o.value.length;
+
return o.value.lastIndexOf(r.text);
- } else { return o.selectionStart; }
-};
+ } else return o.selectionStart;
+}
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
$.fn.getSelectionEnd = function(o)
From 21869b026ac9723fbd561d8755a4fba45c53d76c Mon Sep 17 00:00:00 2001
From: damintsew
Date: Mon, 9 Jun 2014 10:57:12 +0400
Subject: [PATCH 16/31] small fix
---
numeric/jquery.numeric.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 4b5366d..c7dd25e 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -260,7 +260,7 @@ $.fn.getSelectionStart = function(o)
return o.value.lastIndexOf(r.text);
} else return o.selectionStart;
-}
+};
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
$.fn.getSelectionEnd = function(o)
From 3d90fc611f8f2895f2c555ace7b03ba077f7c745 Mon Sep 17 00:00:00 2001
From: damintsew
Date: Mon, 9 Jun 2014 10:58:09 +0400
Subject: [PATCH 17/31] Fixed code style
---
numeric/jquery.numeric.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index c7dd25e..a6c188b 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -259,7 +259,7 @@ $.fn.getSelectionStart = function(o)
if (r.text == '') return o.value.length;
return o.value.lastIndexOf(r.text);
- } else return o.selectionStart;
+ } else { return o.selectionStart; }
};
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
From 286265d1f2fce99a1619001454be40ac77d00f3e Mon Sep 17 00:00:00 2001
From: kmjones77
Date: Fri, 13 Jun 2014 12:03:05 +0100
Subject: [PATCH 18/31] Update jquery.numeric.js
I suggest that carat and selectionEnd are incremented if a 0 is prepended to the beginning of the value
---
numeric/jquery.numeric.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index bfc79c1..32ec279 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -158,11 +158,15 @@ $.fn.numeric.keyup = function(e)
if(dot === 0)
{
this.value = "0" + val;
+ carat++;
+ selectionEnd++;
}
// if dot at position 1, check if there is a - symbol before it
if(dot == 1 && val.charAt(0) == "-")
{
this.value = "-0" + val.substring(1);
+ carat++;
+ selectionEnd++;
}
val = this.value;
}
From 442239279d213100e9be99a3bff6a2cce12b5031 Mon Sep 17 00:00:00 2001
From: SamWM
Date: Fri, 27 Jun 2014 11:08:11 +0100
Subject: [PATCH 19/31] Update jquery.numeric.js
---
numeric/jquery.numeric.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 1599734..96e800f 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -1,10 +1,10 @@
/*
*
- * Copyright (c) 2006-2011 Sam Collett (http://www.texotela.co.uk)
+ * Copyright (c) 2006-2014 Sam Collett (http://www.texotela.co.uk)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
- * Version 1.3.1
+ * Version 1.4
* Demo: http://www.texotela.co.uk/code/jquery/numeric/
*
*/
From 3a80bec910534b0c0cc4840414ee296b49b24767 Mon Sep 17 00:00:00 2001
From: Jorge Plaza
Date: Tue, 26 Aug 2014 01:30:02 -0430
Subject: [PATCH 20/31] Decimal places configuration. Several fixes: Callback
function is not called when a negative numbers is introduced, removeNumeric
removes listeners for keyUp event. Test page improved, with all examples
working as expected.
---
numeric/jquery.numeric.js | 36 +++++++++++++++++++++++++++++++-----
numeric/test.html | 12 ++++++++++--
2 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/numeric/jquery.numeric.js b/numeric/jquery.numeric.js
index 96e800f..de699c1 100644
--- a/numeric/jquery.numeric.js
+++ b/numeric/jquery.numeric.js
@@ -22,6 +22,7 @@
* @example $(".numeric").numeric(","); // use , as separator
* @example $(".numeric").numeric({ decimal : "," }); // use , as separator
* @example $(".numeric").numeric({ negative : false }); // do not allow negative values
+ * @example $(".numeric").numeric({ decimalPlaces : 2 }); // only allow 2 decimal places
* @example $(".numeric").numeric(null, callback); // use default values, pass on the 'callback' function
*
*/
@@ -29,7 +30,7 @@ $.fn.numeric = function(config, callback)
{
if(typeof config === 'boolean')
{
- config = { decimal: config };
+ config = { decimal: config, negative: true, decimalPlaces: -1 };
}
config = config || {};
// if config.negative undefined, set to true (default is to allow negative numbers)
@@ -38,10 +39,12 @@ $.fn.numeric = function(config, callback)
var decimal = (config.decimal === false) ? "" : config.decimal || ".";
// allow negatives
var negative = (config.negative === true) ? true : false;
+ // set decimal places
+ var decimalPlaces = (typeof config.decimalPlaces == "undefined") ? -1 : config.decimalPlaces;
// callback function
callback = (typeof(callback) == "function" ? callback : function() {});
// set data and methods
- return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur);
+ return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).data("numeric.decimalPlaces", decimalPlaces).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur);
};
$.fn.numeric.keypress = function(e)
@@ -49,6 +52,7 @@ $.fn.numeric.keypress = function(e)
// get decimal character and determine if negatives are allowed
var decimal = $.data(this, "numeric.decimal");
var negative = $.data(this, "numeric.negative");
+ var decimalPlaces = $.data(this, "numeric.decimalPlaces");
// get the key that was pressed
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
// allow enter/return key (only when in an input box)
@@ -133,6 +137,15 @@ $.fn.numeric.keypress = function(e)
else
{
allow = true;
+ // remove extra decimal places
+ if(decimal && decimalPlaces > 0)
+ {
+ var dot = $.inArray(decimal, $(this).val().split(''));
+ if (dot >= 0 && $(this).val().length > dot + decimalPlaces) {
+ allow = false;
+ }
+ }
+
}
return allow;
};
@@ -148,6 +161,7 @@ $.fn.numeric.keyup = function(e)
// get decimal character and determine if negatives are allowed
var decimal = $.data(this, "numeric.decimal");
var negative = $.data(this, "numeric.negative");
+ var decimalPlaces = $.data(this, "numeric.decimalPlaces");
// prepend a 0 if necessary
if(decimal !== "" && decimal !== null)
@@ -220,6 +234,17 @@ $.fn.numeric.keyup = function(e)
}
}
}
+
+ // remove extra decimal places
+ if(decimal && decimalPlaces > 0)
+ {
+ var dot = $.inArray(decimal, val.split(''));
+ if (dot >= 0)
+ {
+ val = val.substring(0, dot + decimalPlaces + 1);
+ selectionEnd = Math.min(val.length, selectionEnd);
+ }
+ }
// set the value and prevent the cursor moving to the end
this.value = val;
$.fn.setSelection(this, [carat, selectionEnd]);
@@ -230,10 +255,11 @@ $.fn.numeric.blur = function()
{
var decimal = $.data(this, "numeric.decimal");
var callback = $.data(this, "numeric.callback");
+ var negative = $.data(this, "numeric.negative");
var val = this.value;
- if(val !== "")
+ if(val !== "" && decimal)
{
- var re = new RegExp("^\\d+$|^\\d*" + decimal + "\\d+$");
+ var re = new RegExp(negative?"-?":"" + "^\\d+$|^\\d*" + decimal + "\\d+$");
if(!re.exec(val))
{
callback.apply(this);
@@ -243,7 +269,7 @@ $.fn.numeric.blur = function()
$.fn.removeNumeric = function()
{
- return this.data("numeric.decimal", null).data("numeric.negative", null).data("numeric.callback", null).unbind("keypress", $.fn.numeric.keypress).unbind("blur", $.fn.numeric.blur);
+ return this.data("numeric.decimal", null).data("numeric.negative", null).data("numeric.callback", null).data("numeric.decimalPlaces", null).unbind("keypress", $.fn.numeric.keypress).unbind("keyup", $.fn.numeric.keyup).unbind("blur", $.fn.numeric.blur);
};
// Based on code from http://javascript.nwbox.com/cursor_position/ (Diego Perini )
diff --git a/numeric/test.html b/numeric/test.html
index 631dbfc..54fe2df 100644
--- a/numeric/test.html
+++ b/numeric/test.html
@@ -8,12 +8,19 @@