The ramblings of Chad Humphries

The calendar that prototype built

I started looking for a new javascript calendar today after the reviewing the new Yahoo Calendar from their very nice library of widgets. Unfortunately I already have a good deal of javascript in one of my applications that utilizes prototype and scriptaculous, so I figured I would try to find something that used that. After searching a bit I found a post from Xarb about a javascript calendar he created with prototype.

After initial review the calendar seems very nice and light weight, but there were some issues (mainly the prototype extension methods showing up in the month dropdown). After some review I found a simple way to patch this issue.

In date-chooser.js you can change the month selection routine to use the month numbers instead looping through the enumeration.

Old code:

for (var mon in  Date.monthNames)
  formHtml += “\r\n   + mon + “\”"
  + (mon == this._date.getMonth() ? ” selected=\”1\”" : “”)
  + “>” +  Date.monthNames[mon] + “”;

New code:

for(var monIndex = 0; monIndex <= 11; monIndex++)
  formHtml += "\r\n  + monIndex + "\""
  + (monIndex == this._date.getMonth() ? " selected=\"1\"" : "")
  + ">” + Date.monthNames[monIndex] + “”;

I’ll package my changes up later tonight and add them in.


Written by spicycode

May 20, 2006 at 5:43 pm

Posted in programming

Tagged with ,

%d bloggers like this: