From a48195e52865532add00af44788c938071eb0e1d Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 20 Jan 2006 07:02:43 +0000 Subject: Update date picker --- framework/Web/Javascripts/js/datepicker.js | 192 +++++++++++++++-------------- framework/Web/Javascripts/js/prado.js | 147 +++++++++++----------- 2 files changed, 174 insertions(+), 165 deletions(-) (limited to 'framework/Web/Javascripts/js') diff --git a/framework/Web/Javascripts/js/datepicker.js b/framework/Web/Javascripts/js/datepicker.js index e840fc68..4ab5cd68 100644 --- a/framework/Web/Javascripts/js/datepicker.js +++ b/framework/Web/Javascripts/js/datepicker.js @@ -25,6 +25,7 @@ var td; this._calDiv=document.createElement("div"); this._calDiv.className=this.ClassName; this._calDiv.style.display="none"; +this._calDiv.style.position="absolute"; _4=document.createElement("div"); _4.className="calendarHeader"; this._calDiv.appendChild(_4); @@ -120,14 +121,9 @@ this._calDiv.appendChild(_4); var _17=document.createElement("button"); _17.className="todayButton"; var _18=this.newDate(); -var _19=_18.getDate()+" "+this.MonthNames[_18.getMonth()]+", "+_18.getFullYear(); +var _19=_18.SimpleFormat(this.Format); _17.appendChild(document.createTextNode(_19)); _4.appendChild(_17); -var _20=document.createElement("button"); -_20.className="clearButton"; -_19="Clear"; -_20.appendChild(document.createTextNode(_19)); -_4.appendChild(_20); if(Prado.Browser().ie){ this.iePopUp=document.createElement("iframe"); this.iePopUp.src=""; @@ -146,19 +142,18 @@ _17.hideFocus=true; Event.observe(_9,"click",this.prevMonth.bindEvent(this)); Event.observe(_12,"click",this.nextMonth.bindEvent(this)); Event.observe(_17,"click",this.selectToday.bindEvent(this)); -Event.observe(_20,"click",this.clearSelection.bindEvent(this)); Event.observe(this._monthSelect,"change",this.monthSelect.bindEvent(this)); Event.observe(this._yearSelect,"change",this.yearSelect.bindEvent(this)); Event.observe(this._calDiv,"mousewheel",this.mouseWheelChange.bindEvent(this)); Event.observe(_13,"click",this.selectDate.bindEvent(this)); -},ieHack:function(_21){ +},ieHack:function(_20){ if(this.iePopUp){ this.iePopUp.style.display="block"; this.iePopUp.style.top=(this._calDiv.offsetTop-1)+"px"; this.iePopUp.style.left=(this._calDiv.offsetLeft-1)+"px"; this.iePopUp.style.width=Math.abs(this._calDiv.offsetWidth-2)+"px"; this.iePopUp.style.height=(this._calDiv.offsetHeight+1)+"px"; -if(_21){ +if(_20){ this.iePopUp.style.display="none"; } } @@ -171,51 +166,56 @@ ev=document.parentWindow.event; } var kc=ev.keyCode!=null?ev.keyCode:ev.charCode; if(kc==Event.KEY_RETURN){ +this.setSelectedDate(this.selectedDate); Event.stop(ev); this.hide(); } -var _24=function(_25,_26){ -_25=(_25+12)%12; -var _27=[31,28,31,30,31,30,31,31,30,31,30,31]; -var res=_27[_25]; -if(_25==1){ -res+=_26%4==0&&!(_26%400==0)?1:0; +if(kc==Event.KEY_ESC){ +Event.stop(ev); +this.hide(); +} +var _23=function(_24,_25){ +_24=(_24+12)%12; +var _26=[31,28,31,30,31,30,31,31,30,31,30,31]; +var res=_26[_24]; +if(_24==1){ +res+=_25%4==0&&!(_25%400==0)?1:0; } return res; }; if(kc<37||kc>40){ return true; } -var _29=this.selectedDate; -var d=_29.valueOf(); +var _28=this.selectedDate; +var d=_28.valueOf(); if(kc==Event.KEY_LEFT){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth()-1,_29.getFullYear()))); -d=_29.setMonth(_29.getMonth()-1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth()-1,_28.getFullYear()))); +d=_28.setMonth(_28.getMonth()-1); }else{ d-=86400000; } }else{ if(kc==Event.KEY_RIGHT){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth()+1,_29.getFullYear()))); -d=_29.setMonth(_29.getMonth()+1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth()+1,_28.getFullYear()))); +d=_28.setMonth(_28.getMonth()+1); }else{ d+=86400000; } }else{ if(kc==Event.KEY_UP){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth(),_29.getFullYear()-1))); -d=_29.setFullYear(_29.getFullYear()-1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth(),_28.getFullYear()-1))); +d=_28.setFullYear(_28.getFullYear()-1); }else{ d-=604800000; } }else{ if(kc==Event.KEY_DOWN){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth(),_29.getFullYear()+1))); -d=_29.setFullYear(_29.getFullYear()+1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth(),_28.getFullYear()+1))); +d=_28.setFullYear(_28.getFullYear()+1); }else{ d+=7*24*61*60*1000; } @@ -245,8 +245,10 @@ d.setDate(n); this.setSelectedDate(d); this.hide(); },selectToday:function(){ -this.setSelectedDate(this.newDate()); +if(this.selectedDate.toISODate()==this.newDate().toISODate()){ this.hide(); +} +this.setSelectedDate(this.newDate()); },clearSelection:function(){ this.setSelectedDate(this.newDate()); this.hide(); @@ -267,19 +269,19 @@ return false; this.control.value=this.formatDate(); },formatDate:function(){ return this.selectedDate?this.selectedDate.SimpleFormat(this.Format):""; -},newDate:function(_35){ -if(!_35){ -_35=new Date(); +},newDate:function(_34){ +if(!_34){ +_34=new Date(); } -if(isString(_35)||isNumber(_35)){ -_35=new Date(_35); +if(isString(_34)||isNumber(_34)){ +_34=new Date(_34); } -return new Date(_35.getFullYear(),_35.getMonth(),_35.getDate(),0,0,0); -},setSelectedDate:function(_36){ -if(_36==null){ +return new Date(_34.getFullYear(),_34.getMonth(),_34.getDate(),0,0,0); +},setSelectedDate:function(_35){ +if(_35==null){ return; } -this.selectedDate=this.newDate(_36); +this.selectedDate=this.newDate(_35); this.updateHeader(); this.update(); if(isFunction(this.onchange)){ @@ -289,13 +291,13 @@ this.onchange(); return this._calDiv; },getSelectedDate:function(){ return isNull(this.selectedDate)?null:this.newDate(this.selectedDate); -},setYear:function(_37){ +},setYear:function(_36){ var d=this.newDate(this.selectedDate); -d.setFullYear(_37); +d.setFullYear(_36); this.setSelectedDate(d); -},setMonth:function(_38){ +},setMonth:function(_37){ var d=this.newDate(this.selectedDate); -d.setMonth(_38); +d.setMonth(_37); this.setSelectedDate(d); },nextMonth:function(){ this.setMonth(this.selectedDate.getMonth()+1); @@ -312,10 +314,10 @@ this.ieHack(false); this.documentClickEvent=this.hideOnClick.bindEvent(this); this.documentKeyDownEvent=this.keyPressed.bindEvent(this); Event.observe(document.body,"click",this.documentClickEvent); -var _40=Date.SimpleParse(Form.Element.getValue(this.control),this.Format); -if(!isNull(_40)){ -this.selectedDate=_40; -this.setSelectedDate(_40); +var _39=Date.SimpleParse(Form.Element.getValue(this.control),this.Format); +if(!isNull(_39)){ +this.selectedDate=_39; +this.setSelectedDate(_39); } Event.observe(document,"keydown",this.documentKeyDownEvent); this.showing=true; @@ -325,17 +327,17 @@ if(!this.showing){ return; } var el=Event.element(ev); -var _41=false; +var _40=false; do{ -_41=_41||el.className==this.ClassName; -_41=_41||el==this.trigger; -_41=_41||el==this.control; -if(_41){ +_40=_40||el.className==this.ClassName; +_40=_40||el==this.trigger; +_40=_40||el==this.control; +if(_40){ break; } el=el.parentNode; }while(el); -if(!_41){ +if(!_40){ this.hide(); } },hide:function(){ @@ -349,61 +351,61 @@ Event.stopObserving(document.body,"click",this.documentClickEvent); Event.stopObserving(document,"keydown",this.documentKeyDownEvent); } },update:function(){ -var _42=this.selectedDate; -var _43=(this.newDate()).toISODate(); -var _44=_42.toISODate(); -var d1=new Date(_42.getFullYear(),_42.getMonth(),1); -var d2=new Date(_42.getFullYear(),_42.getMonth()+1,1); -var _47=Math.round((d2-d1)/(24*60*60*1000)); -var _48=(d1.getDay()-this.FirstDayOfWeek)%7; -if(_48<0){ -_48+=7; -} -var _49=0; -while(_49<_48){ -this.dateSlot[_49].value=-1; -this.dateSlot[_49].data.data=String.fromCharCode(160); -this.dateSlot[_49].data.parentNode.className="empty"; -_49++; -} -for(i=1;i<=_47;i++,_49++){ -var _50=this.dateSlot[_49]; -var _51=_50.data.parentNode; -_50.value=i; -_50.data.data=i; -_51.className="date"; -if(d1.toISODate()==_43){ -_51.className+=" today"; +var _41=this.selectedDate; +var _42=(this.newDate()).toISODate(); +var _43=_41.toISODate(); +var d1=new Date(_41.getFullYear(),_41.getMonth(),1); +var d2=new Date(_41.getFullYear(),_41.getMonth()+1,1); +var _46=Math.round((d2-d1)/(24*60*60*1000)); +var _47=(d1.getDay()-this.FirstDayOfWeek)%7; +if(_47<0){ +_47+=7; +} +var _48=0; +while(_48<_47){ +this.dateSlot[_48].value=-1; +this.dateSlot[_48].data.data=String.fromCharCode(160); +this.dateSlot[_48].data.parentNode.className="empty"; +_48++; +} +for(i=1;i<=_46;i++,_48++){ +var _49=this.dateSlot[_48]; +var _50=_49.data.parentNode; +_49.value=i; +_49.data.data=i; +_50.className="date"; +if(d1.toISODate()==_42){ +_50.className+=" today"; } -if(d1.toISODate()==_44){ -_51.className+=" selected"; +if(d1.toISODate()==_43){ +_50.className+=" selected"; } d1=new Date(d1.getFullYear(),d1.getMonth(),d1.getDate()+1); } -var _52=_49; -while(_49<42){ -this.dateSlot[_49].value=-1; -this.dateSlot[_49].data.data=String.fromCharCode(160); -this.dateSlot[_49].data.parentNode.className="empty"; -++_49; +var _51=_48; +while(_48<42){ +this.dateSlot[_48].value=-1; +this.dateSlot[_48].data.data=String.fromCharCode(160); +this.dateSlot[_48].data.parentNode.className="empty"; +++_48; } },hover:function(ev){ Element.condClassName(Event.element(ev),"hover",ev.type=="mouseover"); },updateHeader:function(){ -var _53=this._monthSelect.options; +var _52=this._monthSelect.options; var m=this.selectedDate.getMonth(); -for(var i=0;i<_53.length;++i){ -_53[i].selected=false; -if(_53[i].value==m){ -_53[i].selected=true; -} -} -_53=this._yearSelect.options; -var _54=this.selectedDate.getFullYear(); -for(var i=0;i<_53.length;++i){ -_53[i].selected=false; -if(_53[i].value==_54){ -_53[i].selected=true; +for(var i=0;i<_52.length;++i){ +_52[i].selected=false; +if(_52[i].value==m){ +_52[i].selected=true; +} +} +_52=this._yearSelect.options; +var _53=this.selectedDate.getFullYear(); +for(var i=0;i<_52.length;++i){ +_52[i].selected=false; +if(_52[i].value==_53){ +_52[i].selected=true; } } }}; diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 92bd4921..590882fa 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -1961,144 +1961,151 @@ _89.push(_88[i]); return _89; }}; -Object.extend(Date.prototype,{SimpleFormat:function(_1){ -var _2=new Array(); -_2["d"]=this.getDate(); -_2["dd"]=String(this.getDate()).zerofill(2); -_2["M"]=this.getMonth()+1; -_2["MM"]=String(this.getMonth()+1).zerofill(2); -var _3=""+this.getFullYear(); -_3=(_3.length==2)?"19"+_3:_3; -_2["yyyy"]=_3; -_2["yy"]=_2["yyyy"].toString().substr(2,2); -var _4=new String(_1); -for(var _5 in _2){ -var _6=new RegExp("\\b"+_5+"\\b","g"); -_4=_4.replace(_6,_2[_5]); +Object.extend(Date.prototype,{SimpleFormat:function(_1,_2){ +_2=_2||{}; +var _3=new Array(); +_3["d"]=this.getDate(); +_3["dd"]=String(this.getDate()).zerofill(2); +_3["M"]=this.getMonth()+1; +_3["MM"]=String(this.getMonth()+1).zerofill(2); +if(_2.AbbreviatedMonthNames){ +_3["MMM"]=_2.AbbreviatedMonthNames[this.getMonth()]; +} +if(_2.MonthNames){ +_3["MMMM"]=_2.MonthNames[this.getMonth()]; +} +var _4=""+this.getFullYear(); +_4=(_4.length==2)?"19"+_4:_4; +_3["yyyy"]=_4; +_3["yy"]=_3["yyyy"].toString().substr(2,2); +var _5=new String(_1); +for(var _6 in _3){ +var _7=new RegExp("\\b"+_6+"\\b","g"); +_5=_5.replace(_7,_3[_6]); } -return _4; +return _5; },toISODate:function(){ var y=this.getFullYear(); var m=String(this.getMonth()+1).zerofill(2); var d=String(this.getDate()).zerofill(2); return String(y)+String(m)+String(d); }}); -Object.extend(Date,{SimpleParse:function(_10,_11){ -val=String(_10); -_11=String(_11); +Object.extend(Date,{SimpleParse:function(_11,_12){ +val=String(_11); +_12=String(_12); if(val.length<=0){ return null; } -if(_11.length<=0){ -return new Date(_10); +if(_12.length<=0){ +return new Date(_11); } -var _12=function(val){ -var _14="1234567890"; +var _13=function(val){ +var _15="1234567890"; for(var i=0;i=_18;x--){ -var _21=str.substring(i,i+x); -if(_21.length<_18){ +var _17=function(str,i,_19,_20){ +for(var x=_20;x>=_19;x--){ +var _22=str.substring(i,i+x); +if(_22.length<_19){ return null; } -if(_12(_21)){ -return _21; +if(_13(_22)){ +return _22; } } return null; }; -var _22=0; var _23=0; +var _24=0; var c=""; -var _25=""; var _26=""; +var _27=""; var x,y; var now=new Date(); -var _28=now.getFullYear(); -var _29=now.getMonth()+1; -var _30=1; -while(_23<_11.length){ -c=_11.charAt(_23); -_25=""; -while((_11.charAt(_23)==c)&&(_23<_11.length)){ -_25+=_11.charAt(_23++); -} -if(_25=="yyyy"||_25=="yy"||_25=="y"){ -if(_25=="yyyy"){ +var _29=now.getFullYear(); +var _30=now.getMonth()+1; +var _31=1; +while(_24<_12.length){ +c=_12.charAt(_24); +_26=""; +while((_12.charAt(_24)==c)&&(_24<_12.length)){ +_26+=_12.charAt(_24++); +} +if(_26=="yyyy"||_26=="yy"||_26=="y"){ +if(_26=="yyyy"){ x=4; y=4; } -if(_25=="yy"){ +if(_26=="yy"){ x=2; y=2; } -if(_25=="y"){ +if(_26=="y"){ x=2; y=4; } -_28=_16(val,_22,x,y); -if(_28==null){ +_29=_17(val,_23,x,y); +if(_29==null){ return null; } -_22+=_28.length; -if(_28.length==2){ -if(_28>70){ -_28=1900+(_28-0); +_23+=_29.length; +if(_29.length==2){ +if(_29>70){ +_29=1900+(_29-0); }else{ -_28=2000+(_28-0); +_29=2000+(_29-0); } } }else{ -if(_25=="MM"||_25=="M"){ -_29=_16(val,_22,_25.length,2); -if(_29==null||(_29<1)||(_29>12)){ +if(_26=="MM"||_26=="M"){ +_30=_17(val,_23,_26.length,2); +if(_30==null||(_30<1)||(_30>12)){ return null; } -_22+=_29.length; +_23+=_30.length; }else{ -if(_25=="dd"||_25=="d"){ -_30=_16(val,_22,_25.length,2); -if(_30==null||(_30<1)||(_30>31)){ +if(_26=="dd"||_26=="d"){ +_31=_17(val,_23,_26.length,2); +if(_31==null||(_31<1)||(_31>31)){ return null; } -_22+=_30.length; +_23+=_31.length; }else{ -if(val.substring(_22,_22+_25.length)!=_25){ +if(val.substring(_23,_23+_26.length)!=_26){ return null; }else{ -_22+=_25.length; +_23+=_26.length; } } } } } -if(_22!=val.length){ +if(_23!=val.length){ return null; } -if(_29==2){ -if(((_28%4==0)&&(_28%100!=0))||(_28%400==0)){ -if(_30>29){ +if(_30==2){ +if(((_29%4==0)&&(_29%100!=0))||(_29%400==0)){ +if(_31>29){ return null; } }else{ -if(_30>28){ +if(_31>28){ return null; } } } -if((_29==4)||(_29==6)||(_29==9)||(_29==11)){ -if(_30>30){ +if((_30==4)||(_30==6)||(_30==9)||(_30==11)){ +if(_31>30){ return null; } } -var _31=new Date(_28,_29-1,_30,0,0,0); -return _31; +var _32=new Date(_29,_30-1,_31,0,0,0); +return _32; }}); var Prado={Version:"3.0a",Browser:function(){ -- cgit v1.2.3