inputmask.date.extensions.min.js 5.4 KB

123456789
  1. /*!
  2. * inputmask.date.extensions.min.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2017 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 4.0.0-75
  7. */
  8. !function(t){"function"==typeof define&&define.amd?define(["./dependencyLibs/inputmask.dependencyLib","./inputmask"],t):"object"==typeof exports?module.exports=t(require("./dependencyLibs/inputmask.dependencyLib"),require("./inputmask")):t(window.dependencyLib||jQuery,window.Inputmask)}(function(t,e){function o(t){if(!t.tokenizer){var e=[];for(var o in s)-1===e.indexOf(o[0])&&e.push(o[0]);t.tokenizer="("+e.join("+|")+")+?|.",t.tokenizer=new RegExp(t.tokenizer,"g")}return t.tokenizer}function r(t,e){return(!isFinite(t.day)||"29"==t.day&&!isFinite(t.rawyear)||new Date(t.date.getFullYear(),isFinite(t.month)?t.month:t.date.getMonth()+1,0).getDate()>=t.day)&&e}function n(t,e){var o=!0;return e.min&&e.min.date.getTime()===e.min.date.getTime()&&(o=o&&e.min.date.getTime()<=t.getTime()),e.max&&e.max.date.getTime()===e.max.date.getTime()&&(o=o&&e.max.date.getTime()>=t.getTime()),o}function a(t,e,r){for(var n,a="";n=o(r).exec(t);)void 0===e?a+=s[n[0]]?"("+s[n[0]][0]+")":n[0]:s[n[0]]?a+=s[n[0]][3].call(e.date):a+=n[0];return a}function i(t,e){for(t=String(t),e=e||2;t.length<e;)t="0"+t;return t}function u(t,e,r){function n(t){var e=4===t.length?t:(new Date).getFullYear().toString().substr(0,4-t.length)+t;return r.min&&r.min.year&&r.max&&r.max.year?(e=e.replace(/[^0-9]/g,""),e=t.charAt(0)===r.max.year.charAt(0)?t.replace(/[^0-9]/g,"0"):e+r.min.year.substr(e.length)):e=e.replace(/[^0-9]/g,"0"),e}var a,i,u,p={date:new Date(1,0,1)},y=t;if("string"==typeof y){for(;i=o(r).exec(e);){var m=y.slice(0,i[0].length);s.hasOwnProperty(i[0])&&(a=s[i[0]][2],u=s[i[0]][1],function(t,e,o){"year"===a?(t[a]=n(e),t["raw"+a]=e):t[a]=o.min&&e.match(/[^0-9]/)?o.min[a]:e,void 0!==u&&u.call(t.date,"month"==a?parseInt(t[a])-1:t[a])}(p,m,r)),y=y.slice(m.length)}return p}}var s={d:["[1-9]|[12][0-9]|3[01]",Date.prototype.setDate,"day",Date.prototype.getDate],dd:["0[1-9]|[12][0-9]|3[01]",Date.prototype.setDate,"day",function(){return i(Date.prototype.getDate.call(this),2)}],ddd:[""],dddd:[""],m:["[1-9]|1[012]",Date.prototype.setMonth,"month",function(){return Date.prototype.getMonth.call(this)+1}],mm:["0[1-9]|1[012]",Date.prototype.setMonth,"month",function(){return i(Date.prototype.getMonth.call(this)+1,2)}],mmm:[""],mmmm:[""],yy:["[0-9]{2}",Date.prototype.setFullYear,"year",function(){return i(Date.prototype.getFullYear.call(this),2)}],yyyy:["[0-9]{4}",Date.prototype.setFullYear,"year",function(){return i(Date.prototype.getFullYear.call(this),4)}],h:["[1-9]|1[0-2]",Date.prototype.setHours,"hours",Date.prototype.getHours],hh:["0[1-9]|1[0-2]",Date.prototype.setHours,"hours",function(){return i(Date.prototype.getHours.call(this),2)}],hhh:["[0-9]+",Date.prototype.setHours,"hours",Date.prototype.getHours],H:["1?[1-9]|2[0-3]",Date.prototype.setHours,"hours",Date.prototype.getHours],HH:["[01][1-9]|2[0-3]",Date.prototype.setHours,"hours",function(){return i(Date.prototype.getHours.call(this),2)}],HHH:["[0-9]+",Date.prototype.setHours,"hours",Date.prototype.getHours],M:["[1-5]?[0-9]",Date.prototype.setMinutes,"minutes",Date.prototype.getMinutes],MM:["[0-5][0-9]",Date.prototype.setMinutes,"minutes",function(){return i(Date.prototype.getMinutes.call(this),2)}],s:["[1-5]?[0-9]",Date.prototype.setSeconds,"seconds",Date.prototype.getSeconds],ss:["[0-5][0-9]",Date.prototype.setSeconds,"seconds",function(){return i(Date.prototype.getSeconds.call(this),2)}],l:["[0-9]{3}",Date.prototype.setMilliseconds,"milliseconds",function(){return i(Date.prototype.getMilliseconds.call(this),3)}],L:["[0-9]{2}",Date.prototype.setMilliseconds,"milliseconds",function(){return i(Date.prototype.getMilliseconds.call(this),2)}],t:[""],tt:[""],T:[""],TT:[""],Z:[""],o:[""],S:[""]},p={isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};return e.extendAliases({datetime:{mask:function(t){return t.inputFormat=p[t.inputFormat]||t.inputFormat,t.displayFormat=p[t.displayFormat]||t.displayFormat||t.inputFormat,t.outputFormat=p[t.outputFormat]||t.outputFormat||t.inputFormat,t.placeholder=t.placeholder!==e.prototype.defaults.placeholder?t.placeholder:t.inputFormat,t.min=u(t.min,t.inputFormat,t),t.max=u(t.max,t.inputFormat,t),t.regex=a(t.inputFormat,void 0,t),null},inputFormat:"isoDateTime",displayFormat:void 0,outputFormat:void 0,min:null,max:null,i18n:{dayNames:["Mon","Tue","Wed","Thu","Fri","Sat","Sun","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]},postValidation:function(t,e,o){var a=e,i=u(t.join(""),o.inputFormat,o);return a&&i.date.getTime()===i.date.getTime()&&(a=(a=r(i,a))&&n(i.date,o)),a},onKeyDown:function(r,n,a,i){var u=this;if(r.ctrlKey&&r.keyCode===e.keyCode.RIGHT){for(var s,p=new Date,y="";s=o(i).exec(i.inputFormat);)"d"===s[0].charAt(0)?y+=p.getDate().toString():"m"===s[0].charAt(0)?y+=(p.getMonth()+1).toString():"yyyy"===s[0]?y+=p.getFullYear().toString():"yy"===s[0]&&(y+=p.getYear().toString());u.inputmask._valueSet(y),t(u).trigger("setvalue")}},onUnMask:function(t,e,o){return a(o.outputFormat,u(t,o.inputFormat,o),o)},insertMode:!1}}),e});