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 ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jquery-inputmask-rails.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jquery-inputmask-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jquery-inputmask-rails"
7
+ s.version = Jquery::Inputmask::Rails::VERSION
8
+ s.authors = ["Marcos Nogueira"]
9
+ s.email = ["marcosnogueiraalves@gmail.com"]
10
+ s.homepage = "http://github.com/marcosnogueira/jquery-inputmask-rails"
11
+ s.summary = %q{Integrate the jQuery InputMask plugin into the Rails asset pipeline}
12
+ s.description = %q{An inputmask helps the user with the input by ensuring a predefined format. This can be usefull for dates, numerics, phone numbers...}
13
+
14
+ s.rubyforge_project = "jquery-inputmask-rails"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,9 @@
1
+ require "jquery-inputmask-rails/version"
2
+
3
+ module Jquery
4
+ module Inputmask
5
+ module Rails
6
+ require "jquery-inputmask-rails/engine"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Inputmask
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Inputmask
3
+ module Rails
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
data/vendor/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,479 @@
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.2.3
7
+
8
+ Optional extensions on the jquery.inputmask base
9
+ */
10
+ (function($) {
11
+ //date & time aliases
12
+ $.extend($.inputmask.defaults.definitions, {
13
+ 'h': { //hours
14
+ validator: "[01][0-9]|2[0-3]",
15
+ cardinality: 2,
16
+ prevalidator: [{ validator: "[0-2]", cardinality: 1}]
17
+ },
18
+ 's': { //seconds || minutes
19
+ validator: "[0-5][0-9]",
20
+ cardinality: 2,
21
+ prevalidator: [{ validator: "[0-5]", cardinality: 1}]
22
+ },
23
+ 'd': { //basic day
24
+ validator: "0[1-9]|[12][0-9]|3[01]",
25
+ cardinality: 2,
26
+ prevalidator: [{ validator: "[0-3]", cardinality: 1}]
27
+ },
28
+ 'm': { //basic month
29
+ validator: "0[1-9]|1[012]",
30
+ cardinality: 2,
31
+ prevalidator: [{ validator: "[01]", cardinality: 1}]
32
+ },
33
+ 'y': { //basic year
34
+ validator: "(19|20)\\d{2}",
35
+ cardinality: 4,
36
+ prevalidator: [
37
+ { validator: "[12]", cardinality: 1 },
38
+ { validator: "(19|20)", cardinality: 2 },
39
+ { validator: "(19|20)\\d", cardinality: 3 }
40
+ ]
41
+ }
42
+ });
43
+ $.extend($.inputmask.defaults.aliases, {
44
+ 'dd/mm/yyyy': {
45
+ mask: "1/2/y",
46
+ placeholder: "dd/mm/yyyy",
47
+ regex: {
48
+ val1pre: new RegExp("[0-3]"), //daypre
49
+ val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
50
+ val2pre: function(separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); }, //monthpre
51
+ val2: function(separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|[12][0-9])" + escapedSeparator + "(0[1-9]|1[012]))|(30" + escapedSeparator + "(0[13-9]|1[012]))|(31" + escapedSeparator + "(0[13578]|1[02]))"); }//month
52
+ },
53
+ leapday: "29/02/",
54
+ separator: '/',
55
+ yearrange: { minyear: 1900, maxyear: 2099 },
56
+ isInYearRange: function(chrs, minyear, maxyear){
57
+ var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
58
+ var enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
59
+ return (enteredyear != NaN ? minyear <= enteredyear && enteredyear <= maxyear : false) ||
60
+ (enteredyear2 != NaN ? minyear <= enteredyear2 && enteredyear2 <= maxyear : false);
61
+ },
62
+ determinebaseyear: function(minyear, maxyear){
63
+ var currentyear = (new Date()).getFullYear();
64
+ if(minyear > currentyear) return minyear;
65
+ if(maxyear < currentyear) return maxyear;
66
+
67
+ return currentyear;
68
+ },
69
+ onKeyUp: function(e, opts) {
70
+ var $input = $(this), input = this;
71
+ if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
72
+ var today = new Date();
73
+ $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
74
+ }
75
+ },
76
+ definitions: {
77
+ '1': { //val1 ~ day or month
78
+ validator: function(chrs, buffer, pos, strict, opts) {
79
+ var isValid = opts.regex.val1.test(chrs);
80
+ if (!strict && !isValid) {
81
+ if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1 ) {
82
+ isValid = opts.regex.val1.test("0" + chrs.charAt(0));
83
+ if (isValid) {
84
+ buffer[pos - 1] = "0";
85
+ return { "pos": pos ,"c": chrs.charAt(0) };
86
+ }
87
+ }
88
+ }
89
+ return isValid;
90
+ },
91
+ cardinality: 2,
92
+ prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
93
+ var isValid = opts.regex.val1pre.test(chrs);
94
+ if (!strict && !isValid) {
95
+ isValid = opts.regex.val1.test("0" + chrs);
96
+ if (isValid) {
97
+ buffer[pos] = "0";
98
+ pos++;
99
+ return { "pos": pos };
100
+ }
101
+ }
102
+ return isValid;
103
+ }, cardinality: 1}]
104
+ },
105
+ '2': { //val2 ~ day or month
106
+ validator: function(chrs, buffer, pos, strict, opts) {
107
+ var frontValue = buffer.join('').substr(0, 3);
108
+ var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
109
+ if (!strict && !isValid) {
110
+ if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1 ) {
111
+ isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
112
+ if (isValid) {
113
+ buffer[pos - 1] = "0";
114
+ return { "pos": pos, "c": chrs.charAt(0) };
115
+ }
116
+ }
117
+ }
118
+ return isValid;
119
+ },
120
+ cardinality: 2,
121
+ prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
122
+ var frontValue = buffer.join('').substr(0, 3);
123
+ var isValid = opts.regex.val2pre(opts.separator).test(frontValue + chrs);
124
+ if (!strict && !isValid) {
125
+ isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
126
+ if (isValid) {
127
+ buffer[pos] = "0";
128
+ pos++;
129
+ return { "pos": pos };
130
+ }
131
+ }
132
+ return isValid;
133
+ }, cardinality: 1}]
134
+ },
135
+ 'y': { //year
136
+ validator: function(chrs, buffer, pos, strict, opts) {
137
+ if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
138
+ var dayMonthValue = buffer.join('').substr(0, 6);
139
+ if (dayMonthValue != opts.leapday)
140
+ return true;
141
+ else {
142
+ var year = parseInt(chrs,10);//detect leap year
143
+ if (year % 4 === 0)
144
+ if (year % 100 === 0)
145
+ if (year % 400 === 0)
146
+ return true;
147
+ else return false;
148
+ else return true;
149
+ else return false;
150
+ }
151
+ } else return false;
152
+ },
153
+ cardinality: 4,
154
+ prevalidator: [
155
+ { validator: function(chrs, buffer, pos, strict, opts) {
156
+ var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
157
+ if (!strict && !isValid) {
158
+ var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 1);
159
+
160
+ isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
161
+ if (isValid) {
162
+ buffer[pos++] = yearPrefix[0];
163
+ return { "pos": pos };
164
+ }
165
+ yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
166
+
167
+ isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
168
+ if (isValid) {
169
+ buffer[pos++] = yearPrefix[0];
170
+ buffer[pos++] = yearPrefix[1];
171
+ return { "pos": pos };
172
+ }
173
+ }
174
+ return isValid;
175
+ },
176
+ cardinality: 1
177
+ },
178
+ { validator: function(chrs, buffer, pos, strict, opts) {
179
+ var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
180
+ if (!strict && !isValid) {
181
+ var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
182
+
183
+ isValid = opts.isInYearRange(yearPrefix + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear);
184
+ if (isValid) {
185
+ buffer[pos++] = yearPrefix[1];
186
+ return { "pos": pos };
187
+ }
188
+
189
+ yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear).toString().slice(0, 2);
190
+ if (opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) {
191
+ var dayMonthValue = buffer.join('').substr(0, 6);
192
+ if (dayMonthValue != opts.leapday)
193
+ isValid = true;
194
+ else {
195
+ var year = parseInt(chrs,10);//detect leap year
196
+ if (year % 4 === 0)
197
+ if (year % 100 === 0)
198
+ if (year % 400 === 0)
199
+ isValid = true;
200
+ else isValid = false;
201
+ else isValid = true;
202
+ else isValid = false;
203
+ }
204
+ } else isValid = false;
205
+ if (isValid) {
206
+ buffer[pos-1] = yearPrefix[0];
207
+ buffer[pos++] = yearPrefix[1];
208
+ buffer[pos++] = chrs[0];
209
+ return { "pos": pos };
210
+ }
211
+ }
212
+ return isValid;
213
+ }, cardinality: 2 },
214
+ { validator: function(chrs, buffer, pos, strict, opts) {
215
+ return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear);
216
+ }, cardinality: 3 }
217
+ ]
218
+ }
219
+ },
220
+ insertMode: false,
221
+ autoUnmask: false
222
+ },
223
+ 'mm/dd/yyyy': {
224
+ placeholder: "mm/dd/yyyy",
225
+ alias: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
226
+ regex: {
227
+ val2pre: function(separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])"); }, //daypre
228
+ val2: function(separator) { var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)"); }, //day
229
+ val1pre: new RegExp("[01]"), //monthpre
230
+ val1: new RegExp("0[1-9]|1[012]") //month
231
+ },
232
+ leapday: "02/29/",
233
+ onKeyUp: function(e, opts) {
234
+ var $input = $(this), input = this;
235
+ if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
236
+ var today = new Date();
237
+ $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
238
+ }
239
+ }
240
+ },
241
+ 'yyyy/mm/dd': {
242
+ mask: "y/1/2",
243
+ placeholder: "yyyy/mm/dd",
244
+ alias: "mm/dd/yyyy",
245
+ leapday: "/02/29",
246
+ onKeyUp: function(e, opts) {
247
+ var $input = $(this), input = this;
248
+ if (e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
249
+ var today = new Date();
250
+ $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
251
+ }
252
+ },
253
+ definitions: {
254
+ '2': { //val2 ~ day or month
255
+ validator: function(chrs, buffer, pos, strict, opts) {
256
+ var frontValue = buffer.join('').substr(5, 3);
257
+ var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs);
258
+ if (!strict && !isValid) {
259
+ if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1 ) {
260
+ isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0));
261
+ if (isValid) {
262
+ buffer[pos - 1] = "0";
263
+ return { "pos": pos, "c": chrs.charAt(0) };
264
+ }
265
+ }
266
+ }
267
+
268
+ //check leap yeap
269
+ if (isValid) {
270
+ var dayMonthValue = buffer.join('').substr(4, 4) + chrs;
271
+ if (dayMonthValue != opts.leapday)
272
+ return true;
273
+ else {
274
+ var year = parseInt(buffer.join('').substr(0, 4),10); //detect leap year
275
+ if (year % 4 === 0)
276
+ if (year % 100 === 0)
277
+ if (year % 400 === 0)
278
+ return true;
279
+ else return false;
280
+ else return true;
281
+ else return false;
282
+ }
283
+ }
284
+
285
+ return isValid;
286
+ },
287
+ cardinality: 2,
288
+ prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
289
+ var frontValue = buffer.join('').substr(5, 3);
290
+ var isValid = opts.regex.val2pre(opts.separator).test(frontValue + chrs);
291
+ if (!strict && !isValid) {
292
+ isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs);
293
+ if (isValid) {
294
+ buffer[pos] = "0";
295
+ pos++;
296
+ return { "pos": pos };
297
+ }
298
+ }
299
+ return isValid;
300
+ }, cardinality: 1}]
301
+ }
302
+ }
303
+ },
304
+ 'dd.mm.yyyy': {
305
+ mask: "1.2.y",
306
+ placeholder: "dd.mm.yyyy",
307
+ leapday: "29.02.",
308
+ separator: '.',
309
+ alias: "dd/mm/yyyy"
310
+ },
311
+ 'dd-mm-yyyy': {
312
+ mask: "1-2-y",
313
+ placeholder: "dd-mm-yyyy",
314
+ leapday: "29-02-",
315
+ separator: '-',
316
+ alias: "dd/mm/yyyy"
317
+ },
318
+ 'mm.dd.yyyy': {
319
+ mask: "1.2.y",
320
+ placeholder: "mm.dd.yyyy",
321
+ leapday: "02.29.",
322
+ separator: '.',
323
+ alias: "mm/dd/yyyy"
324
+ },
325
+ 'mm-dd-yyyy': {
326
+ mask: "1-2-y",
327
+ placeholder: "mm-dd-yyyy",
328
+ leapday: "02-29-",
329
+ separator: '-',
330
+ alias: "mm/dd/yyyy"
331
+ },
332
+ 'yyyy.mm.dd': {
333
+ mask: "y.1.2",
334
+ placeholder: "yyyy.mm.dd",
335
+ leapday: ".02.29",
336
+ separator: '.',
337
+ alias: "yyyy/mm/dd"
338
+ },
339
+ 'yyyy-mm-dd': {
340
+ mask: "y-1-2",
341
+ placeholder: "yyyy-mm-dd",
342
+ leapday: "-02-29",
343
+ separator: '-',
344
+ alias: "yyyy/mm/dd"
345
+ },
346
+ 'datetime': {
347
+ mask: "1/2/y h:s",
348
+ placeholder: "dd/mm/yyyy hh:mm",
349
+ alias: "dd/mm/yyyy",
350
+ regex: {
351
+ hrspre: new RegExp("[012]"), //hours pre
352
+ hrs24: new RegExp("2[0-9]|1[3-9]"),
353
+ hrs: new RegExp("[01][0-9]|2[0-3]"), //hours
354
+ ampmpre: new RegExp("[apAP]"),
355
+ ampm: new RegExp("^[a|p|A|P][m|M]")
356
+ },
357
+ timeseparator: ':',
358
+ hourFormat: "24", // or 12
359
+ definitions: {
360
+ 'h': { //hours
361
+ validator: function(chrs, buffer, pos, strict, opts) {
362
+ var isValid = opts.regex.hrs.test(chrs);
363
+ if (!strict && !isValid) {
364
+ if (chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1 ) {
365
+ isValid = opts.regex.hrs.test("0" + chrs.charAt(0));
366
+ if (isValid) {
367
+ buffer[pos - 1] = "0";
368
+ buffer[pos] = chrs.charAt(0);
369
+ pos++;
370
+ return { "pos": pos };
371
+ }
372
+ }
373
+ }
374
+
375
+ if ( isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs) ) {
376
+
377
+ var tmp = parseInt(chrs,10);
378
+
379
+ if ( tmp == 24 ) {
380
+ buffer[pos+5] = "a";
381
+ buffer[pos+6] = "m";
382
+ } else {
383
+ buffer[pos+5] = "p";
384
+ buffer[pos+6] = "m";
385
+ }
386
+
387
+ tmp = tmp - 12;
388
+
389
+ if ( tmp < 10 ) {
390
+ buffer[pos] = tmp.toString();
391
+ buffer[pos-1] = "0";
392
+ } else {
393
+ buffer[pos] = tmp.toString().charAt(1);
394
+ buffer[pos-1] = tmp.toString().charAt(0);
395
+ }
396
+
397
+ return { "pos": pos, "c" : buffer[pos] };
398
+ }
399
+
400
+ return isValid;
401
+ },
402
+ cardinality: 2,
403
+ prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
404
+ var isValid = opts.regex.hrspre.test(chrs);
405
+ if (!strict && !isValid) {
406
+ isValid = opts.regex.hrs.test("0" + chrs);
407
+ if (isValid) {
408
+ buffer[pos] = "0";
409
+ pos++;
410
+ return { "pos": pos };
411
+ }
412
+ }
413
+ return isValid;
414
+ }, cardinality: 1}]
415
+ },
416
+ 't': { //am/pm
417
+ validator: function(chrs, buffer, pos, strict, opts) {
418
+ var isValid = opts.regex.ampm.test(chrs);
419
+ if (!strict && !isValid) {
420
+ isValid = opts.regex.ampm.test(chrs+'m');
421
+ if (isValid) {
422
+ buffer[pos - 1] = chrs.charAt(0);
423
+ buffer[pos] = "m";
424
+ pos++;
425
+ return pos;
426
+ }
427
+ }
428
+ return isValid;
429
+ },
430
+ casing: "lower",
431
+ cardinality: 2,
432
+ prevalidator: [{ validator: function(chrs, buffer, pos, strict, opts) {
433
+ var isValid = opts.regex.ampmpre.test(chrs);
434
+ if (isValid) {
435
+ isValid = opts.regex.ampm.test(chrs+"m");
436
+ if (isValid) {
437
+ buffer[pos] = chrs;
438
+ buffer[pos+1] = 'm';
439
+ return pos;
440
+ }
441
+ }
442
+ return isValid;
443
+ }, cardinality: 1}]
444
+ }
445
+ },
446
+ insertMode: false,
447
+ autoUnmask: false
448
+ },
449
+ 'datetime12': {
450
+ mask: "1/2/y h:s t",
451
+ placeholder: "dd/mm/yyyy hh:mm xm",
452
+ alias: "datetime",
453
+ hourFormat: "12"
454
+ },
455
+ 'hh:mm t': {
456
+ mask: "h:s t",
457
+ placeholder: "hh:mm xm",
458
+ alias: "datetime",
459
+ hourFormat: "12"
460
+ },
461
+ 'h:s t': {
462
+ mask: "h:s t",
463
+ placeholder: "hh:mm xm",
464
+ alias: "datetime",
465
+ hourFormat: "12"
466
+ },
467
+ 'hh:mm:ss': {
468
+ mask: "h:s:s",
469
+ autoUnmask: false
470
+ },
471
+ 'hh:mm': {
472
+ mask: "h:s",
473
+ autoUnmask: false
474
+ },
475
+ 'date': {
476
+ alias: "dd/mm/yyyy" // "mm/dd/yyyy"
477
+ }
478
+ });
479
+ })(jQuery);