From fd5794c80dd5038209aa3b810b9e5ad75cbb57dc Mon Sep 17 00:00:00 2001 From: linwu Date: Wed, 13 Dec 2017 15:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD=20-=20?= =?UTF-8?q?=E5=9C=A8=E6=97=A5=E6=9C=9F=E8=8C=83=E5=9B=B4=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E5=B7=A6=E4=B8=8B=E8=A7=92=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=80=89=E4=B8=AD=E5=8A=9F=E8=83=BD=20-=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=A8=E8=BE=93=E5=85=A5=E6=A1=86=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E8=BE=93=E5=85=A5=E6=97=B6=EF=BC=8C=E6=97=A5=E5=8E=86?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC=EF=BC=8C=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81"MM/dd/yyyy"=E7=9A=84=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20-=20=E5=B9=B4=E3=80=81=E6=9C=88=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=A8=A1=E5=BC=8F=E4=B8=8B=EF=BC=8C=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E5=B0=B1=E9=9A=90=E8=97=8F=E9=80=89=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/laydate.js | 2 +- dist/theme/default/laydate.css | 2 +- src/laydate.js | 224 +++++++++++++++++++++++++++++++-- 3 files changed, 216 insertions(+), 12 deletions(-) diff --git a/dist/laydate.js b/dist/laydate.js index 83a12cb..75f5e36 100644 --- a/dist/laydate.js +++ b/dist/laydate.js @@ -1,2 +1,2 @@ /*! laydate-v5.0.9 日期与时间组件 MIT License http://www.layui.com/laydate/ By 贤心 */ - ;!function(){"use strict";var e=window.layui&&layui.define,t={getPath:function(){var e=document.currentScript?document.currentScript.src:function(){for(var e,t=document.scripts,n=t.length-1,a=n;a>0;a--)if("interactive"===t[a].readyState){e=t[a].src;break}return e||t[n].src}();return e.substring(0,e.lastIndexOf("/")+1)}(),getStyle:function(e,t){var n=e.currentStyle?e.currentStyle:window.getComputedStyle(e,null);return n[n.getPropertyValue?"getPropertyValue":"getAttribute"](t)},link:function(e,a,i){if(n.path){var r=document.getElementsByTagName("head")[0],o=document.createElement("link");"string"==typeof a&&(i=a);var s=(i||e).replace(/\.|\//g,""),l="layuicss-"+s,d=0;o.rel="stylesheet",o.href=n.path+e,o.id=l,document.getElementById(l)||r.appendChild(o),"function"==typeof a&&!function c(){return++d>80?window.console&&console.error("laydate.css: Invalid"):void(1989===parseInt(t.getStyle(document.getElementById(l),"width"))?a():setTimeout(c,100))}()}}},n={v:"5.0.9",config:{},index:window.laydate&&window.laydate.v?1e5:0,path:t.getPath,set:function(e){var t=this;return t.config=w.extend({},t.config,e),t},ready:function(a){var i="laydate",r="",o=(e?"modules/laydate/":"theme/")+"default/laydate.css?v="+n.v+r;return e?layui.addcss(o,a,i):t.link(o,a,i),this}},a=function(){var e=this;return{hint:function(t){e.hint.call(e,t)},config:e.config}},i="laydate",r=".layui-laydate",o="layui-this",s="laydate-disabled",l="开始日期超出了结束日期
建议重新选择",d=[100,2e5],c="layui-laydate-static",m="layui-laydate-list",u="laydate-selected",h="layui-laydate-hint",y="laydate-day-prev",f="laydate-day-next",p="layui-laydate-footer",g=".laydate-btns-confirm",v="laydate-time-text",D=".laydate-btns-time",T=function(e){var t=this;t.index=++n.index,t.config=w.extend({},t.config,n.config,e),n.ready(function(){t.init()})},w=function(e){return new C(e)},C=function(e){for(var t=0,n="object"==typeof e?[e]:(this.selector=e,document.querySelectorAll(e||null));t0)return n[0].getAttribute(e)}():n.each(function(n,a){a.setAttribute(e,t)})},C.prototype.removeAttr=function(e){return this.each(function(t,n){n.removeAttribute(e)})},C.prototype.html=function(e){return this.each(function(t,n){n.innerHTML=e})},C.prototype.val=function(e){return this.each(function(t,n){n.value=e})},C.prototype.append=function(e){return this.each(function(t,n){"object"==typeof e?n.appendChild(e):n.innerHTML=n.innerHTML+e})},C.prototype.remove=function(e){return this.each(function(t,n){e?n.removeChild(e):n.parentNode.removeChild(n)})},C.prototype.on=function(e,t){return this.each(function(n,a){a.attachEvent?a.attachEvent("on"+e,function(e){e.target=e.srcElement,t.call(a,e)}):a.addEventListener(e,t,!1)})},C.prototype.off=function(e,t){return this.each(function(n,a){a.detachEvent?a.detachEvent("on"+e,t):a.removeEventListener(e,t,!1)})},T.isLeapYear=function(e){return e%4===0&&e%100!==0||e%400===0},T.prototype.config={type:"date",range:!1,format:"yyyy-MM-dd",value:null,min:"1900-1-1",max:"2099-12-31",trigger:"focus",show:!1,showBottom:!0,btns:["clear","now","confirm"],lang:"cn",theme:"default",position:null,calendar:!1,mark:{},zIndex:null,done:null,change:null},T.prototype.lang=function(){var e=this,t=e.config,n={cn:{weeks:["日","一","二","三","四","五","六"],time:["时","分","秒"],timeTips:"选择时间",startTime:"开始时间",endTime:"结束时间",dateTips:"返回日期",month:["一","二","三","四","五","六","七","八","九","十","十一","十二"],tools:{confirm:"确定",clear:"清空",now:"现在"}},en:{weeks:["Su","Mo","Tu","We","Th","Fr","Sa"],time:["Hours","Minutes","Seconds"],timeTips:"Select Time",startTime:"Start Time",endTime:"End Time",dateTips:"Select Date",month:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],tools:{confirm:"Confirm",clear:"Clear",now:"Now"}}};return n[t.lang]||n.cn},T.prototype.init=function(){var e=this,t=e.config,n="yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s",a="static"===t.position,i={year:"yyyy",month:"yyyy-MM",date:"yyyy-MM-dd",time:"HH:mm:ss",datetime:"yyyy-MM-dd HH:mm:ss"};t.elem=w(t.elem),t.eventElem=w(t.eventElem),t.elem[0]&&(t.range===!0&&(t.range="-"),t.format===i.date&&(t.format=i[t.type]),e.format=t.format.match(new RegExp(n+"|.","g"))||[],e.EXP_IF="",e.EXP_SPLIT="",w.each(e.format,function(t,a){var i=new RegExp(n).test(a)?"\\d{"+function(){return new RegExp(n).test(e.format[0===t?t+1:t-1]||"")?/^yyyy|y$/.test(a)?4:a.length:/^yyyy$/.test(a)?"1,4":/^y$/.test(a)?"1,308":"1,2"}()+"}":"\\"+a;e.EXP_IF=e.EXP_IF+i,e.EXP_SPLIT=e.EXP_SPLIT+"("+i+")"}),e.EXP_IF=new RegExp("^"+(t.range?e.EXP_IF+"\\s\\"+t.range+"\\s"+e.EXP_IF:e.EXP_IF)+"$"),e.EXP_SPLIT=new RegExp("^"+e.EXP_SPLIT+"$",""),e.isInput(t.elem[0])||"focus"===t.trigger&&(t.trigger="click"),t.elem.attr("lay-key")||(t.elem.attr("lay-key",e.index),t.eventElem.attr("lay-key",e.index)),t.mark=w.extend({},t.calendar&&"cn"===t.lang?{"0-1-1":"元旦","0-2-14":"情人","0-3-8":"妇女","0-3-12":"植树","0-4-1":"愚人","0-5-1":"劳动","0-5-4":"青年","0-6-1":"儿童","0-9-10":"教师","0-9-18":"国耻","0-10-1":"国庆","0-12-25":"圣诞"}:{},t.mark),w.each(["min","max"],function(e,n){var a=[],i=[];if("number"==typeof t[n]){var r=t[n],o=(new Date).getTime(),s=864e5,l=new Date(r?r0)return!0;var a=w.elem("div",{"class":"layui-laydate-header"}),i=[function(){var e=w.elem("i",{"class":"layui-icon laydate-icon laydate-prev-y"});return e.innerHTML="",e}(),function(){var e=w.elem("i",{"class":"layui-icon laydate-icon laydate-prev-m"});return e.innerHTML="",e}(),function(){var e=w.elem("div",{"class":"laydate-set-ym"}),t=w.elem("span"),n=w.elem("span");return e.appendChild(t),e.appendChild(n),e}(),function(){var e=w.elem("i",{"class":"layui-icon laydate-icon laydate-next-m"});return e.innerHTML="",e}(),function(){var e=w.elem("i",{"class":"layui-icon laydate-icon laydate-next-y"});return e.innerHTML="",e}()],d=w.elem("div",{"class":"layui-laydate-content"}),c=w.elem("table"),m=w.elem("thead"),u=w.elem("tr");w.each(i,function(e,t){a.appendChild(t)}),m.appendChild(u),w.each(new Array(6),function(e){var t=c.insertRow(0);w.each(new Array(7),function(a){if(0===e){var i=w.elem("th");i.innerHTML=n.weeks[a],u.appendChild(i)}t.insertCell(a)})}),c.insertBefore(m,c.children[0]),d.appendChild(c),r[e]=w.elem("div",{"class":"layui-laydate-main laydate-main-list-"+e}),r[e].appendChild(a),r[e].appendChild(d),o.push(i),s.push(d),l.push(c)}),w(d).html(function(){var e=[],i=[];return"datetime"===t.type&&e.push(''+n.timeTips+""),w.each(t.btns,function(e,r){var o=n.tools[r]||"btn";t.range&&"now"===r||(a&&"clear"===r&&(o="cn"===t.lang?"重置":"Reset"),i.push(''+o+""))}),e.push('"),e.join("")}()),w.each(r,function(e,t){i.appendChild(t)}),t.showBottom&&i.appendChild(d),/^#/.test(t.theme)){var m=w.elem("style"),u=["#{{id}} .layui-laydate-header{background-color:{{theme}};}","#{{id}} .layui-this{background-color:{{theme}} !important;}"].join("").replace(/{{id}}/g,e.elemID).replace(/{{theme}}/g,t.theme);"styleSheet"in m?(m.setAttribute("type","text/css"),m.styleSheet.cssText=u):m.innerHTML=u,w(i).addClass("laydate-theme-molv"),i.appendChild(m)}e.remove(T.thisElemDate),a?t.elem.append(i):(document.body.appendChild(i),e.position()),e.checkDate().calendar(),e.changeEvent(),T.thisElemDate=e.elemID,"function"==typeof t.ready&&t.ready(w.extend({},t.dateTime,{month:t.dateTime.month+1}))},T.prototype.remove=function(e){var t=this,n=(t.config,w("#"+(e||t.elemID)));return n.hasClass(c)||t.checkDate(function(){n.remove()}),t},T.prototype.position=function(){var e=this,t=e.config,n=e.bindElem||t.elem[0],a=n.getBoundingClientRect(),i=e.elem.offsetWidth,r=e.elem.offsetHeight,o=function(e){return e=e?"scrollLeft":"scrollTop",document.body[e]|document.documentElement[e]},s=function(e){return document.documentElement[e?"clientWidth":"clientHeight"]},l=5,d=a.left,c=a.bottom;d+i+l>s("width")&&(d=s("width")-i-l),c+r+l>s()&&(c=a.top>r?a.top-r:s()-r,c-=2*l),t.position&&(e.elem.style.position=t.position),e.elem.style.left=d+("fixed"===t.position?0:o(1))+"px",e.elem.style.top=c+("fixed"===t.position?0:o())+"px"},T.prototype.hint=function(e){var t=this,n=(t.config,w.elem("div",{"class":h}));n.innerHTML=e||"",w(t.elem).find("."+h).remove(),t.elem.appendChild(n),clearTimeout(t.hinTimer),t.hinTimer=setTimeout(function(){w(t.elem).find("."+h).remove()},3e3)},T.prototype.getAsYM=function(e,t,n){return n?t--:t++,t<0&&(t=11,e--),t>11&&(t=0,e++),[e,t]},T.prototype.systemDate=function(e){var t=e||new Date;return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),hours:e?e.getHours():0,minutes:e?e.getMinutes():0,seconds:e?e.getSeconds():0}},T.prototype.checkDate=function(e){var t,a,i=this,r=(new Date,i.config),o=r.dateTime=r.dateTime||i.systemDate(),s=i.bindElem||r.elem[0],l=(i.isInput(s)?"val":"html",i.isInput(s)?s.value:"static"===r.position?"":s.innerHTML),c=function(e){e.year>d[1]&&(e.year=d[1],a=!0),e.month>11&&(e.month=11,a=!0),e.hours>23&&(e.hours=0,a=!0),e.minutes>59&&(e.minutes=0,e.hours++,a=!0),e.seconds>59&&(e.seconds=0,e.minutes++,a=!0),t=n.getEndDate(e.month+1,e.year),e.date>t&&(e.date=t,a=!0)},m=function(e,t,n){var o=["startTime","endTime"];t=(t.match(i.EXP_SPLIT)||[]).slice(1),n=n||0,r.range&&(i[o[n]]=i[o[n]]||{}),w.each(i.format,function(s,l){var c=parseFloat(t[s]);t[s].length必须遵循下述格式:
"+(r.range?r.format+" "+r.range+" "+r.format:r.format)+"
已为你重置"),a=!0):l&&l.constructor===Date?r.dateTime=i.systemDate(l):(r.dateTime=i.systemDate(),delete i.startState,delete i.endState,delete i.startDate,delete i.endDate,delete i.startTime,delete i.endTime),c(o),a&&l&&i.setValue(r.range?i.endDate?i.parse():"":i.parse()),e&&e(),i)},T.prototype.mark=function(e,t){var n,a=this,i=a.config;return w.each(i.mark,function(e,a){var i=e.split("-");i[0]!=t[0]&&0!=i[0]||i[1]!=t[1]&&0!=i[1]||i[2]!=t[2]||(n=a||t[2])}),n&&e.html(''+n+""),a},T.prototype.limit=function(e,t,n,a){var i,r=this,o=r.config,l={},d=o[n>41?"endDate":"dateTime"],c=w.extend({},d,t||{});return w.each({now:c,min:o.min,max:o.max},function(e,t){l[e]=r.newDate(w.extend({year:t.year,month:t.month,date:t.date},function(){var e={};return w.each(a,function(n,a){e[a]=t[a]}),e}())).getTime()}),i=l.nowl.max,e&&e[i?"addClass":"removeClass"](s),i},T.prototype.calendar=function(e){var t,a,i,r=this,s=r.config,l=e||s.dateTime,c=new Date,m=r.lang(),u="date"!==s.type&&"datetime"!==s.type,h=e?1:0,y=w(r.table[h]).find("td"),f=w(r.elemHeader[h][2]).find("span");if(l.yeard[1]&&(l.year=d[1],r.hint("最高只能支持到公元"+d[1]+"年")),r.firstDate||(r.firstDate=w.extend({},l)),c.setFullYear(l.year,l.month,1),t=c.getDay(),a=n.getEndDate(l.month||12,l.year),i=n.getEndDate(l.month+1,l.year),w.each(y,function(e,n){var d=[l.year,l.month],c=0;n=w(n),n.removeAttr("class"),e=t&&e=n.firstDate.year&&(r.month=a.max.month,r.date=a.max.date),n.limit(w(i),r,t),M++}),w(u[f?0:1]).attr("lay-ym",M-8+"-"+T[1]).html(b+p+" - "+(M-1+p))}else if("month"===e)w.each(new Array(12),function(e){var i=w.elem("li",{"lay-ym":e}),s={year:T[0],month:e};e+1==T[1]&&w(i).addClass(o),i.innerHTML=r.month[e]+(f?"月":""),d.appendChild(i),T[0]=n.firstDate.year&&(s.date=a.max.date),n.limit(w(i),s,t)}),w(u[f?0:1]).attr("lay-ym",T[0]+"-"+T[1]).html(T[0]+p);else if("time"===e){var E=function(){w(d).find("ol").each(function(e,a){w(a).find("li").each(function(a,i){n.limit(w(i),[{hours:a},{hours:n[x].hours,minutes:a},{hours:n[x].hours,minutes:n[x].minutes,seconds:a}][e],t,[["hours"],["hours","minutes"],["hours","minutes","seconds"]][e])})}),a.range||n.limit(w(n.footer).find(g),n[x],0,["hours","minutes","seconds"])};a.range?n[x]||(n[x]={hours:0,minutes:0,seconds:0}):n[x]=i,w.each([24,60,60],function(e,t){var a=w.elem("li"),i=["

"+r.time[e]+"

    "];w.each(new Array(t),function(t){i.push(""+w.digit(t,2)+"")}),a.innerHTML=i.join("")+"
",d.appendChild(a)}),E()}if(y&&h.removeChild(y),h.appendChild(d),"year"===e||"month"===e)w(n.elemMain[t]).addClass("laydate-ym-show"),w(d).find("li").on("click",function(){var r=0|w(this).attr("lay-ym");if(!w(this).hasClass(s)){if(0===t)i[e]=r,l&&(n.startDate[e]=r),n.limit(w(n.footer).find(g),null,0);else if(l)n.endDate[e]=r;else{var c="year"===e?n.getAsYM(r,T[1]-1,"sub"):n.getAsYM(T[0],r,"sub");w.extend(i,{year:c[0],month:c[1]})}"year"===a.type||"month"===a.type?(w(d).find("."+o).removeClass(o),w(this).addClass(o),"month"===a.type&&"year"===e&&(n.listYM[t][0]=r,l&&(n[["startDate","endDate"][t]].year=r),n.list("month",t))):(n.checkDate("limit").calendar(),n.closeList()),n.setBtnStatus(),a.range||n.done(null,"change"),w(n.footer).find(D).removeClass(s)}});else{var S=w.elem("span",{"class":v}),k=function(){w(d).find("ol").each(function(e){var t=this,a=w(t).find("li");t.scrollTop=30*(n[x][C[e]]-2),t.scrollTop<=0&&a.each(function(e,n){if(!w(this).hasClass(s))return t.scrollTop=30*(e-2),!0})})},H=w(c[2]).find("."+v);k(),S.innerHTML=a.range?[r.startTime,r.endTime][t]:r.timeTips,w(n.elemMain[t]).addClass("laydate-time-show"),H[0]&&H.remove(),c[2].appendChild(S),w(d).find("ol").each(function(e){var t=this;w(t).find("li").on("click",function(){var r=0|this.innerHTML;w(this).hasClass(s)||(a.range?n[x][C[e]]=r:i[C[e]]=r,w(t).find("."+o).removeClass(o),w(this).addClass(o),E(),k(),(n.endDate||"time"===a.type)&&n.done(null,"change"),n.setBtnStatus())})})}return n},T.prototype.listYM=[],T.prototype.closeList=function(){var e=this;e.config;w.each(e.elemCont,function(t,n){w(this).find("."+m).remove(),w(e.elemMain[t]).removeClass("laydate-ym-show laydate-time-show")}),w(e.elem).find("."+v).remove()},T.prototype.setBtnStatus=function(e,t,n){var a,i=this,r=i.config,o=w(i.footer).find(g),d=r.range&&"date"!==r.type&&"time"!==r.type;d&&(t=t||i.startDate,n=n||i.endDate,a=i.newDate(t).getTime()>i.newDate(n).getTime(),i.limit(null,t)||i.limit(null,n)?o.addClass(s):o[a?"addClass":"removeClass"](s),e&&a&&i.hint("string"==typeof e?l.replace(/日期/g,e):l))},T.prototype.parse=function(e,t){var n=this,a=n.config,i=t||(e?w.extend({},n.endDate,n.endTime):a.range?w.extend({},n.startDate,n.startTime):a.dateTime),r=n.format.concat();return w.each(r,function(e,t){/yyyy|y/.test(t)?r[e]=w.digit(i.year,t.length):/MM|M/.test(t)?r[e]=w.digit(i.month+1,t.length):/dd|d/.test(t)?r[e]=w.digit(i.date,t.length):/HH|H/.test(t)?r[e]=w.digit(i.hours,t.length):/mm|m/.test(t)?r[e]=w.digit(i.minutes,t.length):/ss|s/.test(t)&&(r[e]=w.digit(i.seconds,t.length))}),a.range&&!e?r.join("")+" "+a.range+" "+n.parse(1):r.join("")},T.prototype.newDate=function(e){return e=e||{},new Date(e.year||1,e.month||0,e.date||1,e.hours||0,e.minutes||0,e.seconds||0)},T.prototype.setValue=function(e){var t=this,n=t.config,a=t.bindElem||n.elem[0],i=t.isInput(a)?"val":"html";return"static"===n.position||w(a)[i](e||""),this},T.prototype.stampRange=function(){var e,t,n=this,a=n.config,i=w(n.elem).find("td");if(a.range&&!n.endDate&&w(n.footer).find(g).addClass(s),n.endDate)return e=n.newDate({year:n.startDate.year,month:n.startDate.month,date:n.startDate.date}).getTime(),t=n.newDate({year:n.endDate.year,month:n.endDate.month,date:n.endDate.date}).getTime(),e>t?n.hint(l):void w.each(i,function(a,i){var r=w(i).attr("lay-ymd").split("-"),s=n.newDate({year:r[0],month:r[1]-1,date:r[2]}).getTime();w(i).removeClass(u+" "+o),s!==e&&s!==t||w(i).addClass(w(i).hasClass(y)||w(i).hasClass(f)?u:o),s>e&&s0;a--)if("interactive"===t[a].readyState){e=t[a].src;break}return e||t[n].src}();return e.substring(0,e.lastIndexOf("/")+1)}(),getStyle:function(e,t){var n=e.currentStyle?e.currentStyle:window.getComputedStyle(e,null);return n[n.getPropertyValue?"getPropertyValue":"getAttribute"](t)},link:function(e,a,r){if(n.path){var o=document.getElementsByTagName("head")[0],i=document.createElement("link");"string"==typeof a&&(r=a);var s=(r||e).replace(/\.|\//g,""),l="layuicss-"+s,d=0;i.rel="stylesheet",i.href=n.path+e,i.id=l,document.getElementById(l)||o.appendChild(i),"function"==typeof a&&!function c(){return++d>80?window.console&&console.error("laydate.css: Invalid"):void(1989===parseInt(t.getStyle(document.getElementById(l),"width"))?a():setTimeout(c,100))}()}}},n={v:"5.0.9",config:{},index:window.laydate&&window.laydate.v?1e5:0,path:t.getPath,set:function(e){var t=this;return t.config=x.extend({},t.config,e),t},ready:function(a){var r="laydate",o="",i=(e?"modules/laydate/":"theme/")+"default/laydate.css?v="+n.v+o;return e?layui.addcss(i,a,r):t.link(i,a,r),this}},a=function(){var e=this;return{hint:function(t){e.hint.call(e,t)},config:e.config}},r="laydate",o=".layui-laydate",i="layui-this",s="laydate-disabled",l="开始日期超出了结束日期
建议重新选择",d=[100,2e5],c="layui-laydate-static",u="layui-laydate-list",m="laydate-selected",h="layui-laydate-hint",y="laydate-day-prev",p="laydate-day-next",f="layui-laydate-footer",g=".laydate-btns-confirm",v="laydate-time-text",D=".laydate-btns-time",T=function(e){var t=this;t.index=++n.index,t.config=x.extend({},t.config,n.config,e),n.ready(function(){t.init()})},x=function(e){return new w(e)},w=function(e){for(var t=0,n="object"==typeof e?[e]:(this.selector=e,document.querySelectorAll(e||null));t0)return n[0].getAttribute(e)}():n.each(function(n,a){a.setAttribute(e,t)})},w.prototype.removeAttr=function(e){return this.each(function(t,n){n.removeAttribute(e)})},w.prototype.html=function(e){return this.each(function(t,n){n.innerHTML=e})},w.prototype.val=function(e){return this.each(function(t,n){n.value=e})},w.prototype.append=function(e){return this.each(function(t,n){"object"==typeof e?n.appendChild(e):n.innerHTML=n.innerHTML+e})},w.prototype.remove=function(e){return this.each(function(t,n){e?n.removeChild(e):n.parentNode.removeChild(n)})},w.prototype.on=function(e,t){return this.each(function(n,a){a.attachEvent?a.attachEvent("on"+e,function(e){e.target=e.srcElement,t.call(a,e)}):a.addEventListener(e,t,!1)})},w.prototype.off=function(e,t){return this.each(function(n,a){a.detachEvent?a.detachEvent("on"+e,t):a.removeEventListener(e,t,!1)})},T.isLeapYear=function(e){return e%4===0&&e%100!==0||e%400===0},T.prototype.config={type:"date",range:!1,format:"yyyy-MM-dd",value:null,min:"1900-1-1",max:"2099-12-31",trigger:"focus",show:!1,showBottom:!0,btns:["clear","now","confirm"],lang:"cn",theme:"default",position:null,calendar:!1,mark:{},zIndex:null,done:null,change:null},T.prototype.lang=function(){var e=this,t=e.config,n={cn:{weeks:["日","一","二","三","四","五","六"],time:["时","分","秒"],timeTips:"选择时间",startTime:"开始时间",endTime:"结束时间",dateTips:"返回日期",month:["一","二","三","四","五","六","七","八","九","十","十一","十二"],tools:{confirm:"确定",clear:"清空",now:"现在"}},en:{weeks:["Su","Mo","Tu","We","Th","Fr","Sa"],time:["Hours","Minutes","Seconds"],timeTips:"Select Time",startTime:"Start Time",endTime:"End Time",dateTips:"Select Date",month:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],tools:{confirm:"Confirm",clear:"Clear",now:"Now"}}};return n[t.lang]||n.cn},T.prototype.init=function(){var e=this,t=e.config,n="yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s",a="static"===t.position,r={year:"yyyy",month:"yyyy-MM",date:"yyyy-MM-dd",time:"HH:mm:ss",datetime:"yyyy-MM-dd HH:mm:ss"};t.elem=x(t.elem),t.eventElem=x(t.eventElem),t.elem[0]&&(t.range===!0&&(t.range="-"),t.format===r.date&&(t.format=r[t.type]),e.format=t.format.match(new RegExp(n+"|.","g"))||[],e.EXP_IF="",e.EXP_SPLIT="",x.each(e.format,function(t,a){var r=new RegExp(n).test(a)?"\\d{"+function(){return new RegExp(n).test(e.format[0===t?t+1:t-1]||"")?/^yyyy|y$/.test(a)?4:a.length:/^yyyy$/.test(a)?"1,4":/^y$/.test(a)?"1,308":"1,2"}()+"}":"\\"+a;e.EXP_IF=e.EXP_IF+r,e.EXP_SPLIT=e.EXP_SPLIT+"("+r+")"}),e.EXP_IF=new RegExp("^"+(t.range?e.EXP_IF+"\\s\\"+t.range+"\\s"+e.EXP_IF:e.EXP_IF)+"$"),e.EXP_SPLIT=new RegExp("^"+e.EXP_SPLIT+"$",""),e.isInput(t.elem[0])||"focus"===t.trigger&&(t.trigger="click"),t.elem.attr("lay-key")||(t.elem.attr("lay-key",e.index),t.eventElem.attr("lay-key",e.index)),t.mark=x.extend({},t.calendar&&"cn"===t.lang?{"0-1-1":"元旦","0-2-14":"情人","0-3-8":"妇女","0-3-12":"植树","0-4-1":"愚人","0-5-1":"劳动","0-5-4":"青年","0-6-1":"儿童","0-9-10":"教师","0-9-18":"国耻","0-10-1":"国庆","0-12-25":"圣诞"}:{},t.mark),x.each(["min","max"],function(e,n){var a=[],r=[];if("number"==typeof t[n]){var o=t[n],i=(new Date).getTime(),s=864e5,l=new Date(o?o0)return!0;var a=x.elem("div",{"class":"layui-laydate-header"}),r=[function(){var e=x.elem("i",{"class":"layui-icon laydate-icon laydate-prev-y"});return e.innerHTML="",e}(),function(){var e=x.elem("i",{"class":"layui-icon laydate-icon laydate-prev-m"});return e.innerHTML="",e}(),function(){var e=x.elem("div",{"class":"laydate-set-ym"}),t=x.elem("span"),n=x.elem("span");return e.appendChild(t),e.appendChild(n),e}(),function(){var e=x.elem("i",{"class":"layui-icon laydate-icon laydate-next-m"});return e.innerHTML="",e}(),function(){var e=x.elem("i",{"class":"layui-icon laydate-icon laydate-next-y"});return e.innerHTML="",e}()],d=x.elem("div",{"class":"layui-laydate-content"}),c=x.elem("table"),u=x.elem("thead"),m=x.elem("tr");x.each(r,function(e,t){a.appendChild(t)}),u.appendChild(m),x.each(new Array(6),function(e){var t=c.insertRow(0);x.each(new Array(7),function(a){if(0===e){var r=x.elem("th");r.innerHTML=n.weeks[a],m.appendChild(r)}t.insertCell(a)})}),c.insertBefore(u,c.children[0]),d.appendChild(c),o[e]=x.elem("div",{"class":"layui-laydate-main laydate-main-list-"+e}),o[e].appendChild(a),o[e].appendChild(d),i.push(r),s.push(d),l.push(c)}),x(d).html(function(){var r=[],o=[],i=[];return"datetime"===t.type&&r.push(''+n.timeTips+""),x.each(t.btns,function(e,r){var i=n.tools[r]||"btn";t.range&&"now"===r||(a&&"clear"===r&&(i="cn"===t.lang?"重置":"Reset"),o.push(''+i+""))}),t.range&&("date"==e.config.type&&(i.push(''+("cn"==t.lang?"最近30天":"30days")+""),i.push(''+("cn"==t.lang?"上月":"-1month")+""),i.push(''+("cn"==t.lang?"本月":"month")+"")),i.push(''+("cn"==t.lang?"上季度":"-1quarter")+""),i.push(''+("cn"==t.lang?"本季度":"quarter")+""),i.push(''+("cn"==t.lang?"上年":"-1year")+""),i.push(''+("cn"==t.lang?"今年":"year")+"")),r.push('"),r.join("")}()),x.each(o,function(e,t){r.appendChild(t)}),t.showBottom&&r.appendChild(d),/^#/.test(t.theme)){var u=x.elem("style"),m=["#{{id}} .layui-laydate-header{background-color:{{theme}};}","#{{id}} .layui-this{background-color:{{theme}} !important;}"].join("").replace(/{{id}}/g,e.elemID).replace(/{{theme}}/g,t.theme);"styleSheet"in u?(u.setAttribute("type","text/css"),u.styleSheet.cssText=m):u.innerHTML=m,x(r).addClass("laydate-theme-molv"),r.appendChild(u)}e.remove(T.thisElemDate),a?t.elem.append(r):(document.body.appendChild(r),e.position()),e.checkDate().calendar(),e.changeEvent(),T.thisElemDate=e.elemID,"function"==typeof t.ready&&t.ready(x.extend({},t.dateTime,{month:t.dateTime.month+1}))},T.prototype.remove=function(e){var t=this,n=(t.config,x("#"+(e||t.elemID)));return n.hasClass(c)||t.checkDate(function(){n.remove()}),t},T.prototype.position=function(){var e=this,t=e.config,n=e.bindElem||t.elem[0],a=n.getBoundingClientRect(),r=e.elem.offsetWidth,o=e.elem.offsetHeight,i=function(e){return e=e?"scrollLeft":"scrollTop",document.body[e]|document.documentElement[e]},s=function(e){return document.documentElement[e?"clientWidth":"clientHeight"]},l=5,d=a.left,c=a.bottom;d+r+l>s("width")&&(d=s("width")-r-l),c+o+l>s()&&(c=a.top>o?a.top-o:s()-o,c-=2*l),t.position&&(e.elem.style.position=t.position),e.elem.style.left=d+("fixed"===t.position?0:i(1))+"px",e.elem.style.top=c+("fixed"===t.position?0:i())+"px"},T.prototype.hint=function(e){var t=this,n=(t.config,x.elem("div",{"class":h}));n.innerHTML=e||"",x(t.elem).find("."+h).remove(),t.elem.appendChild(n),clearTimeout(t.hinTimer),t.hinTimer=setTimeout(function(){x(t.elem).find("."+h).remove()},3e3)},T.prototype.getAsYM=function(e,t,n){return n?t--:t++,t<0&&(t=11,e--),t>11&&(t=0,e++),[e,t]},T.prototype.systemDate=function(e){var t=e||new Date;return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),hours:e?e.getHours():0,minutes:e?e.getMinutes():0,seconds:e?e.getSeconds():0}},T.prototype.checkDate=function(e){var t,a,r=this,o=(new Date,r.config),i=o.dateTime=o.dateTime||r.systemDate(),s=r.bindElem||o.elem[0],l=(r.isInput(s)?"val":"html",r.isInput(s)?s.value:"static"===o.position?"":s.innerHTML),c=function(e){e.year>d[1]&&(e.year=d[1],a=!0),e.month>11&&(e.month=11,a=!0),e.hours>23&&(e.hours=0,a=!0),e.minutes>59&&(e.minutes=0,e.hours++,a=!0),e.seconds>59&&(e.seconds=0,e.minutes++,a=!0),t=n.getEndDate(e.month+1,e.year),e.date>t&&(e.date=t,a=!0)},u=function(e,t,n){var i=["startTime","endTime"];t=(t.match(r.EXP_SPLIT)||[]).slice(1),n=n||0,o.range&&(r[i[n]]=r[i[n]]||{}),x.each(r.format,function(s,l){var c=parseFloat(t[s]);t[s].length必须遵循下述格式:
"+(o.range?o.format+" "+o.range+" "+o.format:o.format)+"
已为你重置"),a=!0):l&&l.constructor===Date?o.dateTime=r.systemDate(l):(o.dateTime=r.systemDate(),delete r.startState,delete r.endState,delete r.startDate,delete r.endDate,delete r.startTime,delete r.endTime),c(i),a&&l&&r.setValue(o.range?r.endDate?r.parse():"":r.parse()),e&&e(),r)},T.prototype.mark=function(e,t){var n,a=this,r=a.config;return x.each(r.mark,function(e,a){var r=e.split("-");r[0]!=t[0]&&0!=r[0]||r[1]!=t[1]&&0!=r[1]||r[2]!=t[2]||(n=a||t[2])}),n&&e.html(''+n+""),a},T.prototype.limit=function(e,t,n,a){var r,o=this,i=o.config,l={},d=i[n>41?"endDate":"dateTime"],c=x.extend({},d,t||{});return x.each({now:c,min:i.min,max:i.max},function(e,t){l[e]=o.newDate(x.extend({year:t.year,month:t.month,date:t.date},function(){var e={};return x.each(a,function(n,a){e[a]=t[a]}),e}())).getTime()}),r=l.nowl.max,e&&e[r?"addClass":"removeClass"](s),r},T.prototype.calendar=function(e){var t,a,r,o=this,s=o.config,l=e||s.dateTime,c=new Date,u=o.lang(),m="date"!==s.type&&"datetime"!==s.type,h=e?1:0,y=x(o.table[h]).find("td"),p=x(o.elemHeader[h][2]).find("span");if(l.yeard[1]&&(l.year=d[1],o.hint("最高只能支持到公元"+d[1]+"年")),o.firstDate||(o.firstDate=x.extend({},l)),c.setFullYear(l.year,l.month,1),t=c.getDay(),a=n.getEndDate(l.month||12,l.year),r=n.getEndDate(l.month+1,l.year),x.each(y,function(e,n){var d=[l.year,l.month],c=0;n=x(n),n.removeAttr("class"),e=t&&e=n.firstDate.year&&(o.month=a.max.month,o.date=a.max.date),n.limit(x(r),o,t),C++}),x(m[p?0:1]).attr("lay-ym",C-8+"-"+T[1]).html(b+f+" - "+(C-1+f))}else if("month"===e)x.each(new Array(12),function(e){var r=x.elem("li",{"lay-ym":e}),s={year:T[0],month:e};e+1==T[1]&&x(r).addClass(i),r.innerHTML=o.month[e]+(p?"月":""),d.appendChild(r),T[0]=n.firstDate.year&&(s.date=a.max.date),n.limit(x(r),s,t)}),x(m[p?0:1]).attr("lay-ym",T[0]+"-"+T[1]).html(T[0]+f);else if("time"===e){var E=function(){x(d).find("ol").each(function(e,a){x(a).find("li").each(function(a,r){n.limit(x(r),[{hours:a},{hours:n[M].hours,minutes:a},{hours:n[M].hours,minutes:n[M].minutes,seconds:a}][e],t,[["hours"],["hours","minutes"],["hours","minutes","seconds"]][e])})}),a.range||n.limit(x(n.footer).find(g),n[M],0,["hours","minutes","seconds"])};a.range?n[M]||(n[M]={hours:0,minutes:0,seconds:0}):n[M]=r,x.each([24,60,60],function(e,t){var a=x.elem("li"),r=["

