// Accessible Date Picker Calendar - webSemantics // http://www.websemantics.co.uk/tutorials/accessible_jquery_date_picker_calendar/ // modified version of http://www.websemantics.co.uk/tutorials/accessible_date_picker_calendar/ function fullDate(d,m,y){ // m = 1-12 not 0-11 var td=new Date(y,m-1,d); return (daysOfWeek[td.getDay()]+", "+td.getDate()+" "+months[td.getMonth()]+" "+td.getFullYear()); } function addLead0(x){return((x<10)?"0"+x:x)} function buildCalendar(date,calObj){ // original math from http://scripts.franciscocharrua.com/calendar.php var day = date.getDate(); var month = date.getMonth(); var year = date.getFullYear(); var this_month = new Date(year,month,1); var next_month = new Date(year,month+1,1); //Find out when this month starts and ends. var first_week_day=this_month.getDay(); var days_in_this_month=Math.floor((next_month.getTime()-this_month.getTime())/(1000*60*60*24)); if (month===2) days_in_this_month=31; var calendarHTML='\n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+=' \n'; // empty days at start of month for(var week_day=0;week_day \n':' \n'; } week_day=first_week_day; var mm=addLead0(next_month.getMonth()); mm=(mm==0)?12:mm; for(var day_counter=1;day_counter<=days_in_this_month;day_counter++){ week_day%=7; if(week_day===0) calendarHTML+=' \n \n'; calendarHTML+=((week_day===0)||(week_day===6))?' \n'; week_day++ } // empty days at end of month for(week_day=week_day;week_day<7;week_day++){ calendarHTML+=((week_day==0)||(week_day==6))?' \n':' \n'; } calendarHTML+=' \n'; calendarHTML+=' \n'; calendarHTML+='
'+months[month]+' '+year+'
SMTWTFS
'+fullDate(todayDate.getDate(),todayDate.getMonth()+1,todayDate.getFullYear())+'
 
':' '; calendarHTML+=''+day_counter+'  
\n'; return calendarHTML } function hideCalendar(calObj){ $("#"+calObj.space_id).animate({opacity:0},300,function(){$(this).removeClass("show")}); $("#"+calObj.button_id).removeClass("hide"); $("#"+calObj.next_id).focus(); return false } function subtractDate(oneDate,anotherDate){ return (anotherDate-oneDate) } function toShortDate(d){ d=new Date(d); return (addLead0(d.getDate())+dateDelimiter+addLead0(d.getMonth()+1)+dateDelimiter+d.getFullYear()) } function writeInputDateValue(cObj,obj){ d=$(obj).hasClass("today")?$(obj).text():$(obj).attr("title"); if(cObj.shortDate){d=toShortDate(d)} $("#"+cObj.input_id).val(d); hideCalendar(cObj); } function displayCalendar(calObj){ $("#"+calObj.space_id) .empty() .append(buildCalendar(date,calObj)); $("#"+calObj.table_id+" button.lastmonth") .click(function(){ var dateTemp=new Date(date.getFullYear(),date.getMonth()-1,1); // rewrite this garbage: if ( (dateTemp.getFullYear()Pick date from calendar '+i+''; var calspaceHTML='
'; $(this) // end of label text but before an included input .children() .filter("input") .before(buttonHTML) .end() .end() // at end of a label without an included input .filter(function(){ return !$(this).children('input').length; }) .append(buttonHTML) .end() // .end() // add click action .find("a") .click(function(){ displayCalendar(c); return false; }) .end() // add a calender space div after the label .after(calspaceHTML); // hide calendar if focus moves off label (no cigar!) // $(this) // .blur(function(){ // alert($(this).html()) // hideCalendar(c) // }); }); // focused inputs $("input").focus(function(){$(this).addClass("focus")}) $("input").blur(function(){$(this).removeClass("focus")}) });