![]() |
|
#1
|
|||
|
|||
|
See my attached modification of the most recent release (retrieved 2007.07.24).
It's got some vars at the top to control the date format and if to prefix the dates and months with a '0' . The formatting is respected on the output value as well as the input parsing. I've also setup a variable to disable past date selections or to allow them. This is without adding much to the size (7.3KB). ...hope this helps someone... thanks, -alan- |
|
#2
|
|||
|
|||
|
Excellent ! That's precisely what was missing to the widget, IMHO, to complete Oliver's brilliant job. And what I also started to hack, but now can spare myself doing
mmmh, wait a minute... what's this ugly pink as a background ?? lol I've just updated it a bit, and attached the code, to make it more standard compliant ( by adding "px" units for top and left positioning values ) as discussed in another topic here. Thanks. William |
|
#3
|
|||
|
|||
|
Change the codes:
ccd=parseInt(curdtarr[0]); (etc) for ccd=parseInt(curdtarr[0], 10); Motive: When the month is september ('09') this undertand this like octal base, and convert to (0), giving then a undefined month. |
|
#4
|
|||
|
|||
|
Hey guys,
I fixed the calendar and now it can do past month and year and without the "undefine date" problem. Below is the code /* --- Swazz Javascript Calendar --- /* --- v 1.0 3rd November 2006 By Oliver Bryant http://calendar.swazz.org Modified by Alan Blount - alan[a7]zeroasterisk[d07]com Modified by William Eriau - inmagnaveritas[at]gmail.com - fixed positioning problem when using doctype */ //var dateformat = 'ymd'; // year-month-date //var dateformat = 'mdy'; // date-month-year var dateformat = 'dmy'; // date-month-year (default) var datesplitter = '/'; // in between date, month, year... typically '/' or '-' var prefix0 = true; // months and dates less than 10, get prefixed w/ a '0' var disablepast = false; // disable date selection in the past document.write('<table id="fc" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>'); document.write('<tr><td style="cursor document.write('<tr><td align=center style="background:#ABABAB;font:12px Arial">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">S</td></tr>'); for(var kk=1;kk<=6;kk++) { document.write('<tr>'); for(var tt=1;tt<=7;tt++) { num=7 * (kk-1) - (-tt); document.write('<td id="v' + num + '" style="width:18px;height:18px"> </td>'); } document.write('</tr>'); } document.write('</table>'); document.all?document.attachEvent('onclick',checkC lick):document.addEventListener('click',checkClick ,false); // Calendar script var now = new Date; var sccm=now.getMonth(); var sccy=now.getFullYear(); var scfd=now.getDate(); var ccm=sccm; var ccy=sccy; var cfd=scfd; var updobj; var mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','A UG','SEP','OCT','NOV','DEC'); var mnn=new Array('31','28','31','30','31','30','31','31','30' ,'31','30','31'); var mnl=new Array('31','29','31','30','31','30','31','31','30' ,'31','30','31'); var calvalarr=new Array(42); prepcalendar('',ccm,ccy); //getObj('fc'+cc).style.visibility='hidden'; function getObj(objID) { if (document.getElementById) {return document.getElementById(objID);} else if (document.all) {return document.all[objID];} else if (document.layers) {return document.layers[objID];} } function checkClick(e) { e?evt=e:evt=event; CSE=evt.target?evt.target:evt.srcElement; if (getObj('fc')) if (!isChild(CSE,getObj('fc'))) getObj('fc').style.display='none'; } function isChild(s,d) { while(s) { if (s==d) return true; s=s.parentNode; } return false; } function Left(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function Top(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } function lcs(ielem) { updobj=ielem; getObj('fc').style.left = Left(ielem) + "px"; getObj('fc').style.top = Top(ielem) + ielem.offsetHeight + "px"; getObj('fc').style.display = ''; // First check date is valid curdt=ielem.value; curdtarr=curdt.replace(/\ /gi,'').replace(/[^0-9]/gi,'/').split('/'); isdt=true; for(var k=0;k<curdtarr.length;k++) { if (isNaN(parseInt(curdtarr[k]))) isdt=false; } if (isdt&(curdtarr.length==3)) { if (dateformat=='ymd') { ccy=parseInt(curdtarr[0], 10); ccm=parseInt(curdtarr[1], 10)-1; ccd=parseInt(curdtarr[2], 10); } else if (dateformat=='mdy') { ccy=parseInt(curdtarr[2], 10); ccm=parseInt(curdtarr[0], 10)-1; ccd=parseInt(curdtarr[1], 10); } else { ccy=parseInt(curdtarr[2], 10); ccm=parseInt(curdtarr[1], 10)-1; ccd=parseInt(curdtarr[0], 10); } prepcalendar(ccd,ccm,ccy); } } function evtTgt(e) { var el; if(e.target)el=e.target; else if(e.srcElement)el=e.srcElement; if(el.nodeType==3)el=el.parentNode; // defeat Safari bug return el; } function EvtObj(e){if(!e)e=window.event;return e;} function cs_over(e) { evtTgt(EvtObj(e)).style.background='#FFCC66'; } function cs_out(e) { evtTgt(EvtObj(e)).style.background='#FFF0F5'; } function cs_click(e) { updobj.value=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)) .id.length)]; getObj('fc').style.display='none'; } function f_cps(obj) { obj.style.background='#FFF0F5'; obj.style.font='10px Arial'; obj.style.color='#333333'; obj.style.textAlign='center'; obj.style.textDecoration='none'; obj.style.border='1px solid #FFE4E1'; obj.style.cursor='pointer'; } function f_cpps(obj) { obj.style.background='#FFF0F5'; obj.style.font='10px Arial'; obj.style.color='#ABABAB'; obj.style.textAlign='center'; obj.style.textDecoration='line-through'; obj.style.border='1px solid #FAF0E6'; obj.style.cursor='default'; } function f_hds(obj) { obj.style.background='#E36087'; obj.style.font='bold 10px Arial'; obj.style.color='#000000'; obj.style.textAlign='center'; obj.style.border='1px solid #250709'; obj.style.cursor='pointer'; } // day selected function prepcalendar(hd,cm,cy) { now=new Date(); sd=now.getDate(); td=new Date(); td.setDate(1); td.setFullYear(cy); td.setMonth(cm); cd=td.getDay(); getObj('mns').innerHTML=mn[cm]+ ' ' + cy; marr=((cy%4)==0)?mnl:mnn; for(var d=1;d<=42;d++) { f_cps(getObj('v'+parseInt(d))); if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) { dip=(disablepast&&(d-cd < sd)&&(cm==sccm)&&(cy==sccy)); htd=((hd!='')&&(d-cd==hd)); if (dip) f_cpps(getObj('v'+parseInt(d))); else if (htd) f_hds(getObj('v'+parseInt(d))); else f_cps(getObj('v'+parseInt(d))); getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_ over; getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_o ut; getObj('v'+parseInt(d)).onclick=(dip)?null:cs_clic k; getObj('v'+parseInt(d)).innerHTML=d-cd; cmx = parseInt(cm)+1; if (cmx < 10 && prefix0==true) { cmx = '0'+cmx; } dx = d-cd; if (dx < 10 && prefix0==true) { dx = '0'+dx; } if (dateformat=='ymd') { calvalarr[d]=''+cy+datesplitter+cmx+datesplitter+dx; } else if (dateformat=='mdy') { calvalarr[d]=''+cmx+datesplitter+dx+datesplitter+cy; } else { calvalarr[d]=''+dx+datesplitter+cmx+datesplitter+cy; } } else { getObj('v'+d).innerHTML=' '; getObj('v'+parseInt(d)).onmouseover=null; getObj('v'+parseInt(d)).onmouseout=null; getObj('v'+parseInt(d)).style.cursor='default'; } } } function caddm() { marr=((ccy%4)==0)?mnl:mnn; ccm+=1; if (ccm>=12) { ccm=0; ccy++; } cdayf(); prepcalendar('',ccm,ccy); } //Added for Next Year Function function caddy() { marr=((ccy%4)==0)?mnl:mnn; ccy++; prepcalendar('',ccm,ccy); } function csubm() { marr=((ccy%4)==0)?mnl:mnn; ccm-=1; if (ccm<0) { ccm=11; ccy--; } cdayf(); prepcalendar('',ccm,ccy); } //added for Previous Year Function function csuby() { marr=((ccy%4)==0)?mnl:mnn; ccy--; prepcalendar('',ccm,ccy); } function cdayf() { if (!disablepast||((ccy>sccy)||((ccy==sccy)&&(ccm>=sc cm)))) return; else { ccy=sccy; ccm=sccm; cfd=scfd; } } |
|
#5
|
|||
|
|||
|
Hi @all,
I've modified it again: - You can choose German as second language - You can choose your startday (Monday or Sunday) - You can allow or disable the Past with only one command: lcs(this, true) or lcs(this, false). Have fun with these featuers |
|
#6
|
|||
|
|||
|
Hey,
I want the past days as while as the present Saturday and Sunday field disable. |
|
#7
|
|||
|
|||
|
I added Greek as an extra language
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|