forked from mrlan/LRR
1 line
14 KiB
JavaScript
Executable File
1 line
14 KiB
JavaScript
Executable File
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(window.jQuery)}(function(e){function a(a,t){var n,s,d,r={},l=e.fn.datetimepicker.CONSTS,o=l.NAV,i=l.I18N[t.language]?l.I18N[t.language]:l.I18N.en,c={showYear:null,showMonth:null},u=function(e){return new Date(e.getTime())},p=t.date instanceof Date?u(t.date):new Date,v=t.date instanceof Date?u(t.date):null,h=t.firstDayOfWeek,m=e(a),D=function(e,a){var t=e.getFullYear();return null==a&&(a=e.getMonth()),0!=t%4||0==t%100&&0!=t%400||1!==a?[31,28,31,30,31,30,31,31,30,31,30,31][a]:29},M=function(e){return""===e||null==e},f=function(a,t,n,s){return e.isFunction(t)?t.apply(a,n||[]):s},g=function(e,a,t){var n=e+"";for(t||(t=" ");n.length<a;)n=t+n;return n.toString()},b=function(e,a){var t=e.str,n=e.len;switch(e.char){case"E":t=l.DN[a.getDay()];break;case"y":t=n<=3?(a.getFullYear()+"").slice(2,4):a.getFullYear();break;case"M":t=n>2?l.MN[a.getMonth()]:n<2?a.getMonth()+1:g(a.getMonth()+1,2,"0");break;case"d":t=n>1?g(a.getDate(),2,"0"):a.getDate();break;case"h":var s=a.getHours()%12;0===s&&(s=12),t=n>1?g(s,2,"0"):s;break;case"H":t=n>1?g(a.getHours(),2,"0"):a.getHours();break;case"m":t=n>1?g(a.getMinutes(),2,"0"):a.getMinutes();break;case"s":t=n>1?g(a.getSeconds(),2,"0"):a.getSeconds();break;case"a":t=a.getHours()<12?"am":"pm";break;default:t=e.str}return t},y=function(a,t,n,s,d){var r=e("<td/>").attr("colspan",n).html(t).appendTo(a);return s&&r.data("nav",s),r.addClass(d),r},Y=function(){var e=t.startDate,a=c.showMonth,n=c.showYear;e?n>e.getFullYear()?a>0?k(a-1):(p.setFullYear(n-1),k(11)):n==e.getFullYear()&&a>e.getMonth()&&a>0&&(k(a-1),p<e&&(p=u(e))):a>0?k(a-1):(p.setFullYear(n-1),k(11))},C=function(){var e=t.endDate,a=c.showMonth,n=c.showYear;e?n<e.getFullYear()?a<11?k(a+1):(p.setFullYear(n+1),k(0)):n==e.getFullYear()&&a<e.getMonth()&&(k(a+1),p>e&&(p=u(e))):a<11?k(a+1):(p.setFullYear(n+1),k(0))},k=function(e){var a=p.getDate(),n=t.endDate,s=t.startDate,d=D(p,e);a>d&&p.setDate(d),p.setMonth(e),n&&p>n&&p.setDate(n.getDate()),s&&p<s&&p.setDate(s.getDate())},w=function(e,a){if(a instanceof Date){var n=(a=u(a)).getFullYear(),s=a.getMonth(),d=a.getDate(),r=new Date,p=r.getFullYear(),m=r.getMonth(),M=r.getDate();c.showYear=n,c.showMonth=s;var f=t.startDate,g=t.endDate;e.$title.text(i.MN[s]+", "+n);var b=u(a);b.setDate(D(b,null)+1),g&&b>g||b.getFullYear()>l.MAXYEAR?e.$nextm.addClass("disabled").removeClass("hover").data("disabled",!0):e.$nextm.removeClass("disabled").data("disabled",!1);var y=u(a);y.setDate(0),f&&y<f||y.getFullYear()<l.MINYEAR?e.$prevm.addClass("disabled").removeClass("hover").data("disabled",!0):e.$prevm.removeClass("disabled").data("disabled",!1),a.setDate(1);var Y=(a.getDay()-h)%7;a.setDate(0-Y),a.setDate(a.getDate()+1);for(var C=e.find("tbody").children().eq(0),k=0;k<6&&C.length;k++){for(var w,T=C.children(),E=0;E<7;++E,a.setDate(w+1)){var A=T.eq(E);if(A.removeClass().data("nav",o.day),!A.length)break;w=a.getDate(),A.text(w);var N=!1;if(a.getMonth()==s?null!=f&&f>a||null!=g&&g<a?(A.addClass("day disabled"),N=!0):A.addClass("day"):A.addClass("oday"),A.data("disabled",N),!N&&v){v.getMonth()==s&&w==d&&(c.selectedDate&&c.selectedDate.removeClass("selected"),A.addClass("selected"),c.selectedDate=A,c.showDay=w),a.getFullYear()==p&&a.getMonth()==m&&w==M&&A.addClass("today");var x=a.getDay();0!==x&&6!==x||A.addClass("weekend")}}C=C.next()}}},T=function(a,n){if(n){var s=n.getFullYear(),d=n.getMonth(),r=e(a).data("midYear");r?s>r+5?r+=10:s<r-4&&(r-=10):r=s,e(a).data("midYear",r);var u,p,v,h,m=[r-4,r-3,r-2,r-1,r,r+1,r+2,r+3,r+4,r+5],D=e("td.year",a),f=e("td.month",a),g=t.endDate,b=t.startDate;g&&g&&s==(u=g.getFullYear())&&(p=g.getMonth()),(!u||u>l.MAXYEAR)&&(u=l.MAXYEAR),b&&b&&s==(v=b.getFullYear())&&(h=b.getMonth()),(!v||v<l.MINYEAR)&&(v=l.MINYEAR);for(var y=0;y<12;y++){var Y=f.eq(y).text(i.MN[y]).data("nav",o.month).data("month",y);if(y==d&&(c.selectedMonth&&c.selectedMonth.removeClass("selected"),Y.addClass("selected"),c.selectedMonth=Y),!M(h)&&y<h||!M(p)&&y>p?Y.addClass("disabled").data("disabled",!0):Y.removeClass("disabled").data("disabled",!1),y<10){var C=D.eq(y).text(m[y]).data("nav",o.year);m[y]==s&&(c.selectedYear&&c.selectedYear.removeClass("selected"),C.addClass("selected"),c.selectedYear=C),!M(v)&&m[y]<v||!M(u)&&m[y]>u?C.addClass("disabled").data("disabled",!0):C.removeClass("disabled").data("disabled",!1)}}var k=e("td.prevy",a).removeClass("disabled").data("disabled",!1);m[0]<=v&&k.addClass("disabled").data("disabled",!0).removeClass("hover");var w=e("td.nexty",a).removeClass("disabled").data("disabled",!1);m[9]>=u&&w.addClass("disabled").data("disabled",!0).removeClass("hover")}},E=function(e,a,t){if(!(a instanceof Date))return e.$h.val(""),e.$m.val(""),void e.$s.val("");t!=l.VIEWMODE.HM&&t!=l.VIEWMODE.YMDHM||a.setSeconds(0);var n=a.getHours()+"",s=a.getMinutes()+"",d=a.getSeconds()+"";e.$h.val(g(n,2,"0")),e.$m.val(g(s,2,"0")),e.$s.val(g(d,2,"0"))},A=function(e,a,t){return isNaN(e)?a:Math.min(t,Math.max(a,e))},N=function(e){v=e instanceof Date?u(e):null,f(r,t.onDateChange)},x=e("<form novalidate/>").appendTo(m).addClass(t.baseCls);n=function(){var a=e('<table cellspacing = "2px" cellpadding = "0" class="dt"/>'),t=e("<thead/>").appendTo(a);$row=e('<tr class = "mainhead"/>'),a.$prevm=y($row,'<i class="icon-datepicker-prev"/>',1,o.prevm,"prevm"),a.$title=e('<td class="title" colspan="5"/>').data("nav",o.title).appendTo($row),a.$nextm=y($row,'<i class="icon-datepicker-next"/>',1,o.nextm,"nextm"),$row.appendTo(t),$row=e("<tr/>");var n;for(n=0;n<7;++n){var s=e("<td/>").appendTo($row),d=(n+h)%7;s.addClass("day name").text(i.SDN[d]),0!==d&&6!==d||s.addClass("weekend")}$row.appendTo(t);var r=e('<tbody onselectstart="return false;"/>').appendTo(a);for(n=6;n>0;n--)for(var l=e("<tr/>").appendTo(r),c=0;c<7;c++)e("<td/>").appendTo(l);return a}(),w(n,p),s=function(){for(var a=e('<table cellspacing = "2px" cellpadding = "0" class="mt"/>'),t=e("<tbody/>").appendTo(a),n=e("<tr/>").appendTo(t),s=0;s<2;s++)e('<td class="month"/>').appendTo(n);y(n,'<i class="icon-datepicker-prev"/>',1,o.prevy," prevy"),y(n,'<i class="icon-datepicker-next"/>',1,o.nexty," nexty");for(var d=0;d<5;d++)n=e("<tr/>").appendTo(t),e('<td class="month"/><td class="month"/><td class="year"/><td class="year"/>').appendTo(n);var r=e('<tfoot class="buttonpane"/>').appendTo(a);return n=e("<tr/>").appendTo(r),y(n,i.OK,4,o.mok,"ok"),a}(),d=function(a){var t=e('<table cellspacing = "0" cellpadding = "0" class="tt"/>'),n=e("<tbody>").appendTo(t);t.$h=e('<input type="number" min="0" max="23" maxlength="2"/>').data("time","h").change(function(){var e=parseInt(this.value,10),a=A(e,0,23);e!=a&&(this.value=a),p.setHours(a),N(p),E(d,p)}).focus(function(){t.focus=e(this)}),t.$m=e('<input type="number" min="0" max="59" maxlength="2"/>').data("time","m").change(function(){var e=parseInt(this.value,10),a=A(e,0,59);e!=a&&(this.value=a),p.setMinutes(a),N(p),E(d,p)}).focus(function(){t.focus=e(this)}),t.$s=e('<input type="number" min="0" max="59" maxlength="2"/>').data("time","s").change(function(){var e=parseInt(this.value,10),a=A(e,0,59);e!=a&&(this.value=a),p.setSeconds(a),N(p),E(d,p)}).focus(function(){t.focus=e(this)}),t.focus=t.$m;var s=e("<td/>").append(e('<i class="icon-datepicker-plus"/>')).data("nav",o.plus),r=e("<td/>").append(e('<i class="icon-datepicker-minus"/>')).data("nav",o.minus),c=e("<tr/>").append(e('<td rowspan="2"/>').text(i.TIME)).append(e('<td rowspan="2"/>').append(t.$h)).append(e('<td class="common" rowspan="2"/>').text(":")).append(e('<td rowspan="2"/>').append(t.$m));return a!=l.VIEWMODE.YMDHM&&a!=l.VIEWMODE.HM&&c.append(e('<td class="common" rowspan="2"/>').text(":")).append(e('<td rowspan="2"/>').append(t.$s)),c.append(s).appendTo(n),e("<tr/>").append(r).appendTo(n),t}(t.viewMode);var $=function(){var a=e('<table class="buttonpane"/>'),t=e("<tr/>");return y(t,i.CLEAR,null,o.clear,"clear"),y(t,i.TODAY,null,o.today,"today"),y(t,i.OK,null,o.dok,"ok"),t.appendTo(a),a}(),F=l.VIEWMODE;switch(t.viewMode){case F.YM:T(s,p),x.append(s.show());break;case F.HM:case F.HMS:E(d,p,t.viewMode),x.append(d.show()),function(a){var t=e("<table/>"),n=e("<tr/>").appendTo(t);y(n,i.CLEAR,1,o.clear,"clear"),y(n,i.CURRENT,1,o.current,"current"),y(n,i.OK,1,o.dok,"ok"),t.appendTo(a)}(x);break;case F.YMD:x.append(n.show()),s.hide().appendTo(x),x.append($);break;case F.YMDHMS:case F.YMDHM:default:n.appendTo(x).show(),s.hide().appendTo(x),E(d,p,t.viewMode),d.show().appendTo(x),x.append($)}return function(){var a=function(a){var i=a.target,u=e(i).closest("td"),h=a.type,m=u.data("nav"),D=arguments;if(!u.data("disabled")&&0!==u.length&&m)if(p instanceof Date||(p=new Date),"mouseover"===h)u.addClass("hover");else if("mouseup"===h)switch(u.removeClass("hover"),m){case o.prevm:Y(),w(n,p),f(r,t.onDisplayUpdate,D);break;case o.nextm:C(),w(n,p),f(r,t.onDisplayUpdate,D);break;case o.title:T(s,new Date(c.showYear,c.showMonth));var M=s.parent(".perfect-datetimepicker");s.css({position:"absolute",top:0,left:0,height:M.height(),width:M.width(),"z-index":1e5}).show("fast");break;case o.clear:p=null,c.selectedDate&&c.selectedDate.removeClass("selected"),N(p),E(d,null),f(r,t.onDisplayUpdate,D),f(r,t.onClear,D);break;case o.current:p=new Date,v=p,N(p),f(r,t.onDisplayUpdate,D),f(r,t.onClear,D);case o.today:var b=new Date;if(t.startDate&&b<t.startDate||t.endDate&&b>t.endDate)return;w(n,p=b),E(d,p),c.selectedDate&&c.selectedDate.removeClass("selected"),c.selectedDate=n.find("td.today").addClass("selected"),N(p),f(r,t.onDisplayUpdate,D),f(r,t.onToday,D);break;case o.dok:f(r,t.onOk,D);break;case o.prevy:!function(){var e,a,n=t.startDate,s=p.getFullYear()-10,d=p.getMonth();n&&s==(a=n.getFullYear())&&(e=n.getMonth()),(!a||a<l.MINYEAR)&&(a=l.MINYEAR),s<a?(p.setFullYear(a),d<e&&p.setMonth(e)):p.setFullYear(s)}(),T(s,p),f(r,t.onDisplayUpdate,D);break;case o.nexty:!function(){var e,a,n=t.endDate,s=p.getFullYear()+10,d=p.getMonth();n&&s==(a=n.getFullYear())&&(e=n.getMonth()),(!a||a>l.MAXYEAR)&&(a=l.MAXYEAR),s>a?(p.setFullYear(a),d<e&&p.setMonth(e)):p.setFullYear(s)}(),T(s,p),f(r,t.onDisplayUpdate,D);break;case o.mok:w(n,p),f(r,t.onDisplayUpdate,D),n.parent().length>0&&s.hide("fast");break;case o.cancel:w(n,p),s.hide("fast");break;case o.year:c.selectedYear&&c.selectedYear.removeClass("selected"),c.selectedYear=u,p.setFullYear(u.text()),N(p),T(s,p),f(r,t.onDisplayUpdate,D);break;case o.month:c.selectedMonth&&c.selectedMonth.removeClass("selected"),c.selectedMonth=u.addClass("selected"),p.setMonth(u.data("month")),N(p),f(r,t.onDisplayUpdate,D);break;case o.day:var y=parseInt(u.text(),10);u.hasClass("oday")&&(y<15?(C(),p.setDate(y),w(n,p),f(r,t.onDisplayUpdate,D)):(Y(),p.setDate(y),w(n,p),f(r,t.onDisplayUpdate,D)),u=u.closest("table").find("td.day").filter(function(){return e(this).text()==y})),c.selectedDate&&c.selectedDate.removeClass("selected"),c.selectedDate=u.addClass("selected"),p.setFullYear(c.showYear),p.setMonth(c.showMonth),p.setDate(y),N(p),d.parent().length||f(r,t.onClose,D);break;case o.plus:!function(e,a){var t=a.data("time");if("h"===t){var n=(p.getHours()+1)%24;p.setHours(n),e.$h.val(g(n,2,"0"))}else if("m"===t){var s=(p.getMinutes()+5)%60;p.setMinutes(s),e.$m.val(g(s,2,"0"))}else{var r=(p.getSeconds()+5)%60;p.setSeconds(r),e.$s.val(g(r,2,"0"))}a.select(),N(p),E(d,p)}(d,d.focus);break;case o.minus:!function(e,a){var t=a.data("time");if("h"===t){var n=(p.getHours()+23)%24;p.setHours(n),e.$h.val(g(n,2,"0"))}else if("m"===t){var s=(p.getMinutes()+55)%60;p.setMinutes(s),e.$m.val(g(s,2,"0"))}else{var r=(p.getSeconds()+55)%60;p.setSeconds(r),e.$s.val(g(r,2,"0"))}a.select(),N(p),E(d,p)}(d,d.focus)}else"mouseout"===h&&u.removeClass("hover")};m.unbind(),m.bind("mousedown",a).bind("mouseover",a).bind("mouseup",a).bind("mouseout",a)}(),r.element=m,r.$datetable=n,r.$monthtable=s,r.$timetable=d,r.getValue=function(){var e=l.VIEWMODE,a=v;return!a||t.viewMode!==e.YMD&&t.viewMode!==e.YM||a.setHours(0,0,0,0),a},r.getDisplayDate=function(){return p},r.setValue=function(e){if(!(e instanceof Date))throw"datetimepicker.setValue(): Argument is not a Date object";p=e,N(e),f(r,t.onDisplayUpdate,_arguments),w(n,e),T(s,e),E(d,e,t.viewMode)},r.getText=function(e){return function(e,a){if(!e)return"";var t=a.length,n="";if(t>0){for(var s=a.charAt(0),d=0,r=s,l=1;l<t;l++){var o=a.charAt(l);s!==o?(n+=b({char:s,str:r,len:l-d},e),d=l,r=s=o):r+=o}n+=b({char:s,str:r,len:t-d},e)}return n}(this.getValue(),e||"yyyy/MM/dd HH:mm:ss")},r.destroy=function(){return this.element.removeData("datetimepicker"),this.element.remove(),r},r}e.fn.datetimepicker=function(t){return this.each(function(){var n=e(this);n.data("dateTimePicker")||(t=e.extend(!0,{},e.fn.datetimepicker.defaults,t),n.data("dateTimePicker",new a(this,t)))})},e.fn.datetimepicker.init=function(t,n){var s=new a(t,e.extend(!0,{},e.fn.datetimepicker.defaults,n));return e(t).data("dateTimePicker",s),s},e.fn.datetimepicker.CONSTS={I18N:{zh:{SDN:["日","一","二","三","四","五","六"],MN:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],DN:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],CALENDAR:"日历",CLEAR:"清空",TODAY:"今天",OK:"确定",CURRENT:"当前",TIME:"时间"},en:{SDN:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],MN:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],DN:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],CALENDAR:"Calendar",CLEAR:"Clear",TODAY:"Today",OK:"OK",CURRENT:"Now",TIME:"Time"},de:{SDN:["So","Mo","Di","Mi","Do","Fr","Sa"],MN:["Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],DN:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],CALENDAR:"Kalender",CLEAR:"Löschen",TODAY:"Heute",OK:"OK",CURRENT:"Jetzt",TIME:"Zeit"}},VIEWMODE:{YM:"YM",YMD:"YMD",HMS:"HMS",HM:"HM",YMDHMS:"YMDHMS",YMDHM:"YMDHM"},MINYEAR:1900,MAXYEAR:2999,NAV:{prevm:2,nextm:3,title:4,clear:5,today:6,dok:7,prevy:8,nexty:9,cancel:10,mok:11,plus:12,minus:13,current:15,day:100,month:200,year:300}},e.fn.datetimepicker.defaults={baseCls:"perfect-datetimepicker",viewMode:e.fn.datetimepicker.CONSTS.VIEWMODE.YMD,firstDayOfWeek:0,date:null,endDate:null,startDate:null,language:"en",onDisplayUpdate:null,onDateChange:null,onClear:null,onOk:null,onClose:null,onToday:null}}); |