simple-1.html 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <html style="background-color: buttonface; color: buttontext;">
  2. <head>
  3. <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
  4. <title>Simple calendar setups [popup calendar]</title>
  5. <!-- calendar stylesheet -->
  6. <link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-cold-1.css" title="win2k-cold-1" />
  7. <!-- main calendar program -->
  8. <script type="text/javascript" src="calendar.js"></script>
  9. <!-- language for the calendar -->
  10. <script type="text/javascript" src="lang/calendar-en.js"></script>
  11. <!-- the following script defines the Calendar.setup helper function, which makes
  12. adding a calendar a matter of 1 or 2 lines of code. -->
  13. <script type="text/javascript" src="calendar-setup.js"></script>
  14. </head>
  15. <body>
  16. <h2>DHTML Calendar &mdash; for the impatient</h2>
  17. <blockquote>
  18. <p>
  19. This page lists some common setups for the popup calendar. In
  20. order to see how to do any of them please see the source of this
  21. page. For each example it's structured like this: there's the
  22. &lt;form&gt; that contains the input field, and following there is
  23. the JavaScript snippet that setups that form. An example of
  24. <em>flat</em> calendar is available in <a
  25. href="simple-2.html">another page</a>.
  26. </p>
  27. <p>
  28. The code in this page uses a helper function defined in
  29. "calendar-setup.js". With it you can setup the calendar in
  30. minutes. If you're not <em>that</em> impatient, ;-) <a
  31. href="doc/html/reference.html">complete documenation</a> is
  32. available.
  33. </p>
  34. </blockquote>
  35. <hr />
  36. <p><b>Basic setup: one input per calendar.</b> Clicking in the input field
  37. activates the calendar. The date format is "%m/%d/%Y %I:%M %p". The
  38. calendar defaults to "single-click mode".</p>
  39. <p>The example below has been updated to show you how to create "linked"
  40. fields. Basically, when some field is filled with a date, the other
  41. is updated so that the difference between them remains one week. The
  42. property useful here is "onUpdate".</p>
  43. <form action="#" method="get">
  44. <input type="text" name="date" id="f_date_a" />
  45. <input type="text" name="date" id="f_calcdate" />
  46. </form>
  47. <script type="text/javascript">
  48. function catcalc(cal) {
  49. var date = cal.date;
  50. var time = date.getTime()
  51. // use the _other_ field
  52. var field = document.getElementById("f_calcdate");
  53. if (field == cal.params.inputField) {
  54. field = document.getElementById("f_date_a");
  55. time -= Date.WEEK; // substract one week
  56. } else {
  57. time += Date.WEEK; // add one week
  58. }
  59. var date2 = new Date(time);
  60. field.value = date2.print("%Y-%m-%d %H:%M");
  61. }
  62. Calendar.setup({
  63. inputField : "f_date_a", // id of the input field
  64. ifFormat : "%Y-%m-%d %H:%M", // format of the input field
  65. showsTime : true,
  66. timeFormat : "24",
  67. onUpdate : catcalc
  68. });
  69. Calendar.setup({
  70. inputField : "f_calcdate",
  71. ifFormat : "%Y-%m-%d %H:%M",
  72. showsTime : true,
  73. timeFormat : "24",
  74. onUpdate : catcalc
  75. });
  76. </script>
  77. <hr />
  78. <p><b>Input field with a trigger button.</b> Clicking the button activates
  79. the calendar. Note that this one needs double-click (singleClick parameter
  80. is explicitely set to false). Also demonstrates the "step" parameter
  81. introduced in 0.9.6 (show all years in drop-down boxes, instead of every
  82. other year as default).</p>
  83. <form action="#" method="get">
  84. <input type="text" name="date" id="f_date_b" /><button type="reset" id="f_trigger_b">...</button>
  85. </form>
  86. <script type="text/javascript">
  87. Calendar.setup({
  88. inputField : "f_date_b", // id of the input field
  89. ifFormat : "%m/%d/%Y %I:%M %p", // format of the input field
  90. showsTime : true, // will display a time selector
  91. button : "f_trigger_b", // trigger for the calendar (button ID)
  92. singleClick : false, // double-click mode
  93. step : 1 // show all years in drop-down boxes (instead of every other year as default)
  94. });
  95. </script>
  96. <hr />
  97. <p><b>Input field with a trigger image.</b> Note that the Calendar.setup
  98. function doesn't care if the trigger is a button, image, or anything else.
  99. Also in this example we setup a different alignment, just to show how it's
  100. done. The input field is read-only (that is set from HTML).</p>
  101. <form action="#" method="get">
  102. <table cellspacing="0" cellpadding="0" style="border-collapse: collapse"><tr>
  103. <td><input type="text" name="date" id="f_date_c" readonly="1" /></td>
  104. <td><img src="img.gif" id="f_trigger_c" style="cursor: pointer; border: 1px solid red;" title="Date selector"
  105. onmouseover="this.style.background='red';" onmouseout="this.style.background=''" /></td>
  106. </table>
  107. </form>
  108. <script type="text/javascript">
  109. Calendar.setup({
  110. inputField : "f_date_c", // id of the input field
  111. ifFormat : "%B %e, %Y", // format of the input field
  112. button : "f_trigger_c", // trigger for the calendar (button ID)
  113. align : "Tl", // alignment (defaults to "Bl")
  114. singleClick : true
  115. });
  116. </script>
  117. <hr />
  118. <p><b>Hidden field, display area.</b> The calendar now puts the date into 2
  119. elements: one is an input field of type "hidden"&mdash;so that the user
  120. can't directly see or modify it&mdash; and one is a &lt;span&gt; element in
  121. which the date is displayed. Note that if the trigger is not specified the
  122. calendar will use the displayArea (or inputField as in the first example).
  123. The display area can have it's own format. This is useful if, for instance,
  124. we need to store one format in the database (thus pass it in the input
  125. field) but we wanna show a friendlier format to the end-user.</p>
  126. <form action="#" method="get" style="visibility: hidden">
  127. <input type="hidden" name="date" id="f_date_d" />
  128. </form>
  129. <p>Your birthday:
  130. <span style="background-color: #ff8; cursor: default;"
  131. onmouseover="this.style.backgroundColor='#ff0';"
  132. onmouseout="this.style.backgroundColor='#ff8';"
  133. id="show_d"
  134. >Click to open date selector</span>.</p>
  135. <script type="text/javascript">
  136. Calendar.setup({
  137. inputField : "f_date_d", // id of the input field
  138. ifFormat : "%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
  139. displayArea : "show_d", // ID of the span where the date is to be shown
  140. daFormat : "%A, %B %d, %Y",// format of the displayed date
  141. align : "Tl", // alignment (defaults to "Bl")
  142. singleClick : true
  143. });
  144. </script>
  145. <hr />
  146. <p><b>Hidden field, display area, trigger image.</b> Very similar to the
  147. previous example. The difference is that we also have a trigger image.</p>
  148. <form action="#" method="get" style="visibility: hidden">
  149. <input type="hidden" name="date" id="f_date_e" />
  150. </form>
  151. <p>Your birthday: <span id="show_e">-- not entered --</span> <img
  152. src="img.gif" id="f_trigger_e" style="cursor: pointer; border: 1px solid
  153. red;" title="Date selector" onmouseover="this.style.background='red';"
  154. onmouseout="this.style.background=''" />.</p>
  155. <script type="text/javascript">
  156. Calendar.setup({
  157. inputField : "f_date_e", // id of the input field
  158. ifFormat : "%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
  159. displayArea : "show_e", // ID of the span where the date is to be shown
  160. daFormat : "%A, %B %d, %Y",// format of the displayed date
  161. button : "f_trigger_e", // trigger button (well, IMG in our case)
  162. align : "Tl", // alignment (defaults to "Bl")
  163. singleClick : true
  164. });
  165. </script>
  166. <hr />
  167. <p><b>Hidden field, display area.</b> Very much like the previous examples,
  168. but we now disable some dates (all weekends, that is, Saturdays and
  169. Sundays).</p>
  170. <form action="#" method="get" style="visibility: hidden">
  171. <input type="hidden" name="date" id="f_date_f" />
  172. </form>
  173. <p>Your birthday:
  174. <span style="background-color: #ff8; cursor: default;"
  175. onmouseover="this.style.backgroundColor='#ff0';"
  176. onmouseout="this.style.backgroundColor='#ff8';"
  177. id="show_f"
  178. >Click to open date selector</span>.</p>
  179. <script type="text/javascript">
  180. Calendar.setup({
  181. inputField : "f_date_f", // id of the input field
  182. ifFormat : "%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
  183. displayArea : "show_f", // ID of the span where the date is to be shown
  184. daFormat : "%A, %B %d, %Y",// format of the displayed date
  185. align : "Tl", // alignment (defaults to "Bl")
  186. dateStatusFunc : function (date) { // disable weekend days (Saturdays == 6 and Subdays == 0)
  187. return (date.getDay() == 6 || date.getDay() == 0) ? true : false;
  188. }
  189. });
  190. </script>
  191. </body>
  192. </html>