inputmask.date.extensions.min.js 3.8 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-56
  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(e,t){function n(t){return t.tokenizer||(t.tokenizer="("+e.map(o,function(e,t){return t}).join("|")+")+|.",t.tokenizer=new RegExp(t.tokenizer,"g")),t.tokenizer}function a(e){return 29==e.day&&!isFinite(e.rawyear)||new Date(e.year,e.month,0).getDate()>=e.day}function i(e,t){var n=!0;return t.min&&t.min.date.getTime()===t.min.date.getTime()&&(n=n&&t.min.date.getTime()<=e.getTime()),t.max&&t.max.date.getTime()===t.max.date.getTime()&&(n=n&&t.max.date.getTime()>=e.getTime()),n}function m(t,a){for(var i,m="";i=n(a).exec(t);)m+=o[i[0]]?"("+(e.isFunction(o[i[0]])?o[i[0]](a.min,a.max):o[i[0]])+")":i[0];return m}function r(e,t,a){function i(e){var t=4===e.length?e:(new Date).getFullYear().toString().substr(0,4-e.length)+e;return a.min&&a.min.year&&a.max&&a.max.year?(t=t.replace(/[^0-9]/g,""),t=e.charAt(0)===a.max.year.charAt(0)?e.replace(/[^0-9]/g,"0"):t+a.min.year.substr(t.length)):t=t.replace(/[^0-9]/g,"0"),t}function m(e,t,n){"year"===r?(e[r]=i(t),e["raw"+r]=t):e[r]=n.min&&t.match(/[^0-9]/)?n.min[r]:t}var r,d,y={},u=e;if("string"==typeof u){for(;d=n(a).exec(t);)if("d"===d[0].charAt(0))r="day";else if("m"===d[0].charAt(0))r="month";else if("y"===d[0].charAt(0))r="year";else if("h"===d[0].charAt(0).toLowerCase())r="hour";else if("M"===d[0].charAt(0))r="minutes";else if("s"===d[0].charAt(0))r="seconds";else if(o.hasOwnProperty(d[0]))r="unmatched";else{var s=u.split(d[0])[0];m(y,s,a),u=u.slice((s+d[0]).length),r=void 0}return void 0!==r&&m(y,u,a),y.date=new Date(y.year+"-"+y.month+"-"+y.day),y.datetime=new Date(y.year+"-"+y.month+"-"+y.day+"T"+y.hour+":"+y.minutes+":"+y.seconds),y}}var o={d:"[1-9]|[12][0-9]|3[01]",dd:"0[1-9]|[12][0-9]|3[01]",ddd:"",dddd:"",m:"[1-9]|1[012]",mm:"0[1-9]|1[012]",mmm:"",mmmm:"",yy:"[0-9]{2}",yyyy:"[0-9]{4}",h:"[1-9]|1[0-2]",hh:"0[1-9]|1[0-2]",H:"1?[1-9]|2[0-4]",HH:"[01][1-9]|2[0-4]",M:"[1-5]?[0-9]",MM:"[0-5][0-9]",s:"[1-5]?[0-9]",ss:"[0-5][0-9]",l:"",L:"",t:"",tt:"",T:"",TT:"",Z:"",o:"",S:""},d={default:"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",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 t.extendAliases({datetime:{mask:function(e){return e.inputFormat=d[e.inputFormat]||e.inputFormat,e.displayFormat=d[e.displayFormat]||e.displayFormat||e.inputFormat,e.outputFormat=d[e.outputFormat]||e.outputFormat||e.inputFormat,e.placeholder=e.placeholder!==t.prototype.defaults.placeholder?e.placeholder:e.inputFormat,e.min=r(e.min,e.inputFormat,e),e.max=r(e.max,e.inputFormat,e),e.regex=m(e.inputFormat,e),null},inputFormat:"dd/mm/yyyy HH:MM",displayFormat:void 0,outputFormat:void 0,min:null,max:null,postValidation:function(e,t,n){var m=t,o=r(e.join(""),n.inputFormat,n);return m&&o.date.getTime()===o.date.getTime()&&(m=a(o)),m&&o.datetime.getTime()===o.datetime.getTime()&&(m=i(o.date,n)),m},onKeyDown:function(a,i,m,r){var o=this;if(a.ctrlKey&&a.keyCode===t.keyCode.RIGHT){for(var d,y=new Date,u="";d=n(r).exec(r.inputFormat);)"d"===d[0].charAt(0)?u+=y.getDate().toString():"m"===d[0].charAt(0)?u+=(y.getMonth()+1).toString():"yyyy"===d[0]?u+=y.getFullYear().toString():"yy"===d[0]&&(u+=y.getYear().toString());o.inputmask._valueSet(u),e(o).trigger("setvalue")}},insertMode:!1}}),t});