1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
3 <title>How to include additional info in day cells</title>
4 <script type="text/javascript" src="calendar.js"></script>
5 <script type="text/javascript" src="lang/calendar-en.js"></script>
6 <script type="text/javascript" src="calendar-setup.js"></script>
7 <script type="text/javascript">
8 // define info for dates in this table:
10 "20050308" : "Mishoo's birthday",
17 <style type="text/css">
18 @import url(calendar-win2k-1.css);
19 .calendar .inf { font-size: 80%; color: #444; }
20 .calendar .wn { font-weight: bold; vertical-align: top; }
25 <h1>How to include additional info in day cells</h1>
27 <div id="flatcal" style="float: right"></div>
29 <script type="text/javascript">
30 function getDateText(date, d) {
31 var inf = dateInfo[date.print("%Y%m%d")];
33 return d + "<div class='inf'> </div>";
35 return d + "<div class='inf'>" + inf + "</div>";
38 function flatCallback(cal) {
39 if (cal.dateClicked) {
41 window.status = "Selected: " + cal.date;
42 var inf = dateInfo[cal.date.print("%Y%m%d")];
44 window.status += ". Additional info: " + inf;
50 dateText: getDateText,
51 flatCallback: flatCallback
55 <p>The idea is simple:</p>
59 <p>Define a callback that takes two parameters like this:</p>
60 <pre>function getDateText(date, d)</pre>
62 This function will receive the date object as the first
63 parameter and the current date number (1..31) as the second (you
64 can get it as well by calling date.getDate() but since it's very
65 probably useful I thought I'd pass it too so that we can avoid a
69 This function <em>must</em> return the text to be inserted in
70 the cell of the passed date. That is, one should at least
75 Pass the above function as the "dateText" parameter to
81 The function could simply look like:
85 > function getDateText(date, d) {
94 but it's easy to imagine that this approach sucks. For a better
95 way, see the source of this page and note the usage of an externally
96 defined "dateText" object which maps "date" to "date info", also
97 taking into account the year and month. This object can be easily
98 generated from a database, and the getDateText function becomes
99 extremely simple (and static).
107 <address><a href="http://dynarch.com/mishoo/">mishoo</a></address>
108 <!-- hhmts start --> Last modified: Sat Mar 5 17:18:06 EET 2005 <!-- hhmts end -->