Вход Регистрация
Файл: upload/admin/js/jquery.inputmask.date.extensions.js
Строк: 355
<?php
/*
Input Mask plugin extensions
http://github.com/RobinHerbots/jquery.inputmask
Copyright (c) 2010 - 2014 Robin Herbots
Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
Version: 0.0.0

Optional extensions on the jquery.inputmask base
*/
(function ($) {
    
//date & time aliases
    
$.extend($.inputmask.defaults.definitions, {
        
'h': { //hours
            
validator"[01][0-9]|2[0-3]",
            
cardinality2,
            
prevalidator: [{ validator"[0-2]"cardinality}]
        },
        
's': { //seconds || minutes
            
validator"[0-5][0-9]",
            
cardinality2,
            
prevalidator: [{ validator"[0-5]"cardinality}]
        },
        
'd': { //basic day
            
validator"0[1-9]|[12][0-9]|3[01]",
            
cardinality2,
            
prevalidator: [{ validator"[0-3]"cardinality}]
        },
        
'm': { //basic month
            
validator"0[1-9]|1[012]",
            
cardinality2,
            
prevalidator: [{ validator"[01]"cardinality}]
        },
        
'y': { //basic year
            
validator"(19|20)\d{2}",
            
cardinality4,
            
prevalidator: [
                        { 
validator"[12]"cardinality},
                        { 
validator"(19|20)"cardinality},
                        { 
validator"(19|20)\d"cardinality}
            ]
        }
    });
    $.
extend($.inputmask.defaults.aliases, {
        
'dd/mm/yyyy': {
            
mask"1/2/y",
            
placeholder"dd/mm/yyyy",
            
regex: {
                
val1pre: new RegExp("[0-3]"), //daypre
                
val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), //day
                
val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(thisseparator); return new RegExp("((0[1-9]|[12][0-9]|3[01])" escapedSeparator "[01])"); }, //monthpre
                
val2: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(thisseparator); 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
            
},
            
leapday"29/02/",
            
separator'/',
            
yearrange: { minyear1900maxyear2099 },
            
isInYearRange: function (chrsminyearmaxyear) {
                var 
enteredyear parseInt(chrs.concat(minyear.toString().slice(chrs.length)));
                var 
enteredyear2 parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));
                return (
enteredyear != NaN minyear <= enteredyear && enteredyear <= maxyear false) ||
                       (
enteredyear2 != NaN minyear <= enteredyear2 && enteredyear2 <= maxyear false);
            },
            
determinebaseyear: function (minyearmaxyearhint) {
                var 
currentyear = (new Date()).getFullYear();
                if (
minyear currentyear) return minyear;
                if (
maxyear currentyear) {
                    var 
maxYearPrefix maxyear.toString().slice(02);
                    var 
maxYearPostfix maxyear.toString().slice(24);
                    while (
maxyear maxYearPrefix hint) {
                        
maxYearPrefix--;
                    }
                    var 
maxxYear maxYearPrefix maxYearPostfix;
                    return 
minyear maxxYear minyear maxxYear;
                }

                return 
currentyear;
            },
            
onKeyUp: function (ebufferopts) {
                var 
$input = $(this);
                if (
e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
                    var 
today = new Date();
                    
$input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString());
                }
            },
            
