|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
IntroductionThis article describes the development and usage of the attached calendar script. The calendar generated by the script can be used as a date picker, an event navigator, or simply as a dynamically generated static display. While this script has been tested with Internet Explorer 6.0 and Firefox 0.8 and 1.0, on Windows XP, I have not tested it against other browsers and operating systems. There is a known issue with Internet Explorer on Windows XP SP2; points on working around this are presented below. BackgroundWhen I started this project, it was mainly to create a lightweight and more neatly customizable version of the ASP.NET calendar control. Although I use C# nearly exclusively these days, I come from a Java/JSP background, and still make occasional use of PHP. With this in mind, I wanted something which I could use independently of the server side scripting language being used, without compromising functionality. There were a few objectives which I wanted to meet with this calendar:
Although I think I missed the "lightweight" target, I feel that the current implementation achieves all of the above objectives. Using the codeThe calendar script should be referenced like any other external JavaScript file. In order to avoid falling foul of the SP2 script blocking, make sure that you deploy the script file to the same domain as the page calling it. To set up the calendar, you should use the constructor as shown below: cal1 = new Calendar ("cal1", "tester", new Date());
The first argument, BindingIn order to provide data for a form action, the calendar has to be bound to an If you want to bind the calendar to a single text box, define an cal1.fallback = cal1.fallback_single;
Creating a calendar feeding three separate fields for day, month and year requires a little more work, but not much. The fields have to be given IDs with the suffixes "_day", "_month" and "_year" respectively; our example would bind to " cal1.fallback = cal1.fallback_multi;
DisplayIf you test the page at this point, nothing should appear. In order to render the calendar, specify a To render the calendar, call the renderCalendar (cal1);
This will cause the calendar to be displayed in the EventsTo highlight event dates in your calendar, insert an array of event dates into the calendar's cal2.eventDates = new Array(
new Array("2005/2/10", 1)
, new Array("2005/2/12", 2)
, new Array("2005/2/14", 3)
);
The first argument in each array represents the event date; the second represents an event ID. To add on-click functionality to the event dates, you can specify an cal2.selectEvent = function(eventId) {alert("cal2 Event: " + eventId);};
Overall, I think this is the shakiest area when it comes to configuration. I hope to revisit it soon and polish it up using JavaScript RPCs. Points of InterestI hope this project will be of use to others; CodeProject has been very useful to me, and I hope this contribution will, if not used directly, further the education of others; it certainly did mine. The calendar is capable of a few tricks, so please feel free to play around with the properties in the script. Most of these should be self-explanatory; however, I will be pleased to answer any pertinent questions. HistoryRevision: 1.1 - 2005/02/15 23:47:44 - Initial revision.
|
||||||||||||||||||||||