source: trunk/phpgwapi/js/jscalendar/doc/html/reference.html @ 2

Revision 2, 59.1 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!--
4
5Generated from TeX source by tex2page, v 4r8f
6(running on MzScheme 204, unix),
7(c) Dorai Sitaram,
8http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html
9
10-->
11<head>
12<title>
13DHTML Calendar Widget
14</title>
15<link rel="stylesheet" type="text/css" href="reference.css" title=default>
16<link rel="stylesheet" type="text/css" href="reference-Z-S.css" title=default>
17<meta name=robots content="index,follow">
18</head>
19<body>
20<p>
21</p>
22<p>
23</p>
24<p>
25</p>
26<p>
27</p>
28<p>
29</p>
30<p>
31
32
33
34</p>
35<p>
36
37
38
39</p>
40<p>
41
42
43</p>
44<p>
45</p>
46<p>
47</p>
48<h1 class=title align=center><br><br>DHTML Calendar Widget</h1>
49<p></p>
50<div align=center>
51Mihai Bazon, <tt>&lt;mishoo@infoiasi.ro&gt;</tt><p>February 6, 2004<br></p>
52<p></p>
53<p>
54<span class=small>calendar version: 0.9.6 &#8220;Keep cool but don&#8217;t freeze&#8221;</span>
55</p>
56</div>
57<p></p>
58<p>
59</p>
60<span class=small><blockquote>
61<div align=right><table><tr><td>
62
63</td></tr></table></div>
64
65</blockquote></span>
66<a name="node_sec_Temp_1"></a>
67<h1>Contents</h1><p><a name="node_toc_start"></a></p>
68<p><b>
69&nbsp; &nbsp; <a name="node_toc_node_sec_1"></a><a href="#node_sec_1">1&nbsp;&nbsp;Overview</a></b><br>
70&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_1.1"></a><a href="#node_sec_1.1">1.1&nbsp;&nbsp;How does this thing work?</a><br>
71&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_1.2"></a><a href="#node_sec_1.2">1.2&nbsp;&nbsp;Project files</a><br>
72&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_1.3"></a><a href="#node_sec_1.3">1.3&nbsp;&nbsp;License</a><br>
73</p>
74<p><b>
75&nbsp; &nbsp; <a name="node_toc_node_sec_2"></a><a href="#node_sec_2">2&nbsp;&nbsp;Quick startup</a></b><br>
76&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_2.1"></a><a href="#node_sec_2.1">2.1&nbsp;&nbsp;Installing a popup calendar</a><br>
77&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_2.2"></a><a href="#node_sec_2.2">2.2&nbsp;&nbsp;Installing a flat calendar</a><br>
78&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_2.3"></a><a href="#node_sec_2.3">2.3&nbsp;&nbsp;<tt>Calendar.setup</tt> in detail</a><br>
79</p>
80<p><b>
81&nbsp; &nbsp; <a name="node_toc_node_sec_3"></a><a href="#node_sec_3">3&nbsp;&nbsp;The Calendar object overview</a></b><br>
82&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_3.1"></a><a href="#node_sec_3.1">3.1&nbsp;&nbsp;Creating a calendar</a><br>
83&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_3.2"></a><a href="#node_sec_3.2">3.2&nbsp;&nbsp;Order does matter ;-)</a><br>
84&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_3.3"></a><a href="#node_sec_3.3">3.3&nbsp;&nbsp;Caching the object</a><br>
85&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_3.4"></a><a href="#node_sec_3.4">3.4&nbsp;&nbsp;Callback functions</a><br>
86</p>
87<p><b>
88&nbsp; &nbsp; <a name="node_toc_node_sec_4"></a><a href="#node_sec_4">4&nbsp;&nbsp;The Calendar object API reference</a></b><br>
89&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.1"></a><a href="#node_sec_4.1">4.1&nbsp;&nbsp;<tt>Calendar</tt> constructor</a><br>
90&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.2"></a><a href="#node_sec_4.2">4.2&nbsp;&nbsp;Useful member variables (properties)</a><br>
91&nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3"></a><a href="#node_sec_4.3">4.3&nbsp;&nbsp;Public methods</a><br>
92&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.1"></a><a href="#node_sec_4.3.1">4.3.1&nbsp;&nbsp;<tt>Calendar.create</tt></a><br>
93&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.2"></a><a href="#node_sec_4.3.2">4.3.2&nbsp;&nbsp;<tt>Calendar.callHandler</tt></a><br>
94&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.3"></a><a href="#node_sec_4.3.3">4.3.3&nbsp;&nbsp;<tt>Calendar.callCloseHandler</tt></a><br>
95&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.4"></a><a href="#node_sec_4.3.4">4.3.4&nbsp;&nbsp;<tt>Calendar.hide</tt></a><br>
96&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.5"></a><a href="#node_sec_4.3.5">4.3.5&nbsp;&nbsp;<tt>Calendar.setDateFormat</tt></a><br>
97&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.6"></a><a href="#node_sec_4.3.6">4.3.6&nbsp;&nbsp;<tt>Calendar.setTtDateFormat</tt></a><br>
98&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.7"></a><a href="#node_sec_4.3.7">4.3.7&nbsp;&nbsp;<tt>Calendar.setDisabledHandler</tt></a><br>
99&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.8"></a><a href="#node_sec_4.3.8">4.3.8&nbsp;&nbsp;<tt>Calendar.setDateStatusHandler</tt></a><br>
100&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.9"></a><a href="#node_sec_4.3.9">4.3.9&nbsp;&nbsp;<tt>Calendar.show</tt></a><br>
101&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.10"></a><a href="#node_sec_4.3.10">4.3.10&nbsp;&nbsp;<tt>Calendar.showAt</tt></a><br>
102&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.11"></a><a href="#node_sec_4.3.11">4.3.11&nbsp;&nbsp;<tt>Calendar.showAtElement</tt></a><br>
103&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.12"></a><a href="#node_sec_4.3.12">4.3.12&nbsp;&nbsp;<tt>Calendar.setDate</tt></a><br>
104&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.13"></a><a href="#node_sec_4.3.13">4.3.13&nbsp;&nbsp;<tt>Calendar.setFirstDayOfWeek</tt></a><br>
105&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.14"></a><a href="#node_sec_4.3.14">4.3.14&nbsp;&nbsp;<tt>Calendar.parseDate</tt></a><br>
106&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a name="node_toc_node_sec_4.3.15"></a><a href="#node_sec_4.3.15">4.3.15&nbsp;&nbsp;<tt>Calendar.setRange</tt></a><br>
107</p>
108<p><b>
109&nbsp; &nbsp; <a name="node_toc_node_sec_5"></a><a href="#node_sec_5">5&nbsp;&nbsp;Side effects</a></b><br>
110</p>
111<p><b>
112&nbsp; &nbsp; <a name="node_toc_node_sec_6"></a><a href="#node_sec_6">6&nbsp;&nbsp;Credits</a></b><br>
113</p>
114<p>
115</p>
116<p>
117</p>
118<a name="node_sec_1"></a>
119<h1><a href="#node_toc_node_sec_1">1&nbsp;&nbsp;Overview</a></h1><p>The DHTML Calendar widget<a name="call_footnote_Temp_2"></a><a href="#footnote_Temp_2"><sup><small>1</small></sup></a>
120is an (HTML) user interface element that gives end-users a friendly way to
121select date and time.  It works in a web browser.  The first versions only provided
122support for popup calendars, while starting with version 0.9 it also supports
123&#8220;flat&#8221; display.  A &#8220;flat&#8221; calendar is a calendar that stays visible in the
124page all the time.  In this mode it could be very useful for &#8220;blog&#8221; pages and
125other pages that require the calendar to be always present.</p>
126<p>
127The calendar is compatible with most popular browsers nowadays.  While it&#8217;s
128created using web standards and it should generally work with any compliant
129browser, the following browsers were found to work: Mozilla (the
130development platform), Netscape&nbsp;6.0 or better, all other Gecko-based browsers,
131Internet Explorer&nbsp;5.0 or better <em>for Windows</em><a name="call_footnote_Temp_3"></a><a href="#footnote_Temp_3"><sup><small>2</small></sup></a>, Opera&nbsp;7<a name="call_footnote_Temp_4"></a><a href="#footnote_Temp_4"><sup><small>3</small></sup></a> and Konqueror 3.1.2 (with pretty much the
132same dysfunctions as in Opera).</p>
133<p>
134You can find the latest info and version at the calendar homepage:</p>
135<p>
136</p>
137<div align=center><table><tr><td>
138
139<a href="http://dynarch.com/mishoo/calendar.epl"><tt>http://dynarch.com/mishoo/calendar.epl</tt></a>
140</td></tr></table></div>
141<p>
142</p>
143<a name="node_sec_1.1"></a>
144<h2><a href="#node_toc_node_sec_1.1">1.1&nbsp;&nbsp;How does this thing work?</a></h2><p>DHTML is not &#8220;another kind of HTML&#8221;.  It&#8217;s merely a naming convention.  DHTML
145refers to the combination of HTML, CSS, JavaScript and DOM.  DOM (Document
146Object Model) is a set of interfaces that glues the other three together.  In
147other words, DOM allows dynamic modification of an HTML page through a program.
148JavaScript is our programming language, since that&#8217;s what browsers like.  CSS
149is a way to make it look good ;-).  So all this soup is generically known as
150DHTML.</p>
151<p>
152Using DOM calls, the program dynamically creates a <tt>&lt;table&gt;</tt> element
153that contains a calendar for the given date and then inserts it in the document
154body.  Then it shows this table at a specified position.  Usually the position
155is related to some element in which the date needs to be displayed/entered,
156such as an input field.</p>
157<p>
158By assigning a certain CSS class to the table we can control the look of the
159calendar through an external CSS file; therefore, in order to change the
160colors, backgrounds, rollover effects and other stuff, you can only change a
161CSS file&#8212;modification of the program itself is not necessary.</p>
162<p>
163</p>
164<a name="node_sec_1.2"></a>
165<h2><a href="#node_toc_node_sec_1.2">1.2&nbsp;&nbsp;Project files</a></h2><p>Here&#8217;s a description of the project files, excluding documentation and example
166files.</p>
167<p>
168</p>
169<ul><p>
170</p>
171<li><p>the main program file (<tt>calendar.js</tt>).  This defines all the logic
172behind the calendar widget.</p>
173<p>
174</p>
175<li><p>the CSS files (<tt>calendar-*.css</tt>).  Loading one of them is
176necessary in order to see the calendar as intended.</p>
177<p>
178</p>
179<li><p>the language definition files (<tt>lang/calendar-*.js</tt>).  They are
180plain JavaScript files that contain all texts that are displayed by the
181calendar.  Loading one of them is necessary.</p>
182<p>
183</p>
184<li><p>helper functions for quick setup of the calendar
185(<tt>calendar-setup.js</tt>).  You can do fine without it, but starting with
186version 0.9.3 this is the recommended way to setup a calendar.</p>
187<p>
188</p>
189</ul><p></p>
190<p>
191</p>
192<a name="node_sec_1.3"></a>
193<h2><a href="#node_toc_node_sec_1.3">1.3&nbsp;&nbsp;License</a></h2><p></p>
194<div align=center><table><tr><td>
195
196&copy; Mihai Bazon, 2002 &#8211; 2003, <tt>&lt;mishoo@infoiasi.ro&gt;</tt><br>
197<a href="http://dynarch.com/mishoo/"><tt>http://dynarch.com/mishoo/</tt></a>
198</td></tr></table></div>
199<p>
200The calendar is released under the
201<a href="http://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License</a>.  You
202can <a href="http://www.gnu.org/licenses/lgpl.html">read the entire license text
203here</a>.</p>
204<p>
205</p>
206<a name="node_sec_2"></a>
207<h1><a href="#node_toc_node_sec_2">2&nbsp;&nbsp;Quick startup</a></h1><p></p>
208<p>
209Installing the calendar used to be quite a task until version 0.9.3.  Starting
210with 0.9.3 I have included the file <tt>calendar-setup.js</tt> whose goal is to
211assist you to setup a popup or flat calendar in minutes.  You are
212encouraged to modify this file and <em>not</em> calendar.js if you need
213extra customization, but you&#8217;re on your own.</p>
214<p>
215First you have to include the needed scripts and style-sheet.  Make sure you do
216this in your document&#8217;s <tt>&lt;head&gt;</tt> section, also make sure you put the
217correct paths to the scripts.</p>
218<p>
219</p>
220<pre class=verbatim>&lt;style type=&quot;text/css&quot;&gt;@import url(calendar-win2k-1.css);&lt;/style&gt;
221&lt;script type=&quot;text/javascript&quot; src=&quot;calendar.js&quot;&gt;&lt;/script&gt;
222&lt;script type=&quot;text/javascript&quot; src=&quot;lang/calendar-en.js&quot;&gt;&lt;/script&gt;
223&lt;script type=&quot;text/javascript&quot; src=&quot;calendar-setup.js&quot;&gt;&lt;/script&gt;
224</pre><p></p>
225<p>
226</p>
227<a name="node_sec_2.1"></a>
228<h2><a href="#node_toc_node_sec_2.1">2.1&nbsp;&nbsp;Installing a popup calendar</a></h2><p></p>
229<p>
230Now suppose you have the following HTML:</p>
231<p>
232</p>
233<pre class=verbatim>&lt;form ...&gt;
234  &lt;input type=&quot;text&quot; id=&quot;data&quot; name=&quot;data&quot; /&gt;
235  &lt;button id=&quot;trigger&quot;&gt;...&lt;/button&gt;
236&lt;/form&gt;
237</pre><p></p>
238<p>
239You want the button to popup a calendar widget when clicked?  Just
240insert the following code immediately <em>after</em> the HTML form:</p>
241<p>
242</p>
243<pre class=verbatim>&lt;script type=&quot;text/javascript&quot;&gt;
244  Calendar.setup(
245    {
246      inputField  : &quot;data&quot;,         // ID of the input field
247      ifFormat    : &quot;%m %d, %Y&quot;,    // the date format
248      button      : &quot;trigger&quot;       // ID of the button
249    }
250  );
251&lt;/script&gt;
252</pre><p></p>
253<p>
254The <tt>Calendar.setup</tt> function, defined in <tt>calendar-setup.js</tt>
255takes care of &#8220;patching&#8221; the button to display a calendar when clicked.  The
256calendar is by default in single-click mode and linked with the given input
257field, so that when the end-user selects a date it will update the input field
258with the date in the given format and close the calendar.  If you are a
259long-term user of the calendar you probably remember that for doing this you
260needed to write a couple functions and add an &#8220;onclick&#8221; handler for the
261button by hand.</p>
262<p>
263By looking at the example above we can see that the function
264<tt>Calendar.setup</tt> receives only one parameter: a JavaScript object.
265Further, that object can have lots of properties that tell to the setup
266function how would we like to have the calendar.  For instance, if we would
267like a calendar that closes at double-click instead of single-click we would
268also include the following: <tt>singleClick:false</tt>.</p>
269<p>
270For a list of all supported parameters please see the section
271<a href="#node_sec_2.3">2.3</a>.</p>
272<p>
273</p>
274<a name="node_sec_2.2"></a>
275<h2><a href="#node_toc_node_sec_2.2">2.2&nbsp;&nbsp;Installing a flat calendar</a></h2><p></p>
276<p>
277Here&#8217;s how to configure a flat calendar, using the same <tt>Calendar.setup</tt>
278function.  First, you should have an empty element with an ID.  This element
279will act as a container for the calendar.  It can be any block-level element,
280such as DIV, TABLE, etc.  We will use a DIV in this example.</p>
281<p>
282</p>
283<pre class=verbatim>&lt;div id=&quot;calendar-container&quot;&gt;&lt;/div&gt;
284</pre><p></p>
285<p>
286Then there is the JavaScript code that sets up the calendar into the
287&#8220;calendar-container&#8221; DIV.  The code can occur anywhere in HTML
288<em>after</em> the DIV element.</p>
289<p>
290</p>
291<pre class=verbatim>&lt;script type=&quot;text/javascript&quot;&gt;
292  function dateChanged(calendar) {
293    // Beware that this function is called even if the end-user only
294    // changed the month/year.  In order to determine if a date was
295    // clicked you can use the dateClicked property of the calendar:
296    if (calendar.dateClicked) {
297      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
298      var y = calendar.date.getFullYear();
299      var m = calendar.date.getMonth();     // integer, 0..11
300      var d = calendar.date.getDate();      // integer, 1..31
301      // redirect...
302      window.location = &quot;/&quot; + y + &quot;/&quot; + m + &quot;/&quot; + d + &quot;/index.php&quot;;
303    }
304  };
305
306  Calendar.setup(
307    {
308      flat         : &quot;calendar-container&quot;, // ID of the parent element
309      flatCallback : dateChanged           // our callback function
310    }
311  );
312&lt;/script&gt;
313</pre><p></p>
314<p>
315</p>
316<a name="node_sec_2.3"></a>
317<h2><a href="#node_toc_node_sec_2.3">2.3&nbsp;&nbsp;<tt>Calendar.setup</tt> in detail</a></h2><p></p>
318<p>
319Following there is the complete list of properties interpreted by
320Calendar.setup.  All of them have default values, so you can pass only those
321which you would like to customize.  Anyway, you <em>must</em> pass at least one
322of <tt>inputField</tt>, <tt>displayArea</tt> or <tt>button</tt>, for a popup
323calendar, or <tt>flat</tt> for a flat calendar.  Otherwise you will get a
324warning message saying that there&#8217;s nothing to setup.</p>
325<p>
326</p>
327<span class=small><table border=0><tr><td valign=top ><b>property</b> </td><td valign=top ><b>type</b> </td><td valign=top ><b>description</b> </td><td valign=top ><b>default</b>
328</td></tr>
329<tr><td valign=top ><tt>inputField</tt>
330</td><td valign=top >string </td><td valign=top >The ID of your input field.
331</td><td valign=top >null
332</td></tr>
333<tr><td valign=top ><tt>displayArea</tt>
334</td><td valign=top >string </td><td valign=top >This is the ID of a &lt;span&gt;, &lt;div&gt;, or any other element that you would like to use to display the current date. This is generally useful only if the input field is hidden, as an area to display the date.
335</td><td valign=top >null
336</td></tr>
337<tr><td valign=top ><tt>button</tt>
338</td><td valign=top >string </td><td valign=top >The ID of the calendar &#8220;trigger&#8221;. This is an element (ordinarily a button or an image) that will dispatch a certain event (usually &#8220;click&#8221;) to the function that creates and displays the calendar.
339</td><td valign=top >null
340</td></tr>
341<tr><td valign=top ><tt>eventName</tt>
342</td><td valign=top >string </td><td valign=top >The name of the event that will trigger the calendar. The name should be without the &#8220;on&#8221; prefix, such as &#8220;click&#8221; instead of &#8220;onclick&#8221;. Virtually all users will want to let this have the default value (&#8220;click&#8221;). Anyway, it could be useful if, say, you want the calendar to appear when the input field is focused and have no trigger button (in this case use &#8220;focus&#8221; as the event name).
343</td><td valign=top >&#8220;click&#8221;
344</td></tr>
345<tr><td valign=top ><tt>ifFormat</tt>
346</td><td valign=top >string </td><td valign=top >The format string that will be used to enter the date in the input field. This format will be honored even if the input field is hidden.
347</td><td valign=top >&#8220;%Y/%m/%d&#8221;
348</td></tr>
349<tr><td valign=top ><tt>daFormat</tt>
350</td><td valign=top >string </td><td valign=top >Format of the date displayed in the displayArea (if specified).
351</td><td valign=top >&#8220;%Y/%m/%d&#8221;
352</td></tr>
353<tr><td valign=top ><tt>singleClick</tt>
354</td><td valign=top >boolean </td><td valign=top >Wether the calendar is in &#8220;single-click mode&#8221; or &#8220;double-click mode&#8221;. If true (the default) the calendar will be created in single-click mode.
355</td><td valign=top >true
356</td></tr>
357<tr><td valign=top ><tt>disableFunc</tt>
358</td><td valign=top >function </td><td valign=top >A function that receives a JS Date object.  It should return
359<tt>true</tt> if that date has to be disabled, <tt>false</tt> otherwise.
360<font color="red">DEPRECATED (see below).</font>
361</td><td valign=top >null
362</td></tr>
363<tr><td valign=top ><tt>dateStatusFunc</tt>
364</td><td valign=top >function </td><td valign=top >A function that receives a JS Date object and returns a boolean
365or a string.  This function allows one to set a certain CSS class to some
366date, therefore making it look different.  If it returns <tt>true</tt> then
367the date will be disabled.  If it returns <tt>false</tt> nothing special
368happens with the given date.  If it returns a string then that will be taken
369as a CSS class and appended to the date element.  If this string is
370&#8220;disabled&#8221; then the date is also disabled (therefore is like returning
371<tt>true</tt>).  For more information please also refer to section
372<a href="#node_sec_4.3.8">4.3.8</a>.
373</td><td valign=top >null
374</td></tr>
375<tr><td valign=top ><tt>firstDay</tt>
376</td><td valign=top >integer </td><td valign=top >Specifies which day is to be displayed as the first day of
377week.  Possible values are 0 to 6; 0 means Sunday, 1 means Monday, ..., 6
378means Saturday.  The end user can easily change this too, by clicking on the
379day name in the calendar header.
380</td><td valign=top >0
381</td></tr>
382<tr><td valign=top ><tt>weekNumbers</tt>
383</td><td valign=top >boolean </td><td valign=top >If &#8220;true&#8221; then the calendar will display week numbers.
384</td><td valign=top >true
385</td></tr>
386<tr><td valign=top ><tt>align</tt>
387</td><td valign=top >string </td><td valign=top >Alignment of the calendar, relative to the reference element. The
388reference element is dynamically chosen like this: if a displayArea is
389specified then it will be the reference element. Otherwise, the input field
390is the reference element.  For the meaning of the alignment characters
391please section <a href="#node_sec_4.3.11">4.3.11</a>.
392</td><td valign=top >&#8220;Bl&#8221;
393</td></tr>
394<tr><td valign=top ><tt>range</tt>
395</td><td valign=top >array </td><td valign=top >An array having exactly 2 elements, integers. (!) The first [0] element is the minimum year that is available, and the second [1] element is the maximum year that the calendar will allow.
396</td><td valign=top >[1900, 2999]
397</td></tr>
398<tr><td valign=top ><tt>flat</tt>
399</td><td valign=top >string </td><td valign=top >If you want a flat calendar, pass the ID of the parent object in
400this property.  If not, pass <tt>null</tt> here (or nothing at all as
401<tt>null</tt> is the default value).
402</td><td valign=top >null
403</td></tr>
404<tr><td valign=top ><tt>flatCallback</tt>
405</td><td valign=top >function </td><td valign=top >You should provide this function if the calendar is flat.  It
406will be called when the date in the calendar is changed with a reference to
407the calendar object.  See section <a href="#node_sec_2.2">2.2</a> for an example
408of how to setup a flat calendar.
409</td><td valign=top >null
410</td></tr>
411<tr><td valign=top ><tt>onSelect</tt>
412</td><td valign=top >function </td><td valign=top >If you provide a function handler here then you have to manage
413the &#8220;click-on-date&#8221; event by yourself.  Look in the calendar-setup.js and
414take as an example the onSelect handler that you can see there.
415</td><td valign=top >null
416</td></tr>
417<tr><td valign=top ><tt>onClose</tt>
418</td><td valign=top >function </td><td valign=top >This handler will be called when the calendar needs to close.
419You don&#8217;t need to provide one, but if you do it&#8217;s your responsibility to
420hide/destroy the calendar.  You&#8217;re on your own.  Check the calendar-setup.js
421file for an example.
422</td><td valign=top >null
423</td></tr>
424<tr><td valign=top ><tt>onUpdate</tt>
425</td><td valign=top >function </td><td valign=top >If you supply a function handler here, it will be called right
426after the target field is updated with a new date.  You can use this to
427chain 2 calendars, for instance to setup a default date in the second just
428after a date was selected in the first.
429</td><td valign=top >null
430</td></tr>
431<tr><td valign=top ><tt>date</tt>
432</td><td valign=top >date </td><td valign=top >This allows you to setup an initial date where the calendar will be
433positioned to.  If absent then the calendar will open to the today date.
434</td><td valign=top >null
435</td></tr>
436<tr><td valign=top ><tt>showsTime</tt>
437</td><td valign=top >boolean </td><td valign=top >If this is set to <tt>true</tt> then the calendar will also
438allow time selection.
439</td><td valign=top >false
440</td></tr>
441<tr><td valign=top ><tt>timeFormat</tt>
442</td><td valign=top >string </td><td valign=top >Set this to &#8220;12&#8221; or &#8220;24&#8221; to configure the way that the
443calendar will display time.
444</td><td valign=top >&#8220;24&#8221;
445</td></tr>
446<tr><td valign=top ><tt>electric</tt>
447</td><td valign=top >boolean </td><td valign=top >Set this to &#8220;false&#8221; if you want the calendar to update the
448field only when closed (by default it updates the field at each date change,
449even if the calendar is not closed) </td><td valign=top >true
450</td></tr>
451<tr><td valign=top ><tt>position</tt>
452</td><td valign=top >array </td><td valign=top >Specifies the [x, y] position, relative to page&#8217;s top-left corner,
453where the calendar will be displayed.  If not passed then the position will
454be computed based on the &#8220;align&#8221; parameter.  Defaults to &#8220;null&#8221; (not
455used). </td><td valign=top >null
456</td></tr>
457<tr><td valign=top ><tt>cache</tt>
458</td><td valign=top >boolean </td><td valign=top >Set this to &#8220;true&#8221; if you want to cache the calendar object.
459This means that a single calendar object will be used for all fields that
460require a popup calendar </td><td valign=top >false
461</td></tr>
462<tr><td valign=top ><tt>showOthers</tt>
463</td><td valign=top >boolean </td><td valign=top >If set to &#8220;true&#8221; then days belonging to months overlapping
464with the currently displayed month will also be displayed in the calendar
465(but in a &#8220;faded-out&#8221; color) </td><td valign=top >false
466
467</td></tr></table>
468
469</span><p>
470</p>
471<a name="node_sec_3"></a>
472<h1><a href="#node_toc_node_sec_3">3&nbsp;&nbsp;The Calendar object overview</a></h1><p></p>
473<p>
474Basically you should be able to setup the calendar with the function presented
475in the previous section.  However, if for some reason <tt>Calendar.setup</tt>
476doesn&#8217;t provide all the functionality that you need and you want to tweak into
477the process of creating and configuring the calendar &#8220;by hand&#8221;, then this
478section is the way to go.</p>
479<p>
480The file <tt>calendar.js</tt> implements the functionality of the calendar.
481All (well, almost all) functions and variables are embedded in the JavaScript
482object &#8220;Calendar&#8221;.</p>
483<p>
484You can instantiate a <tt>Calendar</tt> object by calling the constructor, like
485this: <tt>var cal = new Calendar(<tt>...</tt>)</tt>.  We will discuss the parameters
486later.  After creating the object, the variable <tt>cal</tt> will contain a
487reference to it.  You can use this reference to access further options of the
488calendar, for instance:</p>
489<p>
490</p>
491<pre class=verbatim>cal.weekNumbers = false; // do not display week numbers
492cal.showsTime = true;    // include a time selector
493cal.setDateFormat(&quot;%Y.%m.%d %H:%M&quot;); // set this format: 2003.12.31 23:59
494cal.setDisabledHandler(function(date, year, month, day) {
495  // verify date and return true if it has to be disabled
496  // ``date'' is a JS Date object, but if you only need the
497  // year, month and/or day you can get them separately as
498  // next 3 parameters, as you can see in the declaration
499  if (year == 2004) {
500    // disable all dates from 2004
501    return true;
502  }
503  return false;
504});
505</pre><p></p>
506<p>
507etc.  Prior to version
5080.9.3 this was the only way to configure it.  The <tt>Calendar.setup</tt>
509function, documented in section <a href="#node_sec_2">2</a>, basically does the same
510things (actually more) in order to setup the calendar, based on the parameters
511that you provided.</p>
512<p>
513</p>
514<a name="node_sec_3.1"></a>
515<h2><a href="#node_toc_node_sec_3.1">3.1&nbsp;&nbsp;Creating a calendar</a></h2><p>The calendar is created by following some steps (even the function
516<tt>Calendar.setup</tt>, described in section <a href="#node_sec_2">2</a>, does the
517same).  While you can skip optional (marked &#8220;opt&#8221;) steps if you&#8217;re happy with
518the defaults, please respect the order below.</p>
519<p>
520</p>
521<ol><p>
522</p>
523<li><p><em>Instantiate</em> a <tt>Calendar</tt> object.  Details about this in
524section <a href="#node_sec_4.1">4.1</a>.</p>
525<p>
526</p>
527<li><p><b>opt</b>&nbsp;&nbsp; Set the <tt>weekNumbers</tt> property to <tt>false</tt> if you don&#8217;t want
528the calendar to display week numbers.</p>
529<p>
530</p>
531<li><p><b>opt</b>&nbsp;&nbsp; Set the <tt>showsTime</tt> property to <tt>true</tt> if you
532want the calendar to also provide a time selector.</p>
533<p>
534</p>
535<li><p><b>opt</b>&nbsp;&nbsp; Set the <tt>time24</tt> property to <tt>false</tt> if you want
536the time selector to be in 12-hour format.  Default is 24-hour format.  This
537property only has effect if you also set <tt>showsTime</tt> to
538<tt>true</tt>.</p>
539<p>
540</p>
541<li><p><b>opt</b>&nbsp;&nbsp; Set the range of years available for selection (see section
542<a href="#node_sec_4.3.15">4.3.15</a>).  The default range is [1970..2050].</p>
543<p>
544</p>
545<li><p><b>opt</b>&nbsp;&nbsp; Set the <tt>getDateStatus</tt> property.  You should pass
546here a function that receives a JavaScript <tt>Date</tt> object and returns
547<tt>true</tt> if the given date should be disabled, false otherwise (details in
548section <a href="#node_sec_4.3.7">4.3.7</a>).</p>
549<p>
550</p>
551<li><p><b>opt</b>&nbsp;&nbsp; Set a date format.  Your handler function, passed to the
552calendar constructor, will be called when a date is selected with a reference
553to the calendar and a date string in this format.</p>
554<p>
555</p>
556<li><p><em>Create</em> the HTML elements related to the calendar.  This step
557practically puts the calendar in your HTML page.  You simply call
558<tt>Calendar.create()</tt>.  You can give an optional parameter if you wanna
559create a flat calendar (details in section <a href="#node_sec_4.3.1">4.3.1</a>).</p>
560<p>
561</p>
562<li><p><b>opt</b>&nbsp;&nbsp; Initialize the calendar to a certain date, for instance from
563the input field.</p>
564<p>
565</p>
566<li><p>Show the calendar (details in section <a href="#node_sec_4.3.9">4.3.9</a>).</p>
567<p>
568</p>
569</ol><p></p>
570<p>
571</p>
572<a name="node_sec_3.2"></a>
573<h2><a href="#node_toc_node_sec_3.2">3.2&nbsp;&nbsp;Order does matter ;-)</a></h2><p>As you could see in the previous section, there are more steps to be followed
574in order to setup the calendar.  This happens because there are two different
575things that need to be accomplished: first there is the JavaScript object, that
576is created with <tt>new Calendar(<tt>...</tt>)</tt>.  Secondly there are the HTML
577elements that actually lets you see and manipulate the calendar.</p>
578<p>
579</p>
580<span class=small>[ Those that did UI<a name="call_footnote_Temp_5"></a><a href="#footnote_Temp_5"><sup><small>4</small></sup></a> programming, no matter in what
581language and on what platform, may be familiar with this concept.  First there
582is the object in memory that lets you manipulate the UI element, and secondly
583there is the UI element (known as &#8220;control&#8221;, &#8220;window&#8221;, &#8220;widget&#8221;, etc.),
584also in memory but you don&#8217;t usually access it directly. ]
585</span><p>
586By instantiating the calendar we create the JavaScript object.  It lets us
587configure some properties and it also knows how to create the UI element (the
588HTML elements actually) that will eventually be what the end-user sees on
589screen.  Creation of the HTML element is accomplished by the function
590<tt>Calendar.create</tt>.  It knows how to create popup or flat calendars.
591This function is described in section <a href="#node_sec_4.3.1">4.3.1</a>.</p>
592<p>
593Some properties need to be set prior to creating the HTML elements, because
594otherwise they wouldn&#8217;t have any effect.  Such a property is
595<tt>weekNumbers</tt>&#8212;it has the default value &#8220;true&#8221;, and if you don&#8217;t
596want the calendar to display the week numbers you have to set it to false.  If,
597however, you do that <em>after</em> calling <tt>Calendar.create</tt> the calendar
598would still display the week numbers, because the HTML elements are already
599created (including the <tt>&lt;td&gt;</tt>-s in the <tt>&lt;table&gt;</tt> element that
600should contain the week numbers).  For this reason the order of the steps above
601is important.</p>
602<p>
603Another example is when you want to show the calendar.  The &#8220;create&#8221; function
604does create the HTML elements, but they are initially hidden (have the style
605&#8220;display: none&#8221;) unless the calendar is a flat calendar that should be always
606visible in the page.  Obviously, the <tt>Calendar.show</tt> function should be
607called <em>after</em> calling <tt>Calendar.create</tt>.</p>
608<p>
609</p>
610<a name="node_sec_3.3"></a>
611<h2><a href="#node_toc_node_sec_3.3">3.3&nbsp;&nbsp;Caching the object</a></h2><p>Suppose the end-user has popped up a calendar and selects a date.  The calendar
612then closes.  What really happens now?</p>
613<p>
614There are two approaches.  The first (used in very old versions of the
615calendar) was to drop completely the Calendar object and when the end-user pops
616up the calendar again to create another one.  This approach is bad for more
617reasons:</p>
618<p>
619</p>
620<ul><p>
621</p>
622<li><p>creating the JavaScript object and HTML elements is time-consuming</p>
623<p>
624</p>
625<li><p>we may loose some end-user preferences (i.e. he might prefer to have
626Monday for the first day of week and probably already clicked it the first time
627when the calendar was opened, but now he has to do it again)</p>
628<p>
629</p>
630</ul><p></p>
631<p>
632The second approach, implemented by the <tt>Calendar.setup</tt> function, is to
633cache the JavaScript object.  It does this by checking the global variable
634<tt>window.calendar</tt> and if it is not null it assumes it is the created
635Calendar object.  When the end-user closes the calendar, our code will only
636call &#8220;<tt>hide</tt>&#8221; on it, therefore keeping the JavaScript object and the
637HTML elements in place.</p>
638<p>
639<font color="red">CAVEAT:</font> &nbsp;&nbsp;&nbsp;&nbsp;Since time selection support was introduced, this
640&#8220;object caching&#8221; mechanism has the following drawback: if you once created
641the calendar with the time selection support, then other items that may not
642require this functionality will still get a calendar with the time selection
643support enabled.  And reciprocal. ;-)  Hopefully this will be corrected in a
644later version, but for now it doesn&#8217;t seem such a big problem.</p>
645<p>
646</p>
647<a name="node_sec_3.4"></a>
648<h2><a href="#node_toc_node_sec_3.4">3.4&nbsp;&nbsp;Callback functions</a></h2><p>You might rightfully wonder how is the calendar related to the input field?
649Who tells it that it has to update <em>that</em> input field when a date is
650selected, or that it has to jump to <em>that</em> URL when a date is clicked in
651flat mode?</p>
652<p>
653All this magic is done through callback functions.  The calendar doesn&#8217;t know
654anything about the existence of an input field, nor does it know where to
655redirect the browser when a date is clicked in flat mode.  It just calls your
656callback when a particular event is happening, and you&#8217;re responsible to handle
657it from there.  For a general purpose library I think this is the best model of
658making a truly reusable thing.</p>
659<p>
660The calendar supports the following user callbacks:</p>
661<p>
662</p>
663<ul><p>
664</p>
665<li><p><b>onSelect</b>&nbsp;&nbsp; &#8212; this gets called when the end-user changes the date in the
666calendar.  Documented in section <a href="#node_sec_4.1">4.1</a>.</p>
667<p>
668</p>
669<li><p><b>onClose</b>&nbsp;&nbsp; &#8212; this gets called when the calendar should close.  It&#8217;s
670user&#8217;s responsibility to close the calendar.  Details in section
671<a href="#node_sec_4.1">4.1</a>.</p>
672<p>
673</p>
674<li><p><b>getDateStatus</b>&nbsp;&nbsp; &#8212; this function gets called for any day in a month,
675just before displaying the month.  It is called with a JavaScript <tt>Date</tt>
676object and should return <tt>true</tt> if that date should be disabled, false
677if it&#8217;s an ordinary date and no action should be taken, or it can return a
678string in which case the returned value will be appended to the element&#8217;s CSS
679class (this way it provides a powerful way to make some dates &#8220;special&#8221;,
680i.e. highlight them differently).  Details in section
681<a href="#node_sec_4.3.8">4.3.8</a>.</p>
682<p>
683</p>
684</ul><p></p>
685<p>
686</p>
687<a name="node_sec_4"></a>
688<h1><a href="#node_toc_node_sec_4">4&nbsp;&nbsp;The Calendar object API reference</a></h1><p></p>
689<p>
690</p>
691<a name="node_sec_4.1"></a>
692<h2><a href="#node_toc_node_sec_4.1">4.1&nbsp;&nbsp;<tt>Calendar</tt> constructor</a></h2><p></p>
693<p>
694Synopsis:</p>
695<p>
696</p>
697<pre class=verbatim>var calendar = Calendar(firstDayOfWeek, date, onSelect, onClose);
698</pre><p></p>
699<p>
700Parameters are as follows:</p>
701<p>
702</p>
703<ul><p>
704</p>
705<li><p><b>firstDayOfWeek</b>&nbsp;&nbsp; &#8212; specifies which day is to be displayed as the first
706day of week.  Possible values are 0 to 6; 0 means Sunday, 1 means Monday,
707..., 6 means Saturday.</p>
708<p>
709</p>
710<li><p><b>date</b>&nbsp;&nbsp; &#8212; a JavaScript Date object or <tt>null</tt>.  If <tt>null</tt>
711is passed then the calendar will default to today date.  Otherwise it will
712initialize on the given date.</p>
713<p>
714</p>
715<li><p><b>onSelect</b>&nbsp;&nbsp; &#8212; your callback for the &#8220;onChange&#8221; event.  See above.</p>
716<p>
717</p>
718<li><p><b>onClose</b>&nbsp;&nbsp; &#8212; your callback for the &#8220;onClose&#8221; event.  See above.</p>
719<p>
720</p>
721</ul><p></p>
722<p>
723</p>
724<a name="node_sec_Temp_6"></a>
725<h3><a href="#node_toc_node_sec_Temp_6">The <tt>onSelect</tt> event</a></h3><p></p>
726<p>
727Here is a typical implementation of this function:</p>
728<p>
729</p>
730<pre class=verbatim>function onSelect(calendar, date) {
731  var input_field = document.getElementById(&quot;date&quot;);
732  input_field.value = date;
733};
734</pre><p></p>
735<p>
736<tt>date</tt> is in the format selected with <tt>calendar.setDateFormat</tt>
737(see section <a href="#node_sec_4.3.5">4.3.5</a>).  This code simply updates the
738input field.  If you want the calendar to be in single-click mode then you
739should also close the calendar after you updated the input field, so we come to
740the following version:</p>
741<p>
742</p>
743<pre class=verbatim>function onSelect(calendar, date) {
744  var input_field = document.getElementById(&quot;date&quot;);
745  input_field.value = date;
746  if (calendar.dateClicked) {
747    calendar.callCloseHandler(); // this calls &quot;onClose&quot; (see above)
748  }
749};
750</pre><p></p>
751<p>
752Note that we checked the member variable <tt>dateClicked</tt> and
753only hide the calendar if it&#8217;s <tt>true</tt>.  If this variable is <tt>false</tt> it
754means that no date was actually selected, but the user only changed the
755month/year using the navigation buttons or the menus.  We don&#8217;t want to hide
756the calendar in that case.</p>
757<p>
758</p>
759<a name="node_sec_Temp_7"></a>
760<h3><a href="#node_toc_node_sec_Temp_7">The <tt>onClose</tt> event</a></h3><p></p>
761<p>
762This event is triggered when the calendar should close.  It should hide or
763destroy the calendar object&#8212;the calendar itself just triggers the event, but
764it won&#8217;t close itself.</p>
765<p>
766A typical implementation of this function is the following:</p>
767<p>
768</p>
769<pre class=verbatim>function onClose(calendar) {
770  calendar.hide();
771  // or calendar.destroy();
772};
773</pre><p></p>
774<p>
775</p>
776<a name="node_sec_4.2"></a>
777<h2><a href="#node_toc_node_sec_4.2">4.2&nbsp;&nbsp;Useful member variables (properties)</a></h2><p></p>
778<p>
779After creating the Calendar object you can access the following properties:</p>
780<p>
781</p>
782<ul><p>
783</p>
784<li><p><tt>date</tt> &#8212; is a JavaScript <tt>Date</tt> object.  It will always
785reflect the date shown in the calendar (yes, even if the calendar is hidden).</p>
786<p>
787</p>
788<li><p><tt>isPopup</tt> &#8212; if this is true then the current Calendar object is
789a popup calendar.  Otherwise (false) we have a flat calendar.  This variable is
790set from <tt>Calendar.create</tt> and has no meaning before this function was
791called.</p>
792<p>
793</p>
794<li><p><tt>dateClicked</tt> &#8212; particularly useful in the <tt>onSelect</tt>
795handler, this variable tells us if a date was really clicked.  That&#8217;s because
796the <tt>onSelect</tt> handler is called even if the end-user only changed the
797month/year but did not select a date.  We don&#8217;t want to close the calendar in
798that case.</p>
799<p>
800</p>
801<li><p><tt>weekNumbers</tt> &#8212; if <tt>true</tt> (default) then the calendar
802displays week numbers.  If you don&#8217;t want week numbers you have to set this
803variable to <tt>false</tt> <em>before</em> calling <tt>Calendar.create</tt>.</p>
804<p>
805</p>
806<li><p><tt>showsTime</tt> &#8211; if you set this to <tt>true</tt> (it is
807<tt>false</tt> by default) then the calendar will also include a time selector.</p>
808<p>
809</p>
810<li><p><tt>time24</tt> &#8211; if you set this to <tt>false</tt> then the time
811selector will be in 12-hour format.  It is in 24-hour format by default.</p>
812<p>
813</p>
814<li><p><tt>firstDayOfWeek</tt> &#8212; specifies the first day of week (0 to 6, pass
8150 for Sunday, 1 for Monday, ..., 6 for Saturday).  This variable is set from
816constructor, but you still have a chance to modify it <em>before</em> calling
817<tt>Calendar.create</tt>.</p>
818<p>
819</p>
820</ul><p></p>
821<p>
822There are lots of other member variables, but one should access them only
823through member functions so I won&#8217;t document them here.</p>
824<p>
825</p>
826<a name="node_sec_4.3"></a>
827<h2><a href="#node_toc_node_sec_4.3">4.3&nbsp;&nbsp;Public methods</a></h2><p></p>
828<a name="node_sec_4.3.1"></a>
829<h3><a href="#node_toc_node_sec_4.3.1">4.3.1&nbsp;&nbsp;<tt>Calendar.create</tt></a></h3><p></p>
830<p>
831This function creates the afferent HTML elements that are needed to display the
832calendar.  You should call it after setting the calendar properties.  Synopsis:
833</p>
834<pre class=verbatim>calendar.create(); // creates a popup calendar
835  // -- or --
836calendar.create(document.getElementById(parent_id)); // makes a flat calendar
837</pre><p></p>
838<p>
839It can create a popup calendar or a flat calendar.  If the &#8220;parent&#8221; argument
840is present (it should be a <em>reference</em>&#8212;not ID&#8212;to an HTML element) then
841a flat calendar is created and it is inserted in the given element.</p>
842<p>
843At any moment, given a reference to a calendar object, we can inspect if it&#8217;s a
844popup or a flat calendar by checking the boolean member variable
845<tt>isPopup</tt>:</p>
846<p>
847</p>
848<pre class=verbatim>if (calendar.isPopup) {
849   // this is a popup calendar
850} else {
851   // this is a flat calendar
852}
853</pre><p></p>
854<p>
855</p>
856<a name="node_sec_4.3.2"></a>
857<h3><a href="#node_toc_node_sec_4.3.2">4.3.2&nbsp;&nbsp;<tt>Calendar.callHandler</tt></a></h3><p></p>
858<p>
859This function calls the first user callback (the
860<tt>onSelect</tt> handler) with the required parameters.</p>
861<p>
862</p>
863<a name="node_sec_4.3.3"></a>
864<h3><a href="#node_toc_node_sec_4.3.3">4.3.3&nbsp;&nbsp;<tt>Calendar.callCloseHandler</tt></a></h3><p></p>
865<p>
866This function calls the second user callback (the
867<tt>onClose</tt> handler).  It&#8217;s useful when you want to have a
868&#8220;single-click&#8221; calendar&#8212;just call this in your <tt>onSelect</tt> handler,
869if a date was clicked.</p>
870<p>
871</p>
872<a name="node_sec_4.3.4"></a>
873<h3><a href="#node_toc_node_sec_4.3.4">4.3.4&nbsp;&nbsp;<tt>Calendar.hide</tt></a></h3><p></p>
874<p>
875Call this function to hide the calendar.  The calendar object and HTML elements
876will not be destroyed, thus you can later call one of the <tt>show</tt>
877functions on the same element.</p>
878<p>
879</p>
880<a name="node_sec_4.3.5"></a>
881<h3><a href="#node_toc_node_sec_4.3.5">4.3.5&nbsp;&nbsp;<tt>Calendar.setDateFormat</tt></a></h3><p></p>
882<p>
883This function configures the format in which the calendar reports the date to
884your &#8220;onSelect&#8221; handler.  Call it like this:</p>
885<p>
886</p>
887<pre class=verbatim>calendar.setDateFormat(&quot;%y/%m/%d&quot;);
888</pre><p></p>
889<p>
890As you can see, it receives only one parameter, the required format.  The magic
891characters are the following:</p>
892<p>
893</p>
894<table border=0><tr><td valign=top ></td></tr>
895<tr><td valign=top ><tt>%a</tt> </td><td valign=top >abbreviated weekday name </td></tr>
896<tr><td valign=top ><tt>%A</tt> </td><td valign=top >full weekday name </td></tr>
897<tr><td valign=top ><tt>%b</tt> </td><td valign=top >abbreviated month name </td></tr>
898<tr><td valign=top ><tt>%B</tt> </td><td valign=top >full month name </td></tr>
899<tr><td valign=top ><tt>%C</tt> </td><td valign=top >century number </td></tr>
900<tr><td valign=top ><tt>%d</tt> </td><td valign=top >the day of the month ( 00 .. 31 ) </td></tr>
901<tr><td valign=top ><tt>%e</tt> </td><td valign=top >the day of the month ( 0 .. 31 ) </td></tr>
902<tr><td valign=top ><tt>%H</tt> </td><td valign=top >hour ( 00 .. 23 ) </td></tr>
903<tr><td valign=top ><tt>%I</tt> </td><td valign=top >hour ( 01 .. 12 ) </td></tr>
904<tr><td valign=top ><tt>%j</tt> </td><td valign=top >day of the year ( 000 .. 366 ) </td></tr>
905<tr><td valign=top ><tt>%k</tt> </td><td valign=top >hour ( 0 .. 23 ) </td></tr>
906<tr><td valign=top ><tt>%l</tt> </td><td valign=top >hour ( 1 .. 12 ) </td></tr>
907<tr><td valign=top ><tt>%m</tt> </td><td valign=top >month ( 01 .. 12 ) </td></tr>
908<tr><td valign=top ><tt>%M</tt> </td><td valign=top >minute ( 00 .. 59 ) </td></tr>
909<tr><td valign=top ><tt>%n</tt> </td><td valign=top >a newline character </td></tr>
910<tr><td valign=top ><tt>%p</tt> </td><td valign=top >&#8220;PM&#8221; or &#8220;AM&#8221; </td></tr>
911<tr><td valign=top ><tt>%P</tt> </td><td valign=top >&#8220;pm&#8221; or &#8220;am&#8221; </td></tr>
912<tr><td valign=top ><tt>%S</tt> </td><td valign=top >second ( 00 .. 59 ) </td></tr>
913<tr><td valign=top ><tt>%s</tt> </td><td valign=top >number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC) </td></tr>
914<tr><td valign=top ><tt>%t</tt> </td><td valign=top >a tab character </td></tr>
915<tr><td valign=top ><tt>%U, %W, %V</tt> </td><td valign=top >the week number</td></tr>
916<tr><td valign=top ><tt>%u</tt> </td><td valign=top >the day of the week ( 1 .. 7, 1 = MON )</td></tr>
917<tr><td valign=top ><tt>%w</tt> </td><td valign=top >the day of the week ( 0 .. 6, 0 = SUN )</td></tr>
918<tr><td valign=top ><tt>%y</tt> </td><td valign=top >year without the century ( 00 .. 99 )</td></tr>
919<tr><td valign=top ><tt>%Y</tt> </td><td valign=top >year including the century ( ex. 1979 )</td></tr>
920<tr><td valign=top ><tt>%%</tt> </td><td valign=top >a literal <tt>%</tt> character
921</td></tr></table><p>
922There are more algorithms for computing the week number.  All
923three specifiers currently implement the same one, as defined by ISO 8601:
924&#8220;the week 01 is the week that has the Thursday in the current year, which is
925equivalent to the week that contains the fourth day of January.  Weeks start on
926Monday.&#8221;</p>
927<p>
928</p>
929<a name="node_sec_4.3.6"></a>
930<h3><a href="#node_toc_node_sec_4.3.6">4.3.6&nbsp;&nbsp;<tt>Calendar.setTtDateFormat</tt></a></h3><p></p>
931<p>
932Has the same prototype as <tt>Calendar.setDateFormat</tt>, but refers to the
933format of the date displayed in the &#8220;status bar&#8221; when the mouse is over some
934date.</p>
935<p>
936</p>
937<a name="node_sec_4.3.7"></a>
938<h3><a href="#node_toc_node_sec_4.3.7">4.3.7&nbsp;&nbsp;<tt>Calendar.setDisabledHandler</tt></a></h3><p></p>
939<p>
940This function allows you to specify a callback function that checks if a
941certain date must be disabled by the calendar.  You are responsible to write
942the callback function.  Synopsis:</p>
943<p>
944</p>
945<pre class=verbatim>function disallowDate(date) {
946  // date is a JS Date object
947  if (  date.getFullYear() == 2003 &amp;&amp;
948        date.getMonth()    == 6 /* July, it's zero-based */ &amp;&amp;
949        date.getDate()     == 5  ) {
950    return true; // disable July 5 2003
951  }
952  return false; // enable other dates
953};
954
955calendar.setDisabledHandler(disallowDate);
956</pre><p></p>
957<p>
958If you change this function in &#8220;real-time&#8221;, meaning, without creating a new
959calendar, then you have to call <tt>calendar.refresh()</tt> to make it
960redisplay the month and take into account the new disabledHandler.
961<tt>Calendar.setup</tt> does this, so you have no such trouble with it.</p>
962<p>
963Note that <tt>disallowDate</tt> should be very fast, as it is called for each
964date in the month.  Thus, it gets called, say, 30 times before displaying the
965calendar, and 30 times when the month is changed.  Tests I&#8217;ve done so far show
966that it&#8217;s still good, but in the future I might switch it to a different design
967(for instance, to call it once per month and to return an array of dates that
968must be disabled).</p>
969<p>
970This function should be considered deprecated in the favor of
971<tt>Calendar.setDateStatusHandler</tt>, described below.</p>
972<p>
973</p>
974<a name="node_sec_4.3.8"></a>
975<h3><a href="#node_toc_node_sec_4.3.8">4.3.8&nbsp;&nbsp;<tt>Calendar.setDateStatusHandler</tt></a></h3><p></p>
976<p>
977This function obsoletes <tt>Calendar.setDisabledHandler</tt>.  You call it with
978a function parameter, but this function can return a boolean
979<em>or a string</em>. If the return value is a boolean (<tt>true</tt> or
980<tt>false</tt>) then it behaves just like <tt>setDisabledHandler</tt>,
981therefore disabling the date if the return value is <tt>true</tt>.</p>
982<p>
983If the returned value is a string then the given date will gain an additional
984CSS class, namely the returned value.  You can use this to highlight some dates
985in some way.  Note that you are responsible for defining the CSS class that you
986return.  If you return the string &#8220;disabled&#8221; then that date will be disabled,
987just as if you returned <tt>true</tt>.</p>
988<p>
989Here is a simple scenario that shows what you can do with this function.  The
990following should be present in some of your styles, or in the document head in
991a STYLE tag (but put it <em>after</em> the place where the calendar styles were
992loaded):</p>
993<p>
994</p>
995<pre class=verbatim>.special { background-color: #000; color: #fff; }
996</pre><p></p>
997<p>
998And you would use the following code before calling <tt>Calendar.create()</tt>:</p>
999<p>
1000</p>
1001<pre class=verbatim>// this table holds your special days, so that we can automatize
1002// things a bit:
1003var SPECIAL_DAYS = {
1004    0 : [ 13, 24 ],             // special days in January
1005    2 : [ 1, 6, 8, 12, 18 ],    // special days in March
1006    8 : [ 21, 11 ],             // special days in September
1007   11 : [ 25, 28 ]              // special days in December
1008};
1009
1010// this function returns true if the passed date is special
1011function dateIsSpecial(year, month, day) {
1012    var m = SPECIAL_DAYS[month];
1013    if (!m) return false;
1014    for (var i in m) if (m[i] == day) return true;
1015    return false;
1016}
1017
1018// this is the actual date status handler.  Note that it receives the
1019// date object as well as separate values of year, month and date, for
1020// your confort.
1021function dateStatusHandler(date, y, m, d) {
1022    if (dateIsSpecial(y, m, d)) return ``special'';
1023    else return false;
1024    // return true above if you want to disable other dates
1025}
1026
1027// configure it to the calendar
1028calendar.setDateStatusHandler(dateStatusHandler);
1029</pre><p></p>
1030<p>
1031The above code adds the &#8220;special&#8221; class name to some dates that are defined
1032in the SPECIAL_DAYS table.  Other dates will simply be displayed as default,
1033enabled.</p>
1034<p>
1035</p>
1036<a name="node_sec_4.3.9"></a>
1037<h3><a href="#node_toc_node_sec_4.3.9">4.3.9&nbsp;&nbsp;<tt>Calendar.show</tt></a></h3><p></p>
1038<p>
1039Call this function do show the calendar.  It basically sets the CSS &#8220;display&#8221;
1040property to &#8220;block&#8221;.  It doesn&#8217;t modify the calendar position.</p>
1041<p>
1042This function only makes sense when the calendar is in popup mode.</p>
1043<p>
1044</p>
1045<a name="node_sec_4.3.10"></a>
1046<h3><a href="#node_toc_node_sec_4.3.10">4.3.10&nbsp;&nbsp;<tt>Calendar.showAt</tt></a></h3><p></p>
1047<p>
1048Call this to show the calendar at a certain (x, y) position.  Prototype:</p>
1049<p>
1050</p>
1051<pre class=verbatim>calendar.showAt(x, y);
1052</pre><p></p>
1053<p>
1054The parameters are absolute coordinates relative to the top left
1055corner <em>of the page</em>, thus they are <em>page</em> coordinates not screen
1056coordinates.</p>
1057<p>
1058After setting the given coordinates it calls Calendar.show.  This function only
1059makes sense when the calendar is in popup mode.</p>
1060<p>
1061</p>
1062<a name="node_sec_4.3.11"></a>
1063<h3><a href="#node_toc_node_sec_4.3.11">4.3.11&nbsp;&nbsp;<tt>Calendar.showAtElement</tt></a></h3><p></p>
1064<p>
1065This function is useful if you want to display the calendar near some element.
1066You call it like this:</p>
1067<p>
1068</p>
1069<pre class=verbatim>calendar.showAtElement(element, align);
1070</pre><p></p>
1071<p>
1072where element is a reference to your element (for instance it can be the input
1073field that displays the date) and align is an optional parameter, of type string,
1074containing one or two characters.  For instance, if you pass <tt>&quot;Br&quot;</tt> as
1075align, the calendar will appear <em>below</em> the element and with its right
1076margin continuing the element&#8217;s right margin.</p>
1077<p>
1078As stated above, align may contain one or two characters.  The first character
1079dictates the vertical alignment, relative to the element, and the second
1080character dictates the horizontal alignment.  If the second character is
1081missing it will be assumed <tt>&quot;l&quot;</tt> (the left margin of the calendar will
1082be at the same horizontal position as the left margin of the element).</p>
1083<p>
1084The characters given for the align parameters are case sensitive.  This
1085function only makes sense when the calendar is in popup mode.  After computing
1086the position it uses <tt>Calendar.showAt</tt> to display the calendar there.</p>
1087<p>
1088</p>
1089<a name="node_sec_Temp_8"></a>
1090<h4><a href="#node_toc_node_sec_Temp_8">Vertical alignment</a></h4><p>The first character in &#8220;<tt>align</tt>&#8221; can take one of the following values:</p>
1091<p>
1092</p>
1093<ul><p>
1094</p>
1095<li><p><tt>T</tt> &#8212; completely above the reference element (bottom margin of
1096the calendar aligned to the top margin of the element).</p>
1097<p>
1098</p>
1099<li><p><tt>t</tt> &#8212; above the element but may overlap it (bottom margin of the calendar aligned to
1100the bottom margin of the element).</p>
1101<p>
1102</p>
1103<li><p><tt>c</tt> &#8212; the calendar displays vertically centered to the reference
1104element.  It might overlap it (that depends on the horizontal alignment).</p>
1105<p>
1106</p>
1107<li><p><tt>b</tt> &#8212; below the element but may overlap it (top margin of the calendar aligned to
1108the top margin of the element).</p>
1109<p>
1110</p>
1111<li><p><tt>B</tt> &#8212; completely below the element (top margin of the calendar
1112aligned to the bottom margin of the element).</p>
1113<p>
1114</p>
1115</ul><p></p>
1116<p>
1117</p>
1118<a name="node_sec_Temp_9"></a>
1119<h4><a href="#node_toc_node_sec_Temp_9">Horizontal alignment</a></h4><p>The second character in &#8220;<tt>align</tt>&#8221; can take one of the following values:</p>
1120<p>
1121</p>
1122<ul><p>
1123</p>
1124<li><p><tt>L</tt> &#8212; completely to the left of the reference element (right
1125margin of the calendar aligned to the left margin of the element).</p>
1126<p>
1127</p>
1128<li><p><tt>l</tt> &#8212; to the left of the element but may overlap it (left margin
1129of the calendar aligned to the left margin of the element).</p>
1130<p>
1131</p>
1132<li><p><tt>c</tt> &#8212; horizontally centered to the element.  Might overlap it,
1133depending on the vertical alignment.</p>
1134<p>
1135</p>
1136<li><p><tt>r</tt> &#8212; to the right of the element but may overlap it (right
1137margin of the calendar aligned to the right margin of the element).</p>
1138<p>
1139</p>
1140<li><p><tt>R</tt> &#8212; completely to the right of the element (left margin of the
1141calendar aligned to the right margin of the element).</p>
1142<p>
1143</p>
1144</ul><p></p>
1145<p>
1146</p>
1147<a name="node_sec_Temp_10"></a>
1148<h4><a href="#node_toc_node_sec_Temp_10">Default values</a></h4><p>If the &#8220;<tt>align</tt>&#8221; parameter is missing the calendar will choose
1149&#8220;<tt>Br</tt>&#8221;.</p>
1150<p>
1151</p>
1152<a name="node_sec_4.3.12"></a>
1153<h3><a href="#node_toc_node_sec_4.3.12">4.3.12&nbsp;&nbsp;<tt>Calendar.setDate</tt></a></h3><p></p>
1154<p>
1155Receives a JavaScript <tt>Date</tt> object.  Sets the given date in the
1156calendar.  If the calendar is visible the new date is displayed immediately.</p>
1157<p>
1158</p>
1159<pre class=verbatim>calendar.setDate(new Date()); // go today
1160</pre><p></p>
1161<p>
1162</p>
1163<a name="node_sec_4.3.13"></a>
1164<h3><a href="#node_toc_node_sec_4.3.13">4.3.13&nbsp;&nbsp;<tt>Calendar.setFirstDayOfWeek</tt></a></h3><p></p>
1165<p>
1166Changes the first day of week.  The parameter has to be a numeric value ranging
1167from 0 to 6.  Pass 0 for Sunday, 1 for Monday, ..., 6 for Saturday.</p>
1168<p>
1169</p>
1170<pre class=verbatim>calendar.setFirstDayOfWeek(5); // start weeks on Friday
1171</pre><p></p>
1172<p>
1173</p>
1174<a name="node_sec_4.3.14"></a>
1175<h3><a href="#node_toc_node_sec_4.3.14">4.3.14&nbsp;&nbsp;<tt>Calendar.parseDate</tt></a></h3><p></p>
1176<p>
1177Use this function to parse a date given as string and to move the calendar to
1178that date.</p>
1179<p>
1180The algorithm tries to parse the date according to the format that was
1181previously set with <tt>Calendar.setDateFormat</tt>; if that fails, it still
1182tries to get some valid date out of it (it doesn&#8217;t read your thoughts, though).</p>
1183<p>
1184</p>
1185<pre class=verbatim>calendar.parseDate(&quot;2003/07/06&quot;);
1186</pre><p></p>
1187<p>
1188</p>
1189<a name="node_sec_4.3.15"></a>
1190<h3><a href="#node_toc_node_sec_4.3.15">4.3.15&nbsp;&nbsp;<tt>Calendar.setRange</tt></a></h3><p></p>
1191<p>
1192Sets the range of years that are allowed in the calendar.  Synopsis:</p>
1193<p>
1194</p>
1195<pre class=verbatim>calendar.setRange(1970, 2050);
1196</pre><p></p>
1197<p>
1198</p>
1199<a name="node_sec_5"></a>
1200<h1><a href="#node_toc_node_sec_5">5&nbsp;&nbsp;Side effects</a></h1><p>The calendar code was intentionally embedded in an object to make it have as
1201less as possible side effects.  However, there are some&#8212;not harmful, after
1202all.  Here is a list of side effects; you can count they already happened after
1203<tt>calendar.js</tt> was loaded.</p>
1204<p>
1205</p>
1206<ol><p>
1207</p>
1208<li><p>The global variable <tt>window.calendar</tt> will be set to null.  This
1209variable is used by the calendar code, especially when doing drag &amp; drop for
1210moving the calendar.  In the future I might get rid of it, but for now it
1211didn&#8217;t harm anyone.</p>
1212<p>
1213</p>
1214<li><p>The JavaScript <tt>Date</tt> object is modified.  We add some properties
1215and functions that are very useful to our calendar.  It made more sense to add
1216them directly to the <tt>Date</tt> object than to the calendar itself.
1217Complete list:</p>
1218<p>
1219</p>
1220<ol><p>
1221</p>
1222<li><p><tt>Date._MD    = new Array(31,28,31,30,31,30,31,31,30,31,30,31);</tt>
1223</p>
1224<li><p><tt>Date.SECOND = 1000 /* milliseconds */;</tt>
1225</p>
1226<li><p><tt>Date.MINUTE = 60 * Date.SECOND;</tt>
1227</p>
1228<li><p><tt>Date.HOUR   = 60 * Date.MINUTE;</tt>
1229</p>
1230<li><p><tt>Date.DAY    = 24 * Date.HOUR;</tt>
1231</p>
1232<li><p><tt>Date.WEEK   =  7 * Date.DAY;</tt></p>
1233<p>
1234</p>
1235<li><p><tt>Date.prototype.getMonthDays</tt>(month) &#8212; returns the number of days
1236of the given month, or of the current date object if no month was given.</p>
1237<p>
1238</p>
1239<li><p><tt>Date.prototype.getWeekNumber</tt>() &#8212; returns the week number of the
1240date in the current object.</p>
1241<p>
1242</p>
1243<li><p><tt>Date.prototype.equalsTo</tt>(other_date) &#8212; compare the current date
1244object with <tt>other_date</tt> and returns <tt>true</tt> if the dates are
1245equal.  <em>It ignores time</em>.</p>
1246<p>
1247</p>
1248<li><p><tt>Date.prototype.print</tt>(format) &#8212; returns a string with the
1249current date object represented in the given format.  It implements the format
1250specified in section <a href="#node_sec_4.3.5">4.3.5</a>.</p>
1251<p>
1252</p>
1253</ol><p></p>
1254<p>
1255</p>
1256</ol><p></p>
1257<p>
1258</p>
1259<a name="node_sec_6"></a>
1260<h1><a href="#node_toc_node_sec_6">6&nbsp;&nbsp;Credits</a></h1><p>The following people either sponsored, donated money to the project or bought
1261commercial licenses (listed in reverse chronological order).  Your name could
1262be here too!  If you wish to sponsor the project (for instance request a
1263feature and pay me for implementing it) or donate some money please
1264<em>please</em> contact me at <tt><a href="mailto:mishoo@infoiasi.ro">mishoo@infoiasi.ro</a></tt>.</p>
1265<p>
1266</p>
1267<ul><p>
1268</p>
1269<li><p>Sunny Chowdhury (<a href="http://www.ex3.com">www.ex3.com</a>)</p>
1270<p>
1271</p>
1272<li><p>Ian Barrack (<a href="http://www.simban.com">www.simban.com</a>)</p>
1273<p>
1274</p>
1275<li><p>Himanshukumar Shah</p>
1276<p>
1277</p>
1278<li><p>Seyhan Ersoy (<a href="http://www.oocgi.com">www.oocgi.com</a>)</p>
1279<p>
1280</p>
1281<li><p>Jon Stokkeland (<a href="http://www.sauen.com">www.sauen.com</a>)</p>
1282<p>
1283</p>
1284</ul><p></p>
1285<p>
1286</p>
1287<div align=right><table><tr><td>
1288
1289<b>Thank you!</b><br>
1290&#8212; <tt>mishoo@infoiasi.ro</tt>
1291</td></tr></table></div>
1292<p>
1293</p>
1294<div class=footnoterule><hr></div><p></p>
1295<div class=footnote><p><a name="footnote_Temp_2"></a><a href="#call_footnote_Temp_2"><sup><small>1</small></sup></a> 
1296by the term &#8220;widget&#8221; I understand a single element of user interface.
1297But that&#8217;s in Linux world.  For those that did lots of Windows
1298programming the term &#8220;control&#8221; might be more familiar
1299</p>
1300<p><a name="footnote_Temp_3"></a><a href="#call_footnote_Temp_3"><sup><small>2</small></sup></a> people report that the calendar does
1301not work with IE5/Mac.  I don&#8217;t have access to a Macintosh,
1302therefore&#8212;sorry&#8212;I can&#8217;t fix it.</p>
1303<p><a name="footnote_Temp_4"></a><a href="#call_footnote_Temp_4"><sup><small>3</small></sup></a>  under Opera 7 the calendar still lacks some functionality, such as
1304keyboard navigation; also Opera doesn&#8217;t seem to allow disabling text
1305selection when one drags the mouse on the page; despite all that, the
1306calendar is still highly functional under Opera 7 and looks as good as
1307in other supported browsers. </p>
1308<p><a name="footnote_Temp_5"></a><a href="#call_footnote_Temp_5"><sup><small>4</small></sup></a> user interface</p>
1309</div>
1310<div align=right class=colophon>
1311<i>Last modified: Fri, Feb 6, 2004, 8:53 pm<br>
1312HTML conversion by <a href="http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html">TeX2page 4r8f</a></i>
1313</div>
1314</body>
1315</html>
Note: See TracBrowser for help on using the repository browser.