]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/static/AdminLTE-2.3.7/plugins/input-mask/jquery.inputmask.date.extensions.js
2 Input Mask plugin extensions
3 http://github.com/RobinHerbots/jquery.inputmask
4 Copyright (c) 2010 - 2014 Robin Herbots
5 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
8 Optional extensions on the jquery.inputmask base
12 $.extend($.inputmask
.defaults
.definitions
, {
14 validator
: "[01][0-9]|2[0-3]",
16 prevalidator
: [{ validator
: "[0-2]", cardinality
: 1 }]
18 's': { //seconds || minutes
19 validator
: "[0-5][0-9]",
21 prevalidator
: [{ validator
: "[0-5]", cardinality
: 1 }]
24 validator
: "0[1-9]|[12][0-9]|3[01]",
26 prevalidator
: [{ validator
: "[0-3]", cardinality
: 1 }]
29 validator
: "0[1-9]|1[012]",
31 prevalidator
: [{ validator
: "[01]", cardinality
: 1 }]
34 validator
: "(19|20)\\d{2}",
37 { validator
: "[12]", cardinality
: 1 },
38 { validator
: "(19|20)", cardinality
: 2 },
39 { validator
: "(19|20)\\d", cardinality
: 3 }
43 $.extend($.inputmask
.defaults
.aliases
, {
46 placeholder
: "dd/mm/yyyy",
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
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);
62 determinebaseyear: function (minyear
, maxyear
, hint
) {
63 var currentyear
= (new Date()).getFullYear();
64 if (minyear
> currentyear
) return minyear
;
65 if (maxyear
< currentyear
) {
66 var maxYearPrefix
= maxyear
.toString().slice(0, 2);
67 var maxYearPostfix
= maxyear
.toString().slice(2, 4);
68 while (maxyear
< maxYearPrefix
+ hint
) {
71 var maxxYear
= maxYearPrefix
+ maxYearPostfix
;
72 return minyear
> maxxYear
? minyear
: maxxYear
;
77 onKeyUp: function (e
, buffer
, opts
) {
79 if (e
.ctrlKey
&& e
.keyCode
== opts
.keyCode
.RIGHT
) {
80 var today
= new Date();
81 $input
.val(today
.getDate().toString() + (today
.getMonth() + 1).toString() + today
.getFullYear().toString());
85 '1': { //val1 ~ day or month
86 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
87 var isValid
= opts
.regex
.val1
.test(chrs
);
88 if (!strict
&& !isValid
) {
89 if (chrs
.charAt(1) == opts
.separator
|| "-./".indexOf(chrs
.charAt(1)) != -1) {
90 isValid
= opts
.regex
.val1
.test("0" + chrs
.charAt(0));
92 buffer
[pos
- 1] = "0";
93 return { "pos": pos
, "c": chrs
.charAt(0) };
101 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
102 var isValid
= opts
.regex
.val1pre
.test(chrs
);
103 if (!strict
&& !isValid
) {
104 isValid
= opts
.regex
.val1
.test("0" + chrs
);
108 return { "pos": pos
};
115 '2': { //val2 ~ day or month
116 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
117 var frontValue
= buffer
.join('').substr(0, 3);
118 if (frontValue
.indexOf(opts
.placeholder
[0]) != -1) frontValue
= "01" + opts
.separator
;
119 var isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ chrs
);
120 if (!strict
&& !isValid
) {
121 if (chrs
.charAt(1) == opts
.separator
|| "-./".indexOf(chrs
.charAt(1)) != -1) {
122 isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ "0" + chrs
.charAt(0));
124 buffer
[pos
- 1] = "0";
125 return { "pos": pos
, "c": chrs
.charAt(0) };
133 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
134 var frontValue
= buffer
.join('').substr(0, 3);
135 if (frontValue
.indexOf(opts
.placeholder
[0]) != -1) frontValue
= "01" + opts
.separator
;
136 var isValid
= opts
.regex
.val2pre(opts
.separator
).test(frontValue
+ chrs
);
137 if (!strict
&& !isValid
) {
138 isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ "0" + chrs
);
142 return { "pos": pos
};
150 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
151 if (opts
.isInYearRange(chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
)) {
152 var dayMonthValue
= buffer
.join('').substr(0, 6);
153 if (dayMonthValue
!= opts
.leapday
)
156 var year
= parseInt(chrs
, 10);//detect leap year
158 if (year
% 100 === 0)
159 if (year
% 400 === 0)
170 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
171 var isValid
= opts
.isInYearRange(chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
172 if (!strict
&& !isValid
) {
173 var yearPrefix
= opts
.determinebaseyear(opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
, chrs
+ "0").toString().slice(0, 1);
175 isValid
= opts
.isInYearRange(yearPrefix
+ chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
177 buffer
[pos
++] = yearPrefix
[0];
178 return { "pos": pos
};
180 yearPrefix
= opts
.determinebaseyear(opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
, chrs
+ "0").toString().slice(0, 2);
182 isValid
= opts
.isInYearRange(yearPrefix
+ chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
184 buffer
[pos
++] = yearPrefix
[0];
185 buffer
[pos
++] = yearPrefix
[1];
186 return { "pos": pos
};
194 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
195 var isValid
= opts
.isInYearRange(chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
196 if (!strict
&& !isValid
) {
197 var yearPrefix
= opts
.determinebaseyear(opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
, chrs
).toString().slice(0, 2);
199 isValid
= opts
.isInYearRange(chrs
[0] + yearPrefix
[1] + chrs
[1], opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
201 buffer
[pos
++] = yearPrefix
[1];
202 return { "pos": pos
};
205 yearPrefix
= opts
.determinebaseyear(opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
, chrs
).toString().slice(0, 2);
206 if (opts
.isInYearRange(yearPrefix
+ chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
)) {
207 var dayMonthValue
= buffer
.join('').substr(0, 6);
208 if (dayMonthValue
!= opts
.leapday
)
211 var year
= parseInt(chrs
, 10);//detect leap year
213 if (year
% 100 === 0)
214 if (year
% 400 === 0)
216 else isValid
= false;
218 else isValid
= false;
220 } else isValid
= false;
222 buffer
[pos
- 1] = yearPrefix
[0];
223 buffer
[pos
++] = yearPrefix
[1];
224 buffer
[pos
++] = chrs
[0];
225 return { "pos": pos
};
232 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
233 return opts
.isInYearRange(chrs
, opts
.yearrange
.minyear
, opts
.yearrange
.maxyear
);
243 placeholder
: "mm/dd/yyyy",
244 alias
: "dd/mm/yyyy", //reuse functionality of dd/mm/yyyy alias
246 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
247 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
248 val1pre
: new RegExp("[01]"), //monthpre
249 val1
: new RegExp("0[1-9]|1[012]") //month
252 onKeyUp: function (e
, buffer
, opts
) {
253 var $input
= $(this);
254 if (e
.ctrlKey
&& e
.keyCode
== opts
.keyCode
.RIGHT
) {
255 var today
= new Date();
256 $input
.val((today
.getMonth() + 1).toString() + today
.getDate().toString() + today
.getFullYear().toString());
262 placeholder
: "yyyy/mm/dd",
265 onKeyUp: function (e
, buffer
, opts
) {
266 var $input
= $(this);
267 if (e
.ctrlKey
&& e
.keyCode
== opts
.keyCode
.RIGHT
) {
268 var today
= new Date();
269 $input
.val(today
.getFullYear().toString() + (today
.getMonth() + 1).toString() + today
.getDate().toString());
273 '2': { //val2 ~ day or month
274 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
275 var frontValue
= buffer
.join('').substr(5, 3);
276 if (frontValue
.indexOf(opts
.placeholder
[5]) != -1) frontValue
= "01" + opts
.separator
;
277 var isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ chrs
);
278 if (!strict
&& !isValid
) {
279 if (chrs
.charAt(1) == opts
.separator
|| "-./".indexOf(chrs
.charAt(1)) != -1) {
280 isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ "0" + chrs
.charAt(0));
282 buffer
[pos
- 1] = "0";
283 return { "pos": pos
, "c": chrs
.charAt(0) };
290 var dayMonthValue
= buffer
.join('').substr(4, 4) + chrs
;
291 if (dayMonthValue
!= opts
.leapday
)
294 var year
= parseInt(buffer
.join('').substr(0, 4), 10); //detect leap year
296 if (year
% 100 === 0)
297 if (year
% 400 === 0)
309 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
310 var frontValue
= buffer
.join('').substr(5, 3);
311 if (frontValue
.indexOf(opts
.placeholder
[5]) != -1) frontValue
= "01" + opts
.separator
;
312 var isValid
= opts
.regex
.val2pre(opts
.separator
).test(frontValue
+ chrs
);
313 if (!strict
&& !isValid
) {
314 isValid
= opts
.regex
.val2(opts
.separator
).test(frontValue
+ "0" + chrs
);
318 return { "pos": pos
};
329 placeholder
: "dd.mm.yyyy",
336 placeholder
: "dd-mm-yyyy",
343 placeholder
: "mm.dd.yyyy",
350 placeholder
: "mm-dd-yyyy",
357 placeholder
: "yyyy.mm.dd",
364 placeholder
: "yyyy-mm-dd",
371 placeholder
: "dd/mm/yyyy hh:mm",
374 hrspre
: new RegExp("[012]"), //hours pre
375 hrs24
: new RegExp("2[0-9]|1[3-9]"),
376 hrs
: new RegExp("[01][0-9]|2[0-3]"), //hours
377 ampm
: new RegExp("^[a|p|A|P][m|M]")
380 hourFormat
: "24", // or 12
383 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
384 var isValid
= opts
.regex
.hrs
.test(chrs
);
385 if (!strict
&& !isValid
) {
386 if (chrs
.charAt(1) == opts
.timeseparator
|| "-.:".indexOf(chrs
.charAt(1)) != -1) {
387 isValid
= opts
.regex
.hrs
.test("0" + chrs
.charAt(0));
389 buffer
[pos
- 1] = "0";
390 buffer
[pos
] = chrs
.charAt(0);
392 return { "pos": pos
};
397 if (isValid
&& opts
.hourFormat
!== "24" && opts
.regex
.hrs24
.test(chrs
)) {
399 var tmp
= parseInt(chrs
, 10);
402 buffer
[pos
+ 5] = "a";
403 buffer
[pos
+ 6] = "m";
405 buffer
[pos
+ 5] = "p";
406 buffer
[pos
+ 6] = "m";
412 buffer
[pos
] = tmp
.toString();
413 buffer
[pos
- 1] = "0";
415 buffer
[pos
] = tmp
.toString().charAt(1);
416 buffer
[pos
- 1] = tmp
.toString().charAt(0);
419 return { "pos": pos
, "c": buffer
[pos
] };
426 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
427 var isValid
= opts
.regex
.hrspre
.test(chrs
);
428 if (!strict
&& !isValid
) {
429 isValid
= opts
.regex
.hrs
.test("0" + chrs
);
433 return { "pos": pos
};
441 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
442 return opts
.regex
.ampm
.test(chrs
+ "m");
452 mask
: "1/2/y h:s t\\m",
453 placeholder
: "dd/mm/yyyy hh:mm xm",
459 placeholder
: "hh:mm xm",
465 placeholder
: "hh:mm xm",
478 alias
: "dd/mm/yyyy" // "mm/dd/yyyy"
482 placeholder
: "mm/yyyy",