inputmask.date.extensions.min.js 6.0 KB

123456789
  1. /*!
  2. * inputmask.date.extensions.min.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2018 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 4.0.1-beta.33
  7. */
  8. !function(e){"function"==typeof define&&define.amd?define(["./dependencyLibs/inputmask.dependencyLib","./inputmask"],e):"object"==typeof exports?module.exports=e(require("./dependencyLibs/inputmask.dependencyLib"),require("./inputmask")):e(window.dependencyLib||jQuery,window.Inputmask)}(function(s,u){var m={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 d(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 d(Date.prototype.getMonth.call(this)+1,2)}],mmm:[""],mmmm:[""],yy:["[0-9]{2}",Date.prototype.setFullYear,"year",function(){return d(Date.prototype.getFullYear.call(this),2)}],yyyy:["[0-9]{4}",Date.prototype.setFullYear,"year",function(){return d(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 d(Date.prototype.getHours.call(this),2)}],hhh:["[0-9]+",Date.prototype.setHours,"hours",Date.prototype.getHours],H:["1?[0-9]|2[0-3]",Date.prototype.setHours,"hours",Date.prototype.getHours],HH:["[01][0-9]|2[0-3]",Date.prototype.setHours,"hours",function(){return d(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 d(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 d(Date.prototype.getSeconds.call(this),2)}],l:["[0-9]{3}",Date.prototype.setMilliseconds,"milliseconds",function(){return d(Date.prototype.getMilliseconds.call(this),3)}],L:["[0-9]{2}",Date.prototype.setMilliseconds,"milliseconds",function(){return d(Date.prototype.getMilliseconds.call(this),2)}],t:["[ap]"],tt:["[ap]m"],T:["[AP]"],TT:["[AP]M"],Z:[""],o:[""],S:[""]},t={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'"};function y(e){if(!e.tokenizer){var t=[];for(var o in m)-1===t.indexOf(o[0])&&t.push(o[0]);e.tokenizer="("+t.join("+|")+")+?|.",e.tokenizer=new RegExp(e.tokenizer,"g")}return e.tokenizer}function p(e,t,o,r){for(var a,n="";a=y(o).exec(e);){if(void 0===t)if(m[a[0]])n+="("+m[a[0]][0]+")";else switch(a[0]){case"[":n+="(";break;case"]":n+=")?";break;default:n+=u.escapeRegex(a[0])}else if(m[a[0]])if(!0!==r&&m[a[0]][3])n+=m[a[0]][3].call(t.date);else m[a[0]][2]?n+=t["raw"+m[a[0]][2]]:n+=a[0];else n+=a[0]}return n}function d(e,t){for(e=String(e),t=t||2;e.length<t;)e="0"+e;return e}function l(e,t,a){var n,o,r,i,s={date:new Date(1,0,1)},u=e;function p(e,t,o){e[n]=function(e){var t;if(a.min&&a.min[n]||a.max&&a.max[n]){var o=a.min&&a.min[n]||a.max[n],r=a.max&&a.max[n]||a.min[n];for(t=e.replace(/[^0-9]/g,""),t+=(o.indexOf(t)<r.indexOf(t)?r:o).toString().substr(t.length);!new RegExp(i).test(t);)t--}else t=e.replace(/[^0-9]/g,"0");return t}(t),e["raw"+n]=t,void 0!==r&&r.call(e.date,"month"==n?parseInt(e[n])-1:e[n])}if("string"==typeof u){for(;o=y(a).exec(t);){var d=u.slice(0,o[0].length);m.hasOwnProperty(o[0])&&(i=m[o[0]][0],n=m[o[0]][2],r=m[o[0]][1],p(s,d)),u=u.slice(d.length)}return s}if(u&&"object"==typeof u&&u.hasOwnProperty("date"))return u}return u.extendAliases({datetime:{mask:function(e){return m.S=e.i18n.ordinalSuffix.join("|"),e.inputFormat=t[e.inputFormat]||e.inputFormat,e.displayFormat=t[e.displayFormat]||e.displayFormat||e.inputFormat,e.outputFormat=t[e.outputFormat]||e.outputFormat||e.inputFormat,e.placeholder=""!==e.placeholder?e.placeholder:e.inputFormat.replace(/[\[\]]/,""),e.regex=p(e.inputFormat,void 0,e),null},placeholder:"",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"],ordinalSuffix:["st","nd","rd","th"]},postValidation:function(e,t,o,r){r.min=l(r.min,r.inputFormat,r),r.max=l(r.max,r.inputFormat,r);var a,n,i=o,s=l(e.join(""),r.inputFormat,r);return i&&s.date.getTime()==s.date.getTime()&&(a=s,n=i,i=(i=(!isFinite(a.rawday)||"29"==a.day&&!isFinite(a.rawyear)||new Date(a.date.getFullYear(),isFinite(a.rawmonth)?a.month:a.date.getMonth()+1,0).getDate()>=a.day)&&n)&&function(e,t){var o=!0;if(t.min){if(e.rawyear){var r=e.rawyear.replace(/[^0-9]/g,"");o=t.min.year.substr(0,r.length)<=r}e.year===e.rawyear&&t.min.date.getTime()==t.min.date.getTime()&&(o=t.min.date.getTime()<=e.date.getTime())}return o&&t.max&&t.max.date.getTime()==t.max.date.getTime()&&(o=t.max.date.getTime()>=e.date.getTime()),o}(s,r)),t&&i&&o.pos!==t?{buffer:p(r.inputFormat,s,r),refreshFromBuffer:{start:t,end:o.pos}}:i},onKeyDown:function(e,t,o,r){if(e.ctrlKey&&e.keyCode===u.keyCode.RIGHT){for(var a,n=new Date,i="";a=y(r).exec(r.inputFormat);)"d"===a[0].charAt(0)?i+=d(n.getDate(),a[0].length):"m"===a[0].charAt(0)?i+=d(n.getMonth()+1,a[0].length):"yyyy"===a[0]?i+=n.getFullYear().toString():"y"===a[0].charAt(0)&&(i+=d(n.getYear(),a[0].length));this.inputmask._valueSet(i),s(this).trigger("setvalue")}},onUnMask:function(e,t,o){return p(o.outputFormat,l(e,o.inputFormat,o),o,!0)},casing:function(e,t,o,r){return 0==t.nativeDef.indexOf("[ap]")?e.toLowerCase():0==t.nativeDef.indexOf("[AP]")?e.toUpperCase():e},insertMode:!1}}),u});