definitions: {
                
'1': { //val1 ~ day or month
                    
validator: function (chrsbufferposstrictopts) {
                        var 
isValid opts.regex.val1.test(chrs);
                        if (!
strict && !isValid) {
                            if (
chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
                                
isValid opts.regex.val1.test("0" chrs.charAt(0));
                                if (
isValid) {
                                    
buffer[pos 1] = "0";
                                    return { 
"pos"pos"c"chrs.charAt(0) };
                                }
                            }
                        }
                        return 
isValid;
                    },
                    
cardinality2,
                    
prevalidator: [{
                        
validator: function (chrsbufferposstrictopts) {
                            var 
isValid opts.regex.val1pre.test(chrs);
                            if (!
strict && !isValid) {
                                
isValid opts.regex.val1.test("0" chrs);
                                if (
isValid) {
                                    
buffer[pos] = "0";
                                    
pos++;
                                    return { 
"pos"pos };
                                }
                            }
                            return 
isValid;
                        }, 
cardinality1
                    
}]
                },
                
'2': { //val2 ~ day or month
                    
validator: function (chrsbufferposstrictopts) {
                        var 
frontValue buffer.join('').substr(03);
                        if (
frontValue.indexOf(opts.placeholder[0]) != -1frontValue "01" opts.separator;
                        var 
isValid opts.regex.val2(opts.separator).test(frontValue chrs);
                        if (!
strict && !isValid) {
                            if (
chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
                                
isValid opts.regex.val2(opts.separator).test(frontValue "0" chrs.charAt(0));
                                if (
isValid) {
                                    
buffer[pos 1] = "0";
                                    return { 
"pos"pos"c"chrs.charAt(0) };
                                }
                            }
                        }
                        return 
isValid;
                    },
                    
cardinality2,
                    
prevalidator: [{
                        
validator: function (chrsbufferposstrictopts) {
                            var 
frontValue buffer.join('').substr(03);
                            if (
frontValue.indexOf(opts.placeholder[0]) != -1frontValue "01" opts.separator;
                            var 
isValid opts.regex.val2pre(opts.separator).test(frontValue chrs);
                            if (!
strict && !isValid) {
                                
isValid opts.regex.val2(opts.separator).test(frontValue "0" chrs);
                                if (
isValid) {
                                    
buffer[pos] = "0";
                                    
pos++;
                                    return { 
"pos"pos };
                                }
                            }
                            return 
isValid;
                        }, 
cardinality1
                    
}]
                },
                
'y': { //year
                    
validator: function (chrsbufferposstrictopts) {
                        if (
opts.isInYearRange(chrsopts.yearrange.minyearopts.yearrange.maxyear)) {
                            var 
dayMonthValue buffer.join('').substr(06);
                            if (
dayMonthValue != opts.leapday)
                                return 
true;
                            else {
                                var 
year parseInt(chrs10);//detect leap year
                                
if (year === 0)
                                    if (
year 100 === 0)
                                        if (
year 400 === 0)
                                            return 
true;
                                        else return 
false;
                                    else return 
true;
                                else return 
false;
                            }
                        } else return 
false;
                    },
                    
cardinality4,
                    
prevalidator: [
                {
                    
validator: function (chrsbufferposstrictopts) {
                        var 
isValid opts.isInYearRange(chrsopts.yearrange.minyearopts.yearrange.maxyear);
                        if (!
strict && !isValid) {
                            var 
yearPrefix opts.determinebaseyear(opts.yearrange.minyearopts.yearrange.maxyearchrs "0").toString().slice(01);

                            
isValid opts.isInYearRange(yearPrefix chrsopts.yearrange.minyearopts.yearrange.maxyear);
                            if (
isValid) {
                                
buffer[pos++] = yearPrefix[0];
                                return { 
"pos"pos };
                            }
                            
yearPrefix opts.determinebaseyear(opts.yearrange.minyearopts.yearrange.maxyearchrs "0").toString().slice(02);

                            
isValid opts.isInYearRange(yearPrefix chrsopts.yearrange.minyearopts.yearrange.maxyear);
                            if (
isValid) {
                                
buffer[pos++] = yearPrefix[0];
                                
buffer[pos++] = yearPrefix[1];
                                return { 
"pos"pos };
                            }
                        }
                        return 
isValid;
                    },
                    
cardinality1
                
},
                {
                    
validator: function (chrsbufferposstrictopts) {
                        var 
isValid opts.isInYearRange(chrsopts.yearrange.minyearopts.yearrange.maxyear);
                        if (!
strict && !isValid) {
                            var 
yearPrefix opts.determinebaseyear(opts.yearrange.minyearopts.yearrange.maxyearchrs).toString().slice(02);

                            
isValid opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyearopts.yearrange.maxyear);
                            if (
isValid) {
                                
buffer[pos++] = yearPrefix[1];
                                return { 
"pos"pos };
                            }

                            
yearPrefix opts.determinebaseyear(opts.yearrange.minyearopts.yearrange.maxyearchrs).toString().slice(02);
                            if (
opts.isInYearRange(yearPrefix chrsopts.yearrange.minyearopts.yearrange.maxyear)) {
                                var 
dayMonthValue buffer.join('').substr(06);
                                if (
dayMonthValue != opts.leapday)
                                    
isValid true;
                                else {
                                    var 
year parseInt(chrs10);//detect leap year
                                    
if (year === 0)
                                        if (
year 100 === 0)
                                            if (
year 400 === 0)
                                                
isValid true;
                                            else 
isValid false;
                                        else 
isValid true;
                                    else 
isValid false;
                                }
                            } else 
isValid false;
                            if (
isValid) {
                                
buffer[pos 1] = yearPrefix[0];
                                
buffer[pos++] = yearPrefix[1];
                                
buffer[pos++] = chrs[0];
                                return { 
"pos"pos };
                            }
                        }
                        return 
isValid;
                    }, 
cardinality2
                
},
                {
                    
validator: function (chrsbufferposstrictopts) {
                        return 
opts.isInYearRange(chrsopts.yearrange.minyearopts.yearrange.maxyear);
                    }, 
cardinality3
                
}
                    ]
                }
            },
            
insertModefalse,
            
autoUnmaskfalse
        
},
        