"+o.time[e]+"

    "];x.each(new Array(t),function(t){r.push(""+x.digit(t,2)+"")}),a.innerHTML=r.join("")+"
",d.appendChild(a)}),E()}if(y&&h.removeChild(y),h.appendChild(d),"year"===e||"month"===e)x(n.elemMain[t]).addClass("laydate-ym-show"),x(d).find("li").on("click",function(){var o=0|x(this).attr("lay-ym");if(!x(this).hasClass(s)){if(0===t)r[e]=o,l&&(n.startDate[e]=o),n.limit(x(n.footer).find(g),null,0),("month"==e&&"month"==n.config.type||"year"==e&&"year"==n.config.type)&&n.setValue(n.parse()).remove().done();else if(l)n.endDate[e]=o;else{var c="year"===e?n.getAsYM(o,T[1]-1,"sub"):n.getAsYM(T[0],o,"sub");x.extend(r,{year:c[0],month:c[1]})}"year"===a.type||"month"===a.type?(x(d).find("."+i).removeClass(i),x(this).addClass(i),"month"===a.type&&"year"===e&&(n.listYM[t][0]=o,l&&(n[["startDate","endDate"][t]].year=o),n.list("month",t))):(n.checkDate("limit").calendar(),n.closeList()),n.setBtnStatus(),a.range||n.done(null,"change"),x(n.footer).find(D).removeClass(s)}});else{var S=x.elem("span",{"class":v}),k=function(){x(d).find("ol").each(function(e){var t=this,a=x(t).find("li");t.scrollTop=30*(n[M][w[e]]-2),t.scrollTop<=0&&a.each(function(e,n){if(!x(this).hasClass(s))return t.scrollTop=30*(e-2),!0})})},I=x(c[2]).find("."+v);k(),S.innerHTML=a.range?[o.startTime,o.endTime][t]:o.timeTips,x(n.elemMain[t]).addClass("laydate-time-show"),I[0]&&I.remove(),c[2].appendChild(S),x(d).find("ol").each(function(e){var t=this;x(t).find("li").on("click",function(){var o=0|this.innerHTML;x(this).hasClass(s)||(a.range?n[M][w[e]]=o:r[w[e]]=o,x(t).find("."+i).removeClass(i),x(this).addClass(i),E(),k(),(n.endDate||"time"===a.type)&&n.done(null,"change"),n.setBtnStatus())})})}return n},T.prototype.listYM=[],T.prototype.closeList=function(){var e=this;e.config;x.each(e.elemCont,function(t,n){x(this).find("."+u).remove(),x(e.elemMain[t]).removeClass("laydate-ym-show laydate-time-show")}),x(e.elem).find("."+v).remove()},T.prototype.setBtnStatus=function(e,t,n){var a,r=this,o=r.config,i=x(r.footer).find(g),d=o.range&&"date"!==o.type&&"time"!==o.type;d&&(t=t||r.startDate,n=n||r.endDate,a=r.newDate(t).getTime()>r.newDate(n).getTime(),r.limit(null,t)||r.limit(null,n)?i.addClass(s):i[a?"addClass":"removeClass"](s),e&&a&&r.hint("string"==typeof e?l.replace(/日期/g,e):l))},T.prototype.parse=function(e,t){var n=this,a=n.config,r=t||(e?x.extend({},n.endDate,n.endTime):a.range?x.extend({},n.startDate,n.startTime):a.dateTime),o=n.format.concat();return x.each(o,function(e,t){/yyyy|y/.test(t)?o[e]=x.digit(r.year,t.length):/MM|M/.test(t)?o[e]=x.digit(r.month+1,t.length):/dd|d/.test(t)?o[e]=x.digit(r.date,t.length):/HH|H/.test(t)?o[e]=x.digit(r.hours,t.length):/mm|m/.test(t)?o[e]=x.digit(r.minutes,t.length):/ss|s/.test(t)&&(o[e]=x.digit(r.seconds,t.length))}),a.range&&!e?o.join("")+" "+a.range+" "+n.parse(1):o.join("")},T.prototype.newDate=function(e){return e=e||{},new Date(e.year||1,e.month||0,e.date||1,e.hours||0,e.minutes||0,e.seconds||0)},T.prototype.setValue=function(e){var t=this,n=t.config,a=t.bindElem||n.elem[0],r=t.isInput(a)?"val":"html";return"static"===n.position||x(a)[r](e||""),this},T.prototype.stampRange=function(){var e,t,n=this,a=n.config,r=x(n.elem).find("td");if(a.range&&!n.endDate&&x(n.footer).find(g).addClass(s),n.endDate)return e=n.newDate({year:n.startDate.year,month:n.startDate.month,date:n.startDate.date}).getTime(),t=n.newDate({year:n.endDate.year,month:n.endDate.month,date:n.endDate.date}).getTime(),e>t?n.hint(l):void x.each(r,function(a,r){var o=x(r).attr("lay-ymd").split("-"),s=n.newDate({year:o[0],month:o[1]-1,date:o[2]}).getTime();x(r).removeClass(m+" "+i),s!==e&&s!==t||x(r).addClass(x(r).hasClass(y)||x(r).hasClass(p)?m:i),s>e&&s0&&n.calendar(),n.setValue(n.parse()).remove(),n.done(null,"change"),x(n.footer).find(g).removeClass(s)},clear:function(){n.setValue("").remove(),o&&(x.extend(r,n.firstDate),n.calendar()),a.range&&(delete n.startState,delete n.endState,delete n.endDate,delete n.startTime,delete n.endTime),n.done(["",{},{}])},now:function(){var e=new Date;x.extend(r,n.systemDate(),{hours:e.getHours(),minutes:e.getMinutes(),seconds:e.getSeconds()}),n.setValue(n.parse()).remove(),o&&n.calendar(),n.done()},confirm:function(){if(a.range){if(!n.endDate)return n.hint("请先选择日期范围");if(x(e).hasClass(s))return n.hint("time"===a.type?l.replace(/日期/g,"时间"):l)}else if(x(e).hasClass(s))return n.hint("不在有效日期或时间范围内");n.done(),n.setValue(n.parse()).remove()}};i[t]&&i[t]()},T.prototype.change=function(e){var t=this,n=t.config,a=n.dateTime,r=n.range&&("year"===n.type||"month"===n.type),o=t.elemCont[e||0],i=t.listYM[e],s=function(s,l){var d=["startDate","endDate"][e],c=x(o).find(".laydate-year-list")[0],u=x(o).find(".laydate-month-list")[0],l=void 0===l?1:l;return c&&(i[0]=s?i[0]-15:i[0]+15,t.list("year",e)),u&&(s?i[0]=i[0]-l:i[0]=i[0]+l,t.list("month",e)),(c||u)&&(x.extend(a,{year:i[0]}),r&&(t[d].year=i[0]),n.range||t.done(null,"change"),t.setBtnStatus(),n.range||t.limit(x(t.footer).find(g),{year:i[0]})),c||u};return{prevYear:function(){s("sub")||(a.year--,t.checkDate("limit").calendar(),n.range||t.done(null,"change"))},goToYear:function(e){var r=e-a.year;s("sub",r)||(a.year=e,t.checkDate("limit").calendar(),n.range||t.done(null,"change"))},prevMonth:function(){var e=t.getAsYM(a.year,a.month,"sub");x.extend(a,{year:e[0],month:e[1]}),t.checkDate("limit").calendar(),n.range||t.done(null,"change")},nextMonth:function(){var e=t.getAsYM(a.year,a.month);x.extend(a,{year:e[0],month:e[1]}),t.checkDate("limit").calendar(),n.range||t.done(null,"change")},goToMonth:function(e){x.extend(a,{month:e}),t.checkDate("limit").calendar(),n.range||t.done(null,"change")},nextYear:function(){s()||(a.year++,t.checkDate("limit").calendar(),n.range||t.done(null,"change"))}}},T.prototype.changeEvent=function(){var e=this;e.config;x(e.elem).on("click",function(e){x.stope(e)}),x.each(e.elemHeader,function(t,n){x(n[0]).on("click",function(n){e.change(t).prevYear()}),x(n[1]).on("click",function(n){e.change(t).prevMonth()}),x(n[2]).find("span").on("click",function(n){var a=x(this),r=a.attr("lay-ym"),o=a.attr("lay-type");r&&(r=r.split("-"),e.listYM[t]=[0|r[0],0|r[1]],e.list(o,t),x(e.footer).find(D).addClass(s))}),x(n[3]).on("click",function(n){e.change(t).nextMonth()}),x(n[4]).on("click",function(n){e.change(t).nextYear()})}),x.each(e.table,function(t,n){var a=x(n).find("td");a.on("click",function(){e.choose(x(this))})}),x(e.footer).find("span").on("click",function(){var t=x(this).attr("lay-type");e.tool(this,t)})},T.prototype.isInput=function(e){return/input|textarea/.test(e.tagName.toLocaleLowerCase())},T.prototype.events=function(){var e=this,t=e.config,n=function(n,a){n.on(t.trigger,function(){a&&(e.bindElem=this),e.render()})};t.elem[0]&&!t.elem[0].eventHandler&&(n(t.elem,"bind"),n(t.eventElem),x(document).on("click",function(n){n.target!==t.elem[0]&&n.target!==t.eventElem[0]&&n.target!==x(t.closeStop)[0]&&e.remove()}).on("keydown",function(t){13===t.keyCode&&x("#"+e.elemID)[0]&&e.elemID===T.thisElem&&(t.preventDefault(),x(e.footer).find(g)[0].click())}),t.range||"month"!=t.type&&"date"!=t.type||x(t.elem[0]).on("keyup",function(n){var a=t.dateTime,r=n.currentTarget.value;"cn"==t.lang?/^(\d{4})[\s\-\\]?([0-1][0-9])[\s\-\\]?([0-3][0-9])$/gi.test(r)?(x.extend(a,{year:parseInt(RegExp.$1),month:parseInt(RegExp.$2)-1,date:parseInt(RegExp.$3)}),e.setValue(e.parse(1,a)),e.checkDate("limit").calendar(),e.done(null,"change")):/^(\d{4})[\s\-\\]?([0-1][0-9])$/gi.test(r)?(x.extend(a,{year:parseInt(RegExp.$1),month:parseInt(RegExp.$2)-1}),"month"==t.type&&e.setValue(e.parse(1,a)),e.change(0).goToMonth(a.month)):/^(\d{4})$/gi.test(r)&&(x.extend(a,{year:parseInt(RegExp.$1)}),"year"==t.type&&e.setValue(e.parse(1,a)),e.change(0).goToYear(a.year)):"en"==t.lang&&(!/^([0-1][0-9])$/gi.test(r)||"month"!=t.type&&"date"!=t.type?/^([0-1][0-9])[\s\-\\]?([0-1][0-9])$/gi.test(r)&&"date"==t.type?(x.extend(a,{month:parseInt(RegExp.$1)-1,date:parseInt(RegExp.$2)}),e.checkDate("limit").calendar(),e.done(null,"change")):/^([0-1][0-9])[\s\-\\]?(\d{4})$/gi.test(r)&&"month"==t.type?(x.extend(a,{year:parseInt(RegExp.$2),month:parseInt(RegExp.$1)-1}),e.listYM[0]=[a.year,a.month],e.change(0).goToYear(a.year),e.setValue(e.parse(1,a))):/^([0-1][0-9])[\s\-\\]?([0-1][0-9])[\s\-\\]?(\d{4})$/gi.test(r)&&(x.extend(a,{year:parseInt(RegExp.$3),month:parseInt(RegExp.$1)-1,date:parseInt(RegExp.$2)}),e.listYM[0]=[a.year,a.month],e.change(0).goToYear(a.year),e.setValue(e.parse(1,a))):(x.extend(a,{month:parseInt(RegExp.$1)-1}),e.change(0).goToMonth(a.month)))}),x(window).on("resize",function(){return!(!e.elem||!x(o)[0])&&void e.position()}),t.elem[0].eventHandler=!0)},n.render=function(e){var t=new T(e);return a.call(t)},n.getEndDate=function(e,t){var n=new Date;return n.setFullYear(t||n.getFullYear(),e||n.getMonth()+1,1),new Date(n.getTime()-864e5).getDate()},window.lay=window.lay||x,e?(n.ready(),layui.define(function(e){n.path=layui.cache.dir,e(r,n)})):"function"==typeof define&&define.amd?define(function(){return n}):function(){n.ready(),window.laydate=n}()}(); \ No newline at end of file diff --git a/dist/theme/default/laydate.css b/dist/theme/default/laydate.css index c7e1508..0f1b5fc 100644 --- a/dist/theme/default/laydate.css +++ b/dist/theme/default/laydate.css @@ -1,2 +1,2 @@ /*! laydate-v5.0.9 日期与时间组件 MIT License http://www.layui.com/laydate/ By 贤心 */ -.laydate-set-ym,.layui-laydate,.layui-laydate *,.layui-laydate-list{box-sizing:border-box}html #layuicss-laydate{display:none;position:absolute;width:1989px}.layui-laydate *{margin:0;padding:0}.layui-laydate{position:absolute;z-index:66666666;margin:5px 0;border-radius:2px;font-size:14px;-webkit-animation-duration:.3s;animation-duration:.3s;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-name:laydate-upbit;animation-name:laydate-upbit}.layui-laydate-main{width:272px}.layui-laydate-content td,.layui-laydate-header *,.layui-laydate-list li{transition-duration:.3s;-webkit-transition-duration:.3s}@-webkit-keyframes laydate-upbit{from{-webkit-transform:translate3d(0,20px,0);opacity:.3}to{-webkit-transform:translate3d(0,0,0);opacity:1}}@keyframes laydate-upbit{from{transform:translate3d(0,20px,0);opacity:.3}to{transform:translate3d(0,0,0);opacity:1}}.layui-laydate-static{position:relative;z-index:0;display:inline-block;margin:0;-webkit-animation:none;animation:none}.laydate-ym-show .laydate-next-m,.laydate-ym-show .laydate-prev-m{display:none!important}.laydate-ym-show .laydate-next-y,.laydate-ym-show .laydate-prev-y{display:inline-block!important}.laydate-time-show .laydate-set-ym span[lay-type=month],.laydate-time-show .laydate-set-ym span[lay-type=year],.laydate-time-show .layui-laydate-header .layui-icon,.laydate-ym-show .laydate-set-ym span[lay-type=month]{display:none!important}.layui-laydate-header{position:relative;line-height:30px;padding:10px 70px 5px}.laydate-set-ym span,.layui-laydate-header i{padding:0 5px;cursor:pointer}.layui-laydate-header *{display:inline-block;vertical-align:bottom}.layui-laydate-header i{position:absolute;top:10px;color:#999;font-size:18px}.layui-laydate-header i.laydate-prev-y{left:15px}.layui-laydate-header i.laydate-prev-m{left:45px}.layui-laydate-header i.laydate-next-y{right:15px}.layui-laydate-header i.laydate-next-m{right:45px}.laydate-set-ym{width:100%;text-align:center;text-overflow:ellipsis;overflow:hidden;white-space:nowrap}.laydate-time-text{cursor:default!important}.layui-laydate-content{position:relative;padding:10px;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.layui-laydate-content table{border-collapse:collapse;border-spacing:0}.layui-laydate-content td,.layui-laydate-content th{width:36px;height:30px;padding:5px;text-align:center}.layui-laydate-content td{position:relative;cursor:pointer}.laydate-day-mark{position:absolute;left:0;top:0;width:100%;height:100%;line-height:30px;font-size:12px;overflow:hidden}.laydate-day-mark::after{position:absolute;content:'';right:2px;top:2px;width:5px;height:5px;border-radius:50%}.layui-laydate-footer{position:relative;height:46px;line-height:26px;padding:10px 20px}.layui-laydate-footer span{margin-right:15px;display:inline-block;cursor:pointer;font-size:12px}.layui-laydate-footer span:hover{color:#5FB878}.laydate-footer-btns{position:absolute;right:10px;top:10px}.laydate-footer-btns span{height:26px;line-height:26px;margin:0 0 0 -1px;padding:0 10px;border:1px solid #C9C9C9;background-color:#fff;white-space:nowrap;vertical-align:top;border-radius:2px}.layui-laydate-list>li,.layui-laydate-range .layui-laydate-main{display:inline-block;vertical-align:middle}.layui-laydate-list{position:absolute;left:0;top:0;width:100%;height:100%;padding:10px;background-color:#fff}.layui-laydate-list>li{position:relative;width:33.3%;height:36px;line-height:36px;margin:3px 0;text-align:center;cursor:pointer}.laydate-month-list>li{width:25%;margin:17px 0}.laydate-time-list>li{height:100%;margin:0;line-height:normal;cursor:default}.laydate-time-list p{position:relative;top:-4px;line-height:29px}.laydate-time-list ol{height:181px;overflow:hidden}.laydate-time-list>li:hover ol{overflow-y:auto}.laydate-time-list ol li{width:130%;padding-left:33px;line-height:30px;text-align:left;cursor:pointer}.layui-laydate-hint{position:absolute;top:115px;left:50%;width:250px;margin-left:-125px;line-height:20px;padding:15px;text-align:center;font-size:12px}.layui-laydate-range{width:546px}.layui-laydate-range .laydate-main-list-0 .laydate-next-m,.layui-laydate-range .laydate-main-list-0 .laydate-next-y,.layui-laydate-range .laydate-main-list-1 .laydate-prev-m,.layui-laydate-range .laydate-main-list-1 .laydate-prev-y{display:none}.layui-laydate-range .laydate-main-list-1 .layui-laydate-content{border-left:1px solid #e2e2e2}.layui-laydate,.layui-laydate-hint{border:1px solid #d2d2d2;box-shadow:0 2px 4px rgba(0,0,0,.12);background-color:#fff;color:#666}.layui-laydate-header{border-bottom:1px solid #e2e2e2}.layui-laydate-header i:hover,.layui-laydate-header span:hover{color:#5FB878}.layui-laydate-content{border-top:none 0;border-bottom:none 0}.layui-laydate-content th{font-weight:400;color:#333}.layui-laydate-content td{color:#666}.layui-laydate-content td.laydate-selected{background-color:#00F7DE}.laydate-selected:hover{background-color:#00F7DE!important}.layui-laydate-content td:hover,.layui-laydate-list li:hover{background-color:#eaeaea;color:#333}.laydate-time-list li ol{margin:0;padding:0;border:1px solid #e2e2e2;border-left-width:0}.laydate-time-list li:first-child ol{border-left-width:1px}.laydate-time-list>li:hover{background:0 0}.layui-laydate-content .laydate-day-next,.layui-laydate-content .laydate-day-prev{color:#d2d2d2}.laydate-selected.laydate-day-next,.laydate-selected.laydate-day-prev{background-color:#f8f8f8!important}.layui-laydate-footer{border-top:1px solid #e2e2e2}.layui-laydate-hint{color:#FF5722}.laydate-day-mark::after{background-color:#5FB878}.layui-laydate-content td.layui-this .laydate-day-mark::after{display:none}.layui-laydate-footer span[lay-type=date]{color:#5FB878}.layui-laydate .layui-this{background-color:#009688!important;color:#fff!important}.layui-laydate .laydate-disabled,.layui-laydate .laydate-disabled:hover{background:0 0!important;color:#d2d2d2!important;cursor:not-allowed!important;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.laydate-theme-molv{border:none}.laydate-theme-molv.layui-laydate-range{width:548px}.laydate-theme-molv .layui-laydate-main{width:274px}.laydate-theme-molv .layui-laydate-header{border:none;background-color:#009688}.laydate-theme-molv .layui-laydate-header i,.laydate-theme-molv .layui-laydate-header span{color:#f6f6f6}.laydate-theme-molv .layui-laydate-header i:hover,.laydate-theme-molv .layui-laydate-header span:hover{color:#fff}.laydate-theme-molv .layui-laydate-content{border:1px solid #e2e2e2;border-top:none;border-bottom:none}.laydate-theme-molv .laydate-main-list-1 .layui-laydate-content{border-left:none}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li,.laydate-theme-grid .layui-laydate-content td,.laydate-theme-grid .layui-laydate-content thead,.laydate-theme-molv .layui-laydate-footer{border:1px solid #e2e2e2}.laydate-theme-grid .laydate-selected,.laydate-theme-grid .laydate-selected:hover{background-color:#f2f2f2!important;color:#009688!important}.laydate-theme-grid .laydate-selected.laydate-day-next,.laydate-theme-grid .laydate-selected.laydate-day-prev{color:#d2d2d2!important}.laydate-theme-grid .laydate-month-list,.laydate-theme-grid .laydate-year-list{margin:1px 0 0 1px}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li{margin:0 -1px -1px 0}.laydate-theme-grid .laydate-year-list>li{height:43px;line-height:43px}.laydate-theme-grid .laydate-month-list>li{height:71px;line-height:71px}@font-face{font-family:laydate-icon;src:url(font/iconfont.eot);src:url(font/iconfont.eot#iefix) format('embedded-opentype'),url(font/iconfont.svg#iconfont) format('svg'),url(font/iconfont.woff) format('woff'),url(font/iconfont.ttf) format('truetype')}.laydate-icon{font-family:laydate-icon!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale} \ No newline at end of file +.laydate-set-ym,.layui-laydate,.layui-laydate *,.layui-laydate-list{box-sizing:border-box}@font-face{font-family:laydate-icon;src:url(font/iconfont.eot);src:url(font/iconfont.eot#iefix) format('embedded-opentype'),url(font/iconfont.svg#iconfont) format('svg'),url(font/iconfont.woff) format('woff'),url(font/iconfont.ttf) format('truetype')}.laydate-icon{font-family:laydate-icon!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}html #layuicss-laydate{display:none;position:absolute;width:1989px}.layui-laydate *{margin:0;padding:0}.layui-laydate{position:absolute;z-index:66666666;margin:5px 0;border-radius:2px;font-size:14px;-webkit-animation-duration:.3s;animation-duration:.3s;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-name:laydate-upbit;animation-name:laydate-upbit}.layui-laydate-main{width:272px}.layui-laydate-content td,.layui-laydate-header *,.layui-laydate-list li{transition-duration:.3s;-webkit-transition-duration:.3s}@-webkit-keyframes laydate-upbit{from{-webkit-transform:translate3d(0,20px,0);opacity:.3}to{-webkit-transform:translate3d(0,0,0);opacity:1}}@keyframes laydate-upbit{from{transform:translate3d(0,20px,0);opacity:.3}to{transform:translate3d(0,0,0);opacity:1}}.layui-laydate-static{position:relative;z-index:0;display:inline-block;margin:0;-webkit-animation:none;animation:none}.laydate-ym-show .laydate-next-m,.laydate-ym-show .laydate-prev-m{display:none!important}.laydate-ym-show .laydate-next-y,.laydate-ym-show .laydate-prev-y{display:inline-block!important}.laydate-time-show .laydate-set-ym span[lay-type=month],.laydate-time-show .laydate-set-ym span[lay-type=year],.laydate-time-show .layui-laydate-header .layui-icon,.laydate-ym-show .laydate-set-ym span[lay-type=month]{display:none!important}.layui-laydate-header{position:relative;line-height:30px;padding:10px 70px 5px}.laydate-set-ym span,.layui-laydate-header i{padding:0 5px;cursor:pointer}.layui-laydate-header *{display:inline-block;vertical-align:bottom}.layui-laydate-header i{position:absolute;top:10px;color:#999;font-size:18px}.layui-laydate-header i.laydate-prev-y{left:15px}.layui-laydate-header i.laydate-prev-m{left:45px}.layui-laydate-header i.laydate-next-y{right:15px}.layui-laydate-header i.laydate-next-m{right:45px}.laydate-set-ym{width:100%;text-align:center;text-overflow:ellipsis;overflow:hidden;white-space:nowrap}.laydate-time-text{cursor:default!important}.layui-laydate-content{position:relative;padding:10px;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.layui-laydate-content table{border-collapse:collapse;border-spacing:0}.layui-laydate-content td,.layui-laydate-content th{width:36px;height:30px;padding:5px;text-align:center}.layui-laydate-content td{position:relative;cursor:pointer}.laydate-day-mark{position:absolute;left:0;top:0;width:100%;height:100%;line-height:30px;font-size:12px;overflow:hidden}.laydate-day-mark::after{position:absolute;content:'';right:2px;top:2px;width:5px;height:5px;border-radius:50%}.layui-laydate-footer{position:relative;height:46px;line-height:26px;padding:10px 20px}.layui-laydate-footer span{margin-right:15px;display:inline-block;cursor:pointer;font-size:12px}.layui-laydate-footer span:hover{color:#5FB878}.laydate-footer-btns{position:absolute;right:10px;top:10px}.laydate-footer-btns span{height:26px;line-height:26px;margin:0 0 0 -1px;padding:0 10px;border:1px solid #C9C9C9;background-color:#fff;white-space:nowrap;vertical-align:top;border-radius:2px}.layui-laydate-list>li,.layui-laydate-range .layui-laydate-main{display:inline-block;vertical-align:middle}.layui-laydate-list{position:absolute;left:0;top:0;width:100%;height:100%;padding:10px;background-color:#fff}.layui-laydate-list>li{position:relative;width:33.3%;height:36px;line-height:36px;margin:3px 0;text-align:center;cursor:pointer}.laydate-month-list>li{width:25%;margin:17px 0}.laydate-time-list>li{height:100%;margin:0;line-height:normal;cursor:default}.laydate-time-list p{position:relative;top:-4px;line-height:29px}.laydate-time-list ol{height:181px;overflow:hidden}.laydate-time-list>li:hover ol{overflow-y:auto}.laydate-time-list ol li{width:130%;padding-left:33px;line-height:30px;text-align:left;cursor:pointer}.layui-laydate-hint{position:absolute;top:115px;left:50%;width:250px;margin-left:-125px;line-height:20px;padding:15px;text-align:center;font-size:12px}.layui-laydate-range{width:546px}.layui-laydate-range .laydate-main-list-0 .laydate-next-m,.layui-laydate-range .laydate-main-list-0 .laydate-next-y,.layui-laydate-range .laydate-main-list-1 .laydate-prev-m,.layui-laydate-range .laydate-main-list-1 .laydate-prev-y{display:none}.layui-laydate-range .laydate-main-list-1 .layui-laydate-content{border-left:1px solid #e2e2e2}.layui-laydate,.layui-laydate-hint{border:1px solid #d2d2d2;box-shadow:0 2px 4px rgba(0,0,0,.12);background-color:#fff;color:#666}.layui-laydate-header{border-bottom:1px solid #e2e2e2}.layui-laydate-header i:hover,.layui-laydate-header span:hover{color:#5FB878}.layui-laydate-content{border-top:none 0;border-bottom:none 0}.layui-laydate-content th{font-weight:400;color:#333}.layui-laydate-content td{color:#666}.layui-laydate-content td.laydate-selected{background-color:#00F7DE}.laydate-selected:hover{background-color:#00F7DE!important}.layui-laydate-content td:hover,.layui-laydate-list li:hover{background-color:#eaeaea;color:#333}.laydate-time-list li ol{margin:0;padding:0;border:1px solid #e2e2e2;border-left-width:0}.laydate-time-list li:first-child ol{border-left-width:1px}.laydate-time-list>li:hover{background:0 0}.layui-laydate-content .laydate-day-next,.layui-laydate-content .laydate-day-prev{color:#d2d2d2}.laydate-selected.laydate-day-next,.laydate-selected.laydate-day-prev{background-color:#f8f8f8!important}.layui-laydate-footer{border-top:1px solid #e2e2e2}.layui-laydate-hint{color:#FF5722}.laydate-day-mark::after{background-color:#5FB878}.layui-laydate-content td.layui-this .laydate-day-mark::after{display:none}.layui-laydate-footer span[lay-type=date]{color:#5FB878}.layui-laydate .layui-this{background-color:#009688!important;color:#fff!important}.layui-laydate .laydate-disabled,.layui-laydate .laydate-disabled:hover{background:0 0!important;color:#d2d2d2!important;cursor:not-allowed!important;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.laydate-theme-molv{border:none}.laydate-theme-molv.layui-laydate-range{width:548px}.laydate-theme-molv .layui-laydate-main{width:274px}.laydate-theme-molv .layui-laydate-header{border:none;background-color:#009688}.laydate-theme-molv .layui-laydate-header i,.laydate-theme-molv .layui-laydate-header span{color:#f6f6f6}.laydate-theme-molv .layui-laydate-header i:hover,.laydate-theme-molv .layui-laydate-header span:hover{color:#fff}.laydate-theme-molv .layui-laydate-content{border:1px solid #e2e2e2;border-top:none;border-bottom:none}.laydate-theme-molv .laydate-main-list-1 .layui-laydate-content{border-left:none}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li,.laydate-theme-grid .layui-laydate-content td,.laydate-theme-grid .layui-laydate-content thead,.laydate-theme-molv .layui-laydate-footer{border:1px solid #e2e2e2}.laydate-theme-grid .laydate-selected,.laydate-theme-grid .laydate-selected:hover{background-color:#f2f2f2!important;color:#009688!important}.laydate-theme-grid .laydate-selected.laydate-day-next,.laydate-theme-grid .laydate-selected.laydate-day-prev{color:#d2d2d2!important}.laydate-theme-grid .laydate-month-list,.laydate-theme-grid .laydate-year-list{margin:1px 0 0 1px}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li{margin:0 -1px -1px 0}.laydate-theme-grid .laydate-year-list>li{height:43px;line-height:43px}.laydate-theme-grid .laydate-month-list>li{height:71px;line-height:71px} \ No newline at end of file diff --git a/src/laydate.js b/src/laydate.js index 0a75401..3aa4b41 100644 --- a/src/laydate.js +++ b/src/laydate.js @@ -675,7 +675,7 @@ //生成底部栏 lay(divFooter).html(function(){ - var html = [], btns = []; + var html = [], btns = [], shortcuts = []; if(options.type === 'datetime'){ html.push(''+ lang.timeTips +''); } @@ -683,9 +683,22 @@ var title = lang.tools[item] || 'btn'; if(options.range && item === 'now') return; if(isStatic && item === 'clear') title = options.lang === 'cn' ? '重置' : 'Reset'; - btns.push(''+ title +''); + btns.push('' + title + ''); }); - html.push(''); + + if (options.range) { + if (that.config.type == 'date') { + shortcuts.push('' + (options.lang == 'cn' ? '最近30天' : '30days') + ''); + shortcuts.push('' + (options.lang == 'cn' ? '上月' : '-1month') + ''); + shortcuts.push('' + (options.lang == 'cn' ? '本月' : 'month') + ''); + } + shortcuts.push('' + (options.lang == 'cn' ? '上季度' : '-1quarter') + ''); + shortcuts.push('' + (options.lang == 'cn' ? '本季度' : 'quarter') + ''); + shortcuts.push('' + (options.lang == 'cn' ? '上年' : '-1year') + ''); + shortcuts.push('' + (options.lang == 'cn' ? '今年' : 'year') + ''); + } + + html.push(''); return html.join(''); }()); @@ -1231,6 +1244,11 @@ dateTime[type] = ym; if(isAlone) that.startDate[type] = ym; that.limit(lay(that.footer).find(ELEM_CONFIRM), null, 0); + + // 如果是年或者月模式,选中日期就关闭弹框 + if ((type == "month" && that.config.type == "month") || (type == "year" && that.config.type == "year")) { + that.setValue(that.parse()).remove().done(); + } } else { //范围选择 if(isAlone){ //非date/datetime类型 that.endDate[type] = ym; @@ -1590,8 +1608,108 @@ that.closeList(); lay(btn).attr('lay-type', 'datetime').html(that.lang().timeTips); } - - //清空、重置 + + // 快速选择日期 + , shortcut: function () { + var $btn = btn; + var type = $btn.getAttribute("data-type"); + var count = $btn.getAttribute("data-count"); + var currentDate = new Date(); + var addDays = function (curDate, d) { + curDate.setDate(curDate.getDate() + d); + }; + var addMonths = function (curDate, m) { + var d = curDate.getDate(); + curDate.setMonth(curDate.getMonth() + m); + if (curDate.getDate() < d) + curDate.setDate(0); + }; + var addYears = function (curDate, y) { + var m = curDate.getMonth(); + curDate.setFullYear(curDate.getFullYear() + y); + if (m < curDate.getMonth()) { + curDate.setDate(0); + } + }; + + // 默认 + that.endDate = { + year: currentDate.getFullYear(), + month: currentDate.getMonth(), + date: currentDate.getDate(), + hours: currentDate.getHours(), + minutes: currentDate.getMinutes(), + seconds: currentDate.getSeconds() + }; + + if (type == "day") { + addDays(currentDate, -count); + } else if (type == "month") { + if (count == 0) { + currentDate.setDate(1); + } else { + addMonths(currentDate, -1); + that.endDate.date = new Date((new Date().setDate(0))).getDate(); + that.endDate.month = currentDate.getMonth(); + currentDate.setDate(1); + } + } else if (type == "quarter") { + if (count == 0) { + addMonths(currentDate, -(2 - (that.endDate.month + 1) % 3)); + } else { + that.endDate.month = that.endDate.month - (3 - (that.endDate.month + 1) % 3); + that.endDate.month = that.endDate.month < 0 ? 12 + that.endDate.month : that.endDate.month; + currentDate.setMonth(that.endDate.month - 2); + that.endDate.date = new Date(that.endDate.year, that.endDate.month + 1, "0").getDate(); + } + } else if (type == "year") { + if (count == 0) { + currentDate.setMonth(0); + currentDate.setDate(1); + } else { + addYears(currentDate, -1); + that.endDate.year = currentDate.getFullYear(); + that.endDate.month = 11; + that.endDate.date = 31; + currentDate.setMonth(0); + } + } + + that.config.dateTime = { + year: currentDate.getFullYear(), + month: currentDate.getMonth(), + date: currentDate.getDate(), + hours: currentDate.getHours(), + minutes: currentDate.getMinutes(), + seconds: currentDate.getSeconds() + }; + that.startDate = { + year: currentDate.getFullYear(), + month: currentDate.getMonth(), + date: currentDate.getDate(), + hours: currentDate.getHours(), + minutes: currentDate.getMinutes(), + seconds: currentDate.getSeconds() + }; + that.startYMD = { + year: currentDate.getFullYear(), + month: currentDate.getMonth(), + date: currentDate.getDate() + }; + + that.stampRange(); + that.startState = true; + that.endState = true; + if (lay('.layui-laydate').length > 0) { + that.calendar(); + } + that.setValue(that.parse()).remove(); + that.done(null, 'change'); + + lay(that.footer).find(ELEM_CONFIRM).removeClass(DISABLED); + } + + //清空、重置 ,clear: function(){ that.setValue('').remove(); isStatic && ( @@ -1647,10 +1765,11 @@ ,elemCont = that.elemCont[index || 0] ,listYM = that.listYM[index] - ,addSubYeay = function(type){ + ,addSubYeay = function(type, number){ var startEnd = ['startDate', 'endDate'][index] ,isYear = lay(elemCont).find('.laydate-year-list')[0] - ,isMonth = lay(elemCont).find('.laydate-month-list')[0]; + ,isMonth = lay(elemCont).find('.laydate-month-list')[0] + ,number = number === undefined ? 1 : number; //切换年列表 if(isYear){ @@ -1659,7 +1778,7 @@ } if(isMonth){ //切换月面板中的年 - type ? listYM[0]-- : listYM[0]++; + type ? listYM[0] = listYM[0] - number : listYM[0] = listYM[0] + number; that.list('month', index); } @@ -1684,6 +1803,13 @@ that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } + ,goToYear: function (year) { + var diffYear = year - dateTime.year; + if (addSubYeay('sub', diffYear)) return; + dateTime.year = year; + that.checkDate('limit').calendar(); + options.range || that.done(null, 'change'); + } ,prevMonth: function(){ var YM = that.getAsYM(dateTime.year, dateTime.month, 'sub'); lay.extend(dateTime, { @@ -1702,6 +1828,13 @@ that.checkDate('limit').calendar(); options.range || that.done(null, 'change'); } + ,goToMonth: function (month) { + lay.extend(dateTime, { + month: month + }); + that.checkDate('limit').calendar(); + options.range || that.done(null, 'change'); + } ,nextYear: function(){ if(addSubYeay()) return; dateTime.year++ @@ -1813,8 +1946,79 @@ } } }); - - //自适应定位 + + // 手动输入日期,日历同步跳转 + if (!options.range && (options.type == "month" || options.type == "date")) { + lay(options.elem[0]).on('keyup', function (e) { + var dateTime = options.dateTime; + var value = e.currentTarget.value; + + if (options.lang == "cn") { + if (/^(\d{4})[\s\-\\]?([0-1][0-9])[\s\-\\]?([0-3][0-9])$/ig.test(value)) { + lay.extend(dateTime, { + year: parseInt(RegExp.$1), + month: parseInt(RegExp.$2) - 1, + date: parseInt(RegExp.$3) + }); + that.setValue(that.parse(1, dateTime)); + that.checkDate('limit').calendar(); + that.done(null, 'change'); + } else if (/^(\d{4})[\s\-\\]?([0-1][0-9])$/ig.test(value)) { + lay.extend(dateTime, { + year: parseInt(RegExp.$1), + month: parseInt(RegExp.$2) - 1 + }); + if (options.type == "month") { + that.setValue(that.parse(1, dateTime)); + } + that.change(0).goToMonth(dateTime.month); + } else if (/^(\d{4})$/ig.test(value)) { + lay.extend(dateTime, { + year: parseInt(RegExp.$1) + }); + if (options.type == "year") { + that.setValue(that.parse(1, dateTime)); + } + that.change(0).goToYear(dateTime.year); + } + + } else if (options.lang == "en") { + if (/^([0-1][0-9])$/ig.test(value) && (options.type == "month" || options.type == "date" )) { + lay.extend(dateTime, { + month: parseInt(RegExp.$1) - 1 + }); + that.change(0).goToMonth(dateTime.month); + } else if (/^([0-1][0-9])[\s\-\\]?([0-1][0-9])$/ig.test(value) && options.type == "date") { + lay.extend(dateTime, { + month: parseInt(RegExp.$1) - 1, + date: parseInt(RegExp.$2) + }); + that.checkDate('limit').calendar(); + that.done(null, 'change'); + } else if (/^([0-1][0-9])[\s\-\\]?(\d{4})$/ig.test(value) && options.type == "month") { + lay.extend(dateTime, { + year: parseInt(RegExp.$2), + month: parseInt(RegExp.$1) - 1 + }); + that.listYM[0] = [dateTime.year, dateTime.month]; + that.change(0).goToYear(dateTime.year); + that.setValue(that.parse(1, dateTime)); + } else if (/^([0-1][0-9])[\s\-\\]?([0-1][0-9])[\s\-\\]?(\d{4})$/ig.test(value)) { + lay.extend(dateTime, { + year: parseInt(RegExp.$3), + month: parseInt(RegExp.$1) - 1, + date: parseInt(RegExp.$2) + }); + that.listYM[0] = [dateTime.year, dateTime.month]; + that.change(0).goToYear(dateTime.year); + that.setValue(that.parse(1, dateTime)); + } + } + + }); + } + + //自适应定位 lay(window).on('resize', function(){ if(!that.elem || !lay(ELEM)[0]){ return false;