jquery-inputmask-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/jquery-inputmask-rails.gemspec +20 -0
- data/lib/jquery-inputmask-rails.rb +9 -0
- data/lib/jquery-inputmask-rails/engine.rb +6 -0
- data/lib/jquery-inputmask-rails/version.rb +7 -0
- data/vendor/.DS_Store +0 -0
- data/vendor/assets/.DS_Store +0 -0
- data/vendor/assets/javascripts/jquery.inputmask.date.extensions.js +479 -0
- data/vendor/assets/javascripts/jquery.inputmask.extensions.js +93 -0
- data/vendor/assets/javascripts/jquery.inputmask.js +1202 -0
- data/vendor/assets/javascripts/jquery.inputmask.numeric.extensions.js +128 -0
- metadata +79 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
/*
|
2
|
+
Input Mask plugin extensions
|
3
|
+
http://github.com/RobinHerbots/jquery.inputmask
|
4
|
+
Copyright (c) 2010 - 2012 Robin Herbots
|
5
|
+
Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
|
6
|
+
Version: 1.3.3a
|
7
|
+
|
8
|
+
Optional extensions on the jquery.inputmask base
|
9
|
+
*/
|
10
|
+
(function ($) {
|
11
|
+
//number aliases
|
12
|
+
$.extend($.inputmask.defaults.aliases, {
|
13
|
+
'decimal': {
|
14
|
+
mask: "~",
|
15
|
+
placeholder: "",
|
16
|
+
repeat: 10,
|
17
|
+
greedy: false,
|
18
|
+
numericInput: true,
|
19
|
+
digits: "*", //numer of digits
|
20
|
+
groupSeparator: ",", // | "."
|
21
|
+
groupSize: 3,
|
22
|
+
autoGroup: false,
|
23
|
+
regex: {
|
24
|
+
number: function (groupSeparator, groupSize, radixPoint, digits) {
|
25
|
+
var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, groupSeparator);
|
26
|
+
var escapedRadixPoint = $.inputmask.escapeRegex.call(this, radixPoint);
|
27
|
+
var digitExpression = isNaN(digits) ? digits : '{0,' + digits + '}';
|
28
|
+
return new RegExp("^[\+-]?(\\d+|\\d{1," + groupSize + "}((" + escapedGroupSeparator + "\\d{" + groupSize + "})?)+)(" + escapedRadixPoint + "\\d" + digitExpression + ")?$");
|
29
|
+
}
|
30
|
+
},
|
31
|
+
onKeyDown: function (e, opts) {
|
32
|
+
var $input = $(this), input = this;
|
33
|
+
if (e.keyCode == opts.keyCode.TAB) {
|
34
|
+
var nptStr = input._valueGet();
|
35
|
+
var radixPosition = nptStr.indexOf(opts.radixPoint);
|
36
|
+
if (radixPosition != -1) {
|
37
|
+
for (var i = 1; i < opts.digits; i++) {
|
38
|
+
if (nptStr[radixPosition + i]) nptStr = nptStr + "0";
|
39
|
+
}
|
40
|
+
if (nptStr !== $input.val()) {
|
41
|
+
$input.val(nptStr);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
},
|
46
|
+
definitions: {
|
47
|
+
'~': { //real number
|
48
|
+
validator: function (chrs, buffer, pos, strict, opts) {
|
49
|
+
if (chrs == "") return false;
|
50
|
+
var cbuf = strict ? buffer.slice(0, pos) : buffer.slice();
|
51
|
+
cbuf.splice(pos, 0, chrs);
|
52
|
+
var bufferStr = cbuf.join('');
|
53
|
+
if (opts.autoGroup) //strip groupseparator
|
54
|
+
bufferStr = bufferStr.replace(new RegExp("\\" + opts.groupSeparator, "g"), '');
|
55
|
+
var isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits).test(bufferStr);
|
56
|
+
if (!isValid) {
|
57
|
+
//let's help the regex a bit
|
58
|
+
bufferStr += "0";
|
59
|
+
isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits).test(bufferStr);
|
60
|
+
if (!isValid) {
|
61
|
+
//make a valid group
|
62
|
+
var lastGroupSeparator = bufferStr.lastIndexOf(opts.groupSeparator);
|
63
|
+
for (i = bufferStr.length - lastGroupSeparator; i <= 3; i++) {
|
64
|
+
bufferStr += "0";
|
65
|
+
}
|
66
|
+
|
67
|
+
isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits).test(bufferStr);
|
68
|
+
if (!isValid && !strict) {
|
69
|
+
if (chrs == opts.radixPoint) {
|
70
|
+
isValid = opts.regex.number(opts.groupSeparator, opts.groupSize, opts.radixPoint, opts.digits).test("0" + bufferStr + "0");
|
71
|
+
if (isValid) {
|
72
|
+
buffer[pos] = "0";
|
73
|
+
pos++;
|
74
|
+
return { "pos": pos };
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
if (isValid != false && !strict) {
|
82
|
+
var cbuf = buffer.slice();
|
83
|
+
cbuf.splice(pos, 0, "?"); //set position indicator
|
84
|
+
var bufVal = cbuf.join('');
|
85
|
+
if (opts.autoGroup || bufVal.indexOf(opts.groupSeparator) != -1) {
|
86
|
+
bufVal = bufVal.replace(new RegExp("\\" + opts.groupSeparator, "g"), '');
|
87
|
+
var reg = new RegExp('(-?[\\d?]+)([\\d?]{' + opts.groupSize + '})');
|
88
|
+
while (reg.test(bufVal)) {
|
89
|
+
bufVal = bufVal.replace(reg, '$1' + opts.groupSeparator + '$2');
|
90
|
+
}
|
91
|
+
}
|
92
|
+
buffer.length = bufVal.length; //align the length
|
93
|
+
for (var i = 0, l = bufVal.length; i < l; i++) {
|
94
|
+
buffer[i] = bufVal.charAt(i);
|
95
|
+
}
|
96
|
+
var newPos = buffer.indexOf("?");
|
97
|
+
buffer.splice(newPos, 1);
|
98
|
+
|
99
|
+
return { "pos": newPos };
|
100
|
+
}
|
101
|
+
return isValid;
|
102
|
+
},
|
103
|
+
cardinality: 1,
|
104
|
+
prevalidator: null
|
105
|
+
}
|
106
|
+
},
|
107
|
+
insertMode: true,
|
108
|
+
autoUnmask: false
|
109
|
+
},
|
110
|
+
'non-negative-decimal': {
|
111
|
+
regex: {
|
112
|
+
number: function (groupSeparator, groupSize, radixPoint, digits) {
|
113
|
+
var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, groupSeparator);
|
114
|
+
var escapedRadixPoint = $.inputmask.escapeRegex.call(this, radixPoint);
|
115
|
+
var digitExpression = isNaN(digits) ? digits : '{0,' + digits + '}'
|
116
|
+
return new RegExp("^[\+]?(\\d+|\\d{1," + groupSize + "}((" + escapedGroupSeparator + "\\d{" + groupSize + "})?)+)(" + escapedRadixPoint + "\\d" + digitExpression + ")?$");
|
117
|
+
}
|
118
|
+
},
|
119
|
+
alias: "decimal"
|
120
|
+
},
|
121
|
+
'integer': {
|
122
|
+
regex: {
|
123
|
+
number: function (groupSeparator, groupSize) { return new RegExp("^([\+\-]?\\d*)$"); }
|
124
|
+
},
|
125
|
+
alias: "decimal"
|
126
|
+
}
|
127
|
+
});
|
128
|
+
})(jQuery);
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-inputmask-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marcos Nogueira
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-02-19 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: An inputmask helps the user with the input by ensuring a predefined format. This can be usefull for dates, numerics, phone numbers...
|
22
|
+
email:
|
23
|
+
- marcosnogueiraalves@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .DS_Store
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- jquery-inputmask-rails.gemspec
|
36
|
+
- lib/jquery-inputmask-rails.rb
|
37
|
+
- lib/jquery-inputmask-rails/engine.rb
|
38
|
+
- lib/jquery-inputmask-rails/version.rb
|
39
|
+
- vendor/.DS_Store
|
40
|
+
- vendor/assets/.DS_Store
|
41
|
+
- vendor/assets/javascripts/jquery.inputmask.date.extensions.js
|
42
|
+
- vendor/assets/javascripts/jquery.inputmask.extensions.js
|
43
|
+
- vendor/assets/javascripts/jquery.inputmask.js
|
44
|
+
- vendor/assets/javascripts/jquery.inputmask.numeric.extensions.js
|
45
|
+
homepage: http://github.com/marcosnogueira/jquery-inputmask-rails
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: jquery-inputmask-rails
|
74
|
+
rubygems_version: 1.8.10
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Integrate the jQuery InputMask plugin into the Rails asset pipeline
|
78
|
+
test_files: []
|
79
|
+
|