'mm/dd/yyyy': {
            
placeholder"mm/dd/yyyy",
            
alias"dd/mm/yyyy"//reuse functionality of dd/mm/yyyy alias
            
regex: {
                
val2pre: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(thisseparator); return new RegExp("((0[13-9]|1[012])" escapedSeparator "[0-3])|(02" escapedSeparator "[0-2])"); }, //daypre
                
val2: function (separator) { var escapedSeparator = $.inputmask.escapeRegex.call(thisseparator); 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
                
val1pre: new RegExp("[01]"), //monthpre
                
val1: new RegExp("0[1-9]|1[012]"//month
            
},
            
leapday"02/29/",
            
onKeyUp: function (ebufferopts) {
                var 
$input = $(this);
                if (
e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
                    var 
today = new Date();
                    
$input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString());
                }
            }
        },
        
'yyyy/mm/dd': {
            
mask"y/1/2",
            
placeholder"yyyy/mm/dd",
            
alias"mm/dd/yyyy",
            
leapday"/02/29",
            
onKeyUp: function (ebufferopts) {
                var 
$input = $(this);
                if (
e.ctrlKey && e.keyCode == opts.keyCode.RIGHT) {
                    var 
today = new Date();
                    
$input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString());
                }
            },
            
definitions: {
                
'2': { //val2 ~ day or month
                    
validator: function (chrsbufferposstrictopts) {
                        var 
frontValue buffer.join('').substr(53);
                        if (
frontValue.indexOf(opts.placeholder[5]) != -1frontValue "01" opts.separator;
                        var 
isValid opts.regex.val2(opts.separator).test(frontValue chrs);
                        if (!
strict && !isValid) {
                            if (
chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
                                
isValid opts.regex.val2(opts.separator).test(frontValue "0" chrs.charAt(0));
                                if (
isValid) {
                                    
buffer[pos 1] = "0";
                                    return { 
"pos"pos"c"chrs.charAt(0) };
                                }
                            }
                        }

                        
//check leap yeap
                        
if (isValid) {
                            var 
dayMonthValue buffer.join('').substr(44) + chrs;
                            if (
dayMonthValue != opts.leapday)
                                return 
true;
                            else {
                                var 
year parseInt(buffer.join('').substr(04), 10);  //detect leap year
                                
if (year === 0)
                                    if (
year 100 === 0)
                                        if (
year 400 === 0)
                                            return 
true;
                                        else return 
false;
                                    else return 
true;
                                else return 
false;
                            }
                        }

                        return 
isValid;
                    },
                    
cardinality2,
                    
prevalidator: [{
                        
validator: function (chrsbufferposstrictopts) {
                            var 
frontValue buffer.join('').substr(53);
                            if (
frontValue.indexOf(opts.placeholder[5]) != -1frontValue "01" opts.separator;
                            var 
isValid opts.regex.val2pre(opts.separator).test(frontValue chrs);
                            if (!
strict && !isValid) {
                                
isValid opts.regex.val2(opts.separator).test(frontValue "0" chrs);
                                if (
isValid) {
                                    
buffer[pos] = "0";
                                    
pos++;
                                    return { 
"pos"pos };
                                }
                            }
                            return 
isValid;
                        }, 
cardinality1
                    
}]
                }
            }
        },
        
'dd.mm.yyyy': {
            
mask"1.2.y",
            
placeholder"dd.mm.yyyy",
            
leapday"29.02.",
            
separator'.',
            
alias"dd/mm/yyyy"
        
},
        
'dd-mm-yyyy': {
            
mask"1-2-y",
            
placeholder"dd-mm-yyyy",
            
leapday"29-02-",
            
separator'-',
            
alias"dd/mm/yyyy"
        
},
        
'mm.dd.yyyy': {
            
mask"1.2.y",
            
placeholder"mm.dd.yyyy",
            
leapday"02.29.",
            
separator'.',
            
alias"mm/dd/yyyy"
        
},
        
'mm-dd-yyyy': {
            
mask"1-2-y",
            
placeholder"mm-dd-yyyy",
            
leapday"02-29-",
            
separator'-',
            
alias"mm/dd/yyyy"
        
},
        
'yyyy.mm.dd': {
            
mask"y.1.2",
            
placeholder"yyyy.mm.dd",
            
leapday".02.29",
            
separator'.',
            
alias"yyyy/mm/dd"
        
},
        
'yyyy-mm-dd': {
            
mask"y-1-2",
            
placeholder"yyyy-mm-dd",
            
leapday"-02-29",
            
separator'-',
            
alias"yyyy/mm/dd"
        
},
        
'datetime': {
            
mask"1/2/y h:s",
            
placeholder"dd/mm/yyyy hh:mm",
            
alias"dd/mm/yyyy",
            
regex: {
                
hrspre: new RegExp("[012]"), //hours pre
                
hrs24: new RegExp("2[0-9]|1[3-9]"),
                
hrs: new RegExp("[01][0-9]|2[0-3]"), //hours
                
ampm: new RegExp("^[a|p|A|P][m|M]")
            },
            
timeseparator':',
            
hourFormat"24"// or 12
            
definitions: {
                
'h': { //hours
                    
validator: function (chrsbufferposstrictopts) {
                        var 
isValid opts.regex.hrs.test(chrs);
                        if (!
strict && !isValid) {
                            if (
chrs.charAt(1) == opts.timeseparator || "-.:".indexOf(chrs.charAt(1)) != -1) {
                                
isValid opts.regex.hrs.test("0" chrs.charAt(0));
                                if (
isValid) {
                                    
buffer[pos 1] = "0";
                                    
buffer[pos] = chrs.charAt(0);
                                    
pos++;
                                    return { 
"pos"pos };
                                }
                            }
                        }

                        if (
isValid && opts.hourFormat !== "24" && opts.regex.hrs24.test(chrs)) {

                            var 
tmp parseInt(chrs10);

                            if (
tmp == 24) {
                                
buffer[pos 5] = "a";
                                
buffer[pos 6] = "m";
                            } else {
                                
buffer[pos 5] = "p";
                                
buffer[pos 6] = "m";
                            }

                            
tmp tmp 12;

                            if (
tmp 10) {
                                
buffer[pos] = tmp.toString();
                                
buffer[pos 1] = "0";
                            } else {
                                
buffer[pos] = tmp.toString().charAt(1);
                                
buffer[pos 1] = tmp.toString().charAt(0);
                            }

                            return { 
"pos"pos"c"buffer[pos] };
                        }

                        return 
isValid;
                    },
                    
cardinality2,
                    
prevalidator: [{
                        
validator: function (chrsbufferposstrictopts) {
                            var 
isValid opts.regex.hrspre.test(chrs);
                            if (!
strict && !isValid) {
                                
isValid opts.regex.hrs.test("0" chrs);
                                if (
isValid) {
                                    
buffer[pos] = "0";
                                    
pos++;
                                    return { 
"pos"pos };
                                }
                            }
                            return 
isValid;
                        }, 
cardinality1
                    
}]
                },
                
't': { //am/pm
                    
validator: function (chrsbufferposstrictopts) {
                        return 
opts.regex.ampm.test(chrs "m");
                    },
                    
casing"lower",
                    
cardinality1
                
}
            },
            
insertModefalse,
            
autoUnmaskfalse
        
},
        
'datetime12': {
            
mask"1/2/y h:s t\m",
            
placeholder"dd/mm/yyyy hh:mm xm",
            
alias"datetime",
            
hourFormat"12"
        
},
        
'hh:mm t': {
            
mask"h:s t\m",
            
placeholder"hh:mm xm",
            
alias"datetime",
            
hourFormat"12"
        
},
        
'h:s t': {
            
mask"h:s t\m",
            
placeholder"hh:mm xm",
            
alias"datetime",
            
hourFormat"12"
        
},
        
'hh:mm:ss': {
            
mask"h:s:s",
            
autoUnmaskfalse
        
},
        
'hh:mm': {
            
mask"h:s",
            
autoUnmaskfalse
        
},
        
'date': {
            
alias"dd/mm/yyyy" // "mm/dd/yyyy"
        
},
        
'mm/yyyy': {
            
mask"1/y",
            
placeholder"mm/yyyy",
            
leapday"donotuse",
            
separator'/',
            
alias"mm/dd/yyyy"
        
}
    });
})(
jQuery);
?>
Онлайн: 0
Реклама