You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dayinfo.html 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  2. <html> <head>
  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:
  9. var dateInfo = {
  10. "20050308" : "Mishoo's&nbsp;birthday",
  11. "20050310" : "foo",
  12. "20050315" : "bar",
  13. "20050318" : "25$",
  14. "20050324" : "60$"
  15. };
  16. </script>
  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; }
  21. </style>
  22. </head>
  23. <body>
  24. <h1>How to include additional info in day cells</h1>
  25. <div id="flatcal" style="float: right"></div>
  26. <script type="text/javascript">
  27. function getDateText(date, d) {
  28. var inf = dateInfo[date.print("%Y%m%d")];
  29. if (!inf) {
  30. return d + "<div class='inf'>&nbsp;</div>";
  31. } else {
  32. return d + "<div class='inf'>" + inf + "</div>";
  33. }
  34. };
  35. function flatCallback(cal) {
  36. if (cal.dateClicked) {
  37. // do something here
  38. window.status = "Selected: " + cal.date;
  39. var inf = dateInfo[cal.date.print("%Y%m%d")];
  40. if (inf) {
  41. window.status += ". Additional info: " + inf;
  42. }
  43. }
  44. };
  45. Calendar.setup({
  46. flat: "flatcal",
  47. dateText: getDateText,
  48. flatCallback: flatCallback
  49. });
  50. </script>
  51. <p>The idea is simple:</p>
  52. <ol>
  53. <li>
  54. <p>Define a callback that takes two parameters like this:</p>
  55. <pre>function getDateText(date, d)</pre>
  56. <p>
  57. This function will receive the date object as the first
  58. parameter and the current date number (1..31) as the second (you
  59. can get it as well by calling date.getDate() but since it's very
  60. probably useful I thought I'd pass it too so that we can avoid a
  61. function call).
  62. </p>
  63. <p>
  64. This function <em>must</em> return the text to be inserted in
  65. the cell of the passed date. That is, one should at least
  66. "return d;".
  67. </p>
  68. </li>
  69. <li>
  70. Pass the above function as the "dateText" parameter to
  71. Calendar.setup.
  72. </li>
  73. </ol>
  74. <p>
  75. The function could simply look like:
  76. </p>
  77. <pre
  78. > function getDateText(date, d) {
  79. if (d == 12) {
  80. return "12th";
  81. } else if (d == 13) {
  82. return "bad luck";
  83. } /* ... etc ... */
  84. }</pre>
  85. <p>
  86. but it's easy to imagine that this approach sucks. For a better
  87. way, see the source of this page and note the usage of an externally
  88. defined "dateText" object which maps "date" to "date info", also
  89. taking into account the year and month. This object can be easily
  90. generated from a database, and the getDateText function becomes
  91. extremely simple (and static).
  92. </p>
  93. <p>
  94. Cheers!
  95. </p>
  96. <hr />
  97. <address><a href="http://dynarch.com/mishoo/">mishoo</a></address>
  98. <!-- hhmts start --> Last modified: Sat Mar 5 17:18:06 EET 2005 <!-- hhmts end -->
  99. </body> </html>