1 <!doctype html public
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5 Generated from TeX source by tex2page, v 4r8f
6 (running on MzScheme 204, unix),
8 http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html
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">
48 <h1 class=title align=center
><br><br>DHTML Calendar Widget
</h1>
51 Mihai Bazon,
<tt><mishoo@infoiasi.ro
></tt><p>February
6,
2004<br></p>
54 <span class=small
>calendar version:
0.9.6 “Keep cool but don
’t freeze
”</span>
59 <span class=small
><code class=verbatim
></code></span>
61 <span class=small
><blockquote>
62 <div align=right
><table><tr><td>
64 </td></tr></table></div>
67 <a name=
"node_sec_Temp_1"></a>
68 <h1>Contents
</h1><p><a name=
"node_toc_start"></a></p>
70 <a name=
"node_toc_node_sec_1"></a><a href=
"#node_sec_1">1 Overview
</a></b><br>
71 <a name=
"node_toc_node_sec_1.1"></a><a href=
"#node_sec_1.1">1.1 How does this thing work?
</a><br>
72 <a name=
"node_toc_node_sec_1.2"></a><a href=
"#node_sec_1.2">1.2 Project files
</a><br>
73 <a name=
"node_toc_node_sec_1.3"></a><a href=
"#node_sec_1.3">1.3 License
</a><br>
76 <a name=
"node_toc_node_sec_2"></a><a href=
"#node_sec_2">2 Quick startup
</a></b><br>
77 <a name=
"node_toc_node_sec_2.1"></a><a href=
"#node_sec_2.1">2.1 Installing a popup calendar
</a><br>
78 <a name=
"node_toc_node_sec_2.2"></a><a href=
"#node_sec_2.2">2.2 Installing a flat calendar
</a><br>
79 <a name=
"node_toc_node_sec_2.3"></a><a href=
"#node_sec_2.3">2.3 <tt>Calendar.setup
</tt> in detail
</a><br>
82 <a name=
"node_toc_node_sec_3"></a><a href=
"#node_sec_3">3 The Calendar object overview
</a></b><br>
83 <a name=
"node_toc_node_sec_3.1"></a><a href=
"#node_sec_3.1">3.1 Creating a calendar
</a><br>
84 <a name=
"node_toc_node_sec_3.2"></a><a href=
"#node_sec_3.2">3.2 Order does matter ;-)
</a><br>
85 <a name=
"node_toc_node_sec_3.3"></a><a href=
"#node_sec_3.3">3.3 Caching the object
</a><br>
86 <a name=
"node_toc_node_sec_3.4"></a><a href=
"#node_sec_3.4">3.4 Callback functions
</a><br>
89 <a name=
"node_toc_node_sec_4"></a><a href=
"#node_sec_4">4 The Calendar object API reference
</a></b><br>
90 <a name=
"node_toc_node_sec_4.1"></a><a href=
"#node_sec_4.1">4.1 <tt>Calendar
</tt> constructor
</a><br>
91 <a name=
"node_toc_node_sec_4.2"></a><a href=
"#node_sec_4.2">4.2 Useful member variables (properties)
</a><br>
92 <a name=
"node_toc_node_sec_4.3"></a><a href=
"#node_sec_4.3">4.3 Public methods
</a><br>
93 <a name=
"node_toc_node_sec_4.3.1"></a><a href=
"#node_sec_4.3.1">4.3.1 <tt>Calendar.create
</tt></a><br>
94 <a name=
"node_toc_node_sec_4.3.2"></a><a href=
"#node_sec_4.3.2">4.3.2 <tt>Calendar.callHandler
</tt></a><br>
95 <a name=
"node_toc_node_sec_4.3.3"></a><a href=
"#node_sec_4.3.3">4.3.3 <tt>Calendar.callCloseHandler
</tt></a><br>
96 <a name=
"node_toc_node_sec_4.3.4"></a><a href=
"#node_sec_4.3.4">4.3.4 <tt>Calendar.hide
</tt></a><br>
97 <a name=
"node_toc_node_sec_4.3.5"></a><a href=
"#node_sec_4.3.5">4.3.5 <tt>Calendar.setDateFormat
</tt></a><br>
98 <a name=
"node_toc_node_sec_4.3.6"></a><a href=
"#node_sec_4.3.6">4.3.6 <tt>Calendar.setTtDateFormat
</tt></a><br>
99 <a name=
"node_toc_node_sec_4.3.7"></a><a href=
"#node_sec_4.3.7">4.3.7 <tt>Calendar.setDisabledHandler
</tt></a><br>
100 <a name=
"node_toc_node_sec_4.3.8"></a><a href=
"#node_sec_4.3.8">4.3.8 <tt>Calendar.setDateStatusHandler
</tt></a><br>
101 <a name=
"node_toc_node_sec_4.3.9"></a><a href=
"#node_sec_4.3.9">4.3.9 <tt>Calendar.show
</tt></a><br>
102 <a name=
"node_toc_node_sec_4.3.10"></a><a href=
"#node_sec_4.3.10">4.3.10 <tt>Calendar.showAt
</tt></a><br>
103 <a name=
"node_toc_node_sec_4.3.11"></a><a href=
"#node_sec_4.3.11">4.3.11 <tt>Calendar.showAtElement
</tt></a><br>
104 <a name=
"node_toc_node_sec_4.3.12"></a><a href=
"#node_sec_4.3.12">4.3.12 <tt>Calendar.setDate
</tt></a><br>
105 <a name=
"node_toc_node_sec_4.3.13"></a><a href=
"#node_sec_4.3.13">4.3.13 <tt>Calendar.setFirstDayOfWeek
</tt></a><br>
106 <a name=
"node_toc_node_sec_4.3.14"></a><a href=
"#node_sec_4.3.14">4.3.14 <tt>Calendar.parseDate
</tt></a><br>
107 <a name=
"node_toc_node_sec_4.3.15"></a><a href=
"#node_sec_4.3.15">4.3.15 <tt>Calendar.setRange
</tt></a><br>
110 <a name=
"node_toc_node_sec_5"></a><a href=
"#node_sec_5">5 Side effects
</a></b><br>
113 <a name=
"node_toc_node_sec_6"></a><a href=
"#node_sec_6">6 Credits
</a></b><br>
119 <a name=
"node_sec_1"></a>
120 <h1><a href=
"#node_toc_node_sec_1">1 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>
121 is an (HTML) user interface element that gives end-users a friendly way to
122 select date and time. It works in a web browser. The first versions only provided
123 support for popup calendars, while starting with version
0.9 it also supports
124 “flat
” display. A
“flat
” calendar is a calendar that stays visible in the
125 page all the time. In this mode it could be very useful for
“blog
” pages and
126 other pages that require the calendar to be always present.
</p>
128 The calendar is compatible with most popular browsers nowadays. While it
’s
129 created using web standards and it should generally work with any compliant
130 browser, the following browsers were found to work: Mozilla (the
131 development platform), Netscape
6.0 or better, all other Gecko-based browsers,
132 Internet Explorer
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
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
133 same dysfunctions as in Opera).
</p>
135 You can find the latest info and version at the calendar homepage:
</p>
138 <div align=center
><table><tr><td>
140 <a href=
"http://dynarch.com/mishoo/calendar.epl"><tt>http://dynarch.com/mishoo/calendar.epl
</tt></a>
141 </td></tr></table></div>
144 <a name=
"node_sec_1.1"></a>
145 <h2><a href=
"#node_toc_node_sec_1.1">1.1 How does this thing work?
</a></h2><p>DHTML is not
“another kind of HTML
”. It
’s merely a naming convention. DHTML
146 refers to the combination of HTML, CSS, JavaScript and DOM. DOM (Document
147 Object Model) is a set of interfaces that glues the other three together. In
148 other words, DOM allows dynamic modification of an HTML page through a program.
149 JavaScript is our programming language, since that
’s what browsers like. CSS
150 is a way to make it look good ;-). So all this soup is generically known as
153 Using DOM calls, the program dynamically creates a
<tt><table
></tt> element
154 that contains a calendar for the given date and then inserts it in the document
155 body. Then it shows this table at a specified position. Usually the position
156 is related to some element in which the date needs to be displayed/entered,
157 such as an input field.
</p>
159 By assigning a certain CSS class to the table we can control the look of the
160 calendar through an external CSS file; therefore, in order to change the
161 colors, backgrounds, rollover effects and other stuff, you can only change a
162 CSS file
—modification of the program itself is not necessary.
</p>
165 <a name=
"node_sec_1.2"></a>
166 <h2><a href=
"#node_toc_node_sec_1.2">1.2 Project files
</a></h2><p>Here
’s a description of the project files, excluding documentation and example
172 <li><p>the main program file (
<tt>calendar.js
</tt>). This defines all the logic
173 behind the calendar widget.
</p>
176 <li><p>the CSS files (
<tt>calendar-*.css
</tt>). Loading one of them is
177 necessary in order to see the calendar as intended.
</p>
180 <li><p>the language definition files (
<tt>lang/calendar-*.js
</tt>). They are
181 plain JavaScript files that contain all texts that are displayed by the
182 calendar. Loading one of them is necessary.
</p>
185 <li><p>helper functions for quick setup of the calendar
186 (
<tt>calendar-setup.js
</tt>). You can do fine without it, but starting with
187 version
0.9.3 this is the recommended way to setup a calendar.
</p>
193 <a name=
"node_sec_1.3"></a>
194 <h2><a href=
"#node_toc_node_sec_1.3">1.3 License
</a></h2><p></p>
195 <div align=center
><table><tr><td>
197 © Mihai Bazon,
2002 – 2003,
<tt><mishoo@infoiasi.ro
></tt><br>
198 <a href=
"http://dynarch.com/mishoo/"><tt>http://dynarch.com/mishoo/
</tt></a>
199 </td></tr></table></div>
201 The calendar is released under the
202 <a href=
"http://www.gnu.org/licenses/lgpl.html">GNU Lesser General Public License
</a>. You
203 can
<a href=
"http://www.gnu.org/licenses/lgpl.html">read the entire license text
207 <a name=
"node_sec_2"></a>
208 <h1><a href=
"#node_toc_node_sec_2">2 Quick startup
</a></h1><p></p>
210 Installing the calendar used to be quite a task until version
0.9.3. Starting
211 with
0.9.3 I have included the file
<tt>calendar-setup.js
</tt> whose goal is to
212 assist you to setup a popup or flat calendar in minutes. You are
213 encouraged to modify this file and
<em>not
</em> calendar.js if you need
214 extra customization, but you
’re on your own.
</p>
216 First you have to include the needed scripts and style-sheet. Make sure you do
217 this in your document
’s
<tt><head
></tt> section, also make sure you put the
218 correct paths to the scripts.
</p>
221 <pre class=verbatim
><style type=
"text/css
">@import url(calendar-win2k-
1.css);
</style
>
222 <script type=
"text/javascript
" src=
"calendar.js
"></script
>
223 <script type=
"text/javascript
" src=
"lang/calendar-en.js
"></script
>
224 <script type=
"text/javascript
" src=
"calendar-setup.js
"></script
>
228 <a name=
"node_sec_2.1"></a>
229 <h2><a href=
"#node_toc_node_sec_2.1">2.1 Installing a popup calendar
</a></h2><p></p>
231 Now suppose you have the following HTML:
</p>
234 <pre class=verbatim
><form ...
>
235 <input type=
"text
" id=
"data
" name=
"data
" /
>
236 <button id=
"trigger
">...
</button
>
240 You want the button to popup a calendar widget when clicked? Just
241 insert the following code immediately
<em>after
</em> the HTML form:
</p>
244 <pre class=verbatim
><script type=
"text/javascript
">
247 inputField :
"data
", // ID of the input field
248 ifFormat :
"%m %d, %Y
", // the date format
249 button :
"trigger
" // ID of the button
255 The
<tt>Calendar.setup
</tt> function, defined in
<tt>calendar-setup.js
</tt>
256 takes care of
“patching
” the button to display a calendar when clicked. The
257 calendar is by default in single-click mode and linked with the given input
258 field, so that when the end-user selects a date it will update the input field
259 with the date in the given format and close the calendar. If you are a
260 long-term user of the calendar you probably remember that for doing this you
261 needed to write a couple functions and add an
“onclick
” handler for the
264 By looking at the example above we can see that the function
265 <tt>Calendar.setup
</tt> receives only one parameter: a JavaScript object.
266 Further, that object can have lots of properties that tell to the setup
267 function how would we like to have the calendar. For instance, if we would
268 like a calendar that closes at double-click instead of single-click we would
269 also include the following:
<tt>singleClick:false
</tt>.
</p>
271 For a list of all supported parameters please see the section
272 <a href=
"#node_sec_2.3">2.3</a>.
</p>
275 <a name=
"node_sec_2.2"></a>
276 <h2><a href=
"#node_toc_node_sec_2.2">2.2 Installing a flat calendar
</a></h2><p></p>
278 Here
’s how to configure a flat calendar, using the same
<tt>Calendar.setup
</tt>
279 function. First, you should have an empty element with an ID. This element
280 will act as a container for the calendar. It can be any block-level element,
281 such as DIV, TABLE, etc. We will use a DIV in this example.
</p>
284 <pre class=verbatim
><div id=
"calendar-container
"></div
>
287 Then there is the JavaScript code that sets up the calendar into the
288 “calendar-container
” DIV. The code can occur anywhere in HTML
289 <em>after
</em> the DIV element.
</p>
292 <pre class=verbatim
><script type=
"text/javascript
">
293 function dateChanged(calendar) {
294 // Beware that this function is called even if the end-user only
295 // changed the month/year. In order to determine if a date was
296 // clicked you can use the dateClicked property of the calendar:
297 if (calendar.dateClicked) {
298 // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
299 var y = calendar.date.getFullYear();
300 var m = calendar.date.getMonth(); // integer,
0.
.11
301 var d = calendar.date.getDate(); // integer,
1.
.31
303 window.location =
"/
" + y +
"/
" + m +
"/
" + d +
"/index.php
";
309 flat :
"calendar-container
", // ID of the parent element
310 flatCallback : dateChanged // our callback function
317 <a name=
"node_sec_2.3"></a>
318 <h2><a href=
"#node_toc_node_sec_2.3">2.3 <tt>Calendar.setup
</tt> in detail
</a></h2><p></p>
320 Following there is the complete list of properties interpreted by
321 Calendar.setup. All of them have default values, so you can pass only those
322 which you would like to customize. Anyway, you
<em>must
</em> pass at least one
323 of
<tt>inputField
</tt>,
<tt>displayArea
</tt> or
<tt>button
</tt>, for a popup
324 calendar, or
<tt>flat
</tt> for a flat calendar. Otherwise you will get a
325 warning message saying that there
’s nothing to setup.
</p>
328 <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>
330 <tr><td valign=top
><tt>inputField
</tt>
331 </td><td valign=top
>string
</td><td valign=top
>The ID of your input field.
332 </td><td valign=top
>null
334 <tr><td valign=top
><tt>displayArea
</tt>
335 </td><td valign=top
>string
</td><td valign=top
>This is the ID of a
<span
>,
<div
>, 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.
336 </td><td valign=top
>null
338 <tr><td valign=top
><tt>button
</tt>
339 </td><td valign=top
>string
</td><td valign=top
>The ID of the calendar
“trigger
”. This is an element (ordinarily a button or an image) that will dispatch a certain event (usually
“click
”) to the function that creates and displays the calendar.
340 </td><td valign=top
>null
342 <tr><td valign=top
><tt>eventName
</tt>
343 </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
“on
” prefix, such as
“click
” instead of
“onclick
”. Virtually all users will want to let this have the default value (
“click
”). 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
“focus
” as the event name).
344 </td><td valign=top
>“click
”
346 <tr><td valign=top
><tt>ifFormat
</tt>
347 </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.
348 </td><td valign=top
>“%Y/%m/%d
”
350 <tr><td valign=top
><tt>daFormat
</tt>
351 </td><td valign=top
>string
</td><td valign=top
>Format of the date displayed in the displayArea (if specified).
352 </td><td valign=top
>“%Y/%m/%d
”
354 <tr><td valign=top
><tt>singleClick
</tt>
355 </td><td valign=top
>boolean
</td><td valign=top
>Wether the calendar is in
“single-click mode
” or
“double-click mode
”. If true (the default) the calendar will be created in single-click mode.
356 </td><td valign=top
>true
358 <tr><td valign=top
><tt>disableFunc
</tt>
359 </td><td valign=top
>function
</td><td valign=top
>A function that receives a JS Date object. It should return
360 <tt>true
</tt> if that date has to be disabled,
<tt>false
</tt> otherwise.
361 <font color=
"red">DEPRECATED (see below).
</font>
362 </td><td valign=top
>null
364 <tr><td valign=top
><tt>dateStatusFunc
</tt>
365 </td><td valign=top
>function
</td><td valign=top
>A function that receives a JS Date object and returns a boolean
366 or a string. This function allows one to set a certain CSS class to some
367 date, therefore making it look different. If it returns
<tt>true
</tt> then
368 the date will be disabled. If it returns
<tt>false
</tt> nothing special
369 happens with the given date. If it returns a string then that will be taken
370 as a CSS class and appended to the date element. If this string is
371 “disabled
” then the date is also disabled (therefore is like returning
372 <tt>true
</tt>). For more information please also refer to section
373 <a href=
"#node_sec_4.3.8">4.3.8</a>.
374 </td><td valign=top
>null
376 <tr><td valign=top
><tt>firstDay
</tt>
377 </td><td valign=top
>integer
</td><td valign=top
>Specifies which day is to be displayed as the first day of
378 week. Possible values are
0 to
6;
0 means Sunday,
1 means Monday, ...,
6
379 means Saturday. The end user can easily change this too, by clicking on the
380 day name in the calendar header.
381 </td><td valign=top
>0
383 <tr><td valign=top
><tt>weekNumbers
</tt>
384 </td><td valign=top
>boolean
</td><td valign=top
>If
“true
” then the calendar will display week numbers.
385 </td><td valign=top
>true
387 <tr><td valign=top
><tt>align
</tt>
388 </td><td valign=top
>string
</td><td valign=top
>Alignment of the calendar, relative to the reference element. The
389 reference element is dynamically chosen like this: if a displayArea is
390 specified then it will be the reference element. Otherwise, the input field
391 is the reference element. For the meaning of the alignment characters
392 please section
<a href=
"#node_sec_4.3.11">4.3.11</a>.
393 </td><td valign=top
>“Bl
”
395 <tr><td valign=top
><tt>range
</tt>
396 </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.
397 </td><td valign=top
>[
1900,
2999]
399 <tr><td valign=top
><tt>flat
</tt>
400 </td><td valign=top
>string
</td><td valign=top
>If you want a flat calendar, pass the ID of the parent object in
401 this property. If not, pass
<tt>null
</tt> here (or nothing at all as
402 <tt>null
</tt> is the default value).
403 </td><td valign=top
>null
405 <tr><td valign=top
><tt>flatCallback
</tt>
406 </td><td valign=top
>function
</td><td valign=top
>You should provide this function if the calendar is flat. It
407 will be called when the date in the calendar is changed with a reference to
408 the calendar object. See section
<a href=
"#node_sec_2.2">2.2</a> for an example
409 of how to setup a flat calendar.
410 </td><td valign=top
>null
412 <tr><td valign=top
><tt>onSelect
</tt>
413 </td><td valign=top
>function
</td><td valign=top
>If you provide a function handler here then you have to manage
414 the
“click-on-date
” event by yourself. Look in the calendar-setup.js and
415 take as an example the onSelect handler that you can see there.
416 </td><td valign=top
>null
418 <tr><td valign=top
><tt>onClose
</tt>
419 </td><td valign=top
>function
</td><td valign=top
>This handler will be called when the calendar needs to close.
420 You don
’t need to provide one, but if you do it
’s your responsibility to
421 hide/destroy the calendar. You
’re on your own. Check the calendar-setup.js
423 </td><td valign=top
>null
425 <tr><td valign=top
><tt>onUpdate
</tt>
426 </td><td valign=top
>function
</td><td valign=top
>If you supply a function handler here, it will be called right
427 after the target field is updated with a new date. You can use this to
428 chain
2 calendars, for instance to setup a default date in the second just
429 after a date was selected in the first.
430 </td><td valign=top
>null
432 <tr><td valign=top
><tt>date
</tt>
433 </td><td valign=top
>date
</td><td valign=top
>This allows you to setup an initial date where the calendar will be
434 positioned to. If absent then the calendar will open to the today date.
435 </td><td valign=top
>null
437 <tr><td valign=top
><tt>showsTime
</tt>
438 </td><td valign=top
>boolean
</td><td valign=top
>If this is set to
<tt>true
</tt> then the calendar will also
439 allow time selection.
440 </td><td valign=top
>false
442 <tr><td valign=top
><tt>timeFormat
</tt>
443 </td><td valign=top
>string
</td><td valign=top
>Set this to
“12” or
“24” to configure the way that the
444 calendar will display time.
445 </td><td valign=top
>“24”
447 <tr><td valign=top
><tt>electric
</tt>
448 </td><td valign=top
>boolean
</td><td valign=top
>Set this to
“false
” if you want the calendar to update the
449 field only when closed (by default it updates the field at each date change,
450 even if the calendar is not closed)
</td><td valign=top
>true
452 <tr><td valign=top
><tt>position
</tt>
453 </td><td valign=top
>array
</td><td valign=top
>Specifies the [x, y] position, relative to page
’s top-left corner,
454 where the calendar will be displayed. If not passed then the position will
455 be computed based on the
“align
” parameter. Defaults to
“null
” (not
456 used).
</td><td valign=top
>null
458 <tr><td valign=top
><tt>cache
</tt>
459 </td><td valign=top
>boolean
</td><td valign=top
>Set this to
“true
” if you want to cache the calendar object.
460 This means that a single calendar object will be used for all fields that
461 require a popup calendar
</td><td valign=top
>false
463 <tr><td valign=top
><tt>showOthers
</tt>
464 </td><td valign=top
>boolean
</td><td valign=top
>If set to
“true
” then days belonging to months overlapping
465 with the currently displayed month will also be displayed in the calendar
466 (but in a
“faded-out
” color)
</td><td valign=top
>false
472 <a name=
"node_sec_3"></a>
473 <h1><a href=
"#node_toc_node_sec_3">3 The Calendar object overview
</a></h1><p></p>
475 Basically you should be able to setup the calendar with the function presented
476 in the previous section. However, if for some reason
<tt>Calendar.setup
</tt>
477 doesn
’t provide all the functionality that you need and you want to tweak into
478 the process of creating and configuring the calendar
“by hand
”, then this
479 section is the way to go.
</p>
481 The file
<tt>calendar.js
</tt> implements the functionality of the calendar.
482 All (well, almost all) functions and variables are embedded in the JavaScript
483 object
“Calendar
”.
</p>
485 You can instantiate a
<tt>Calendar
</tt> object by calling the constructor, like
486 this:
<tt>var cal = new Calendar(
<tt>...
</tt>)
</tt>. We will discuss the parameters
487 later. After creating the object, the variable
<tt>cal
</tt> will contain a
488 reference to it. You can use this reference to access further options of the
489 calendar, for instance:
</p>
492 <pre class=verbatim
>cal.weekNumbers = false; // do not display week numbers
493 cal.showsTime = true; // include a time selector
494 cal.setDateFormat(
"%Y.%m.%d %H:%M
"); // set this format:
2003.12.31 23:
59
495 cal.setDisabledHandler(function(date, year, month, day) {
496 // verify date and return true if it has to be disabled
497 // ``date'' is a JS Date object, but if you only need the
498 // year, month and/or day you can get them separately as
499 // next
3 parameters, as you can see in the declaration
501 // disable all dates from
2004
508 etc. Prior to version
509 0.9.3 this was the only way to configure it. The
<tt>Calendar.setup
</tt>
510 function, documented in section
<a href=
"#node_sec_2">2</a>, basically does the same
511 things (actually more) in order to setup the calendar, based on the parameters
512 that you provided.
</p>
515 <a name=
"node_sec_3.1"></a>
516 <h2><a href=
"#node_toc_node_sec_3.1">3.1 Creating a calendar
</a></h2><p>The calendar is created by following some steps (even the function
517 <tt>Calendar.setup
</tt>, described in section
<a href=
"#node_sec_2">2</a>, does the
518 same). While you can skip optional (marked
“opt
”) steps if you
’re happy with
519 the defaults, please respect the order below.
</p>
524 <li><p><em>Instantiate
</em> a
<tt>Calendar
</tt> object. Details about this in
525 section
<a href=
"#node_sec_4.1">4.1</a>.
</p>
528 <li><p><b>opt
</b> Set the
<tt>weekNumbers
</tt> property to
<tt>false
</tt> if you don
’t want
529 the calendar to display week numbers.
</p>
532 <li><p><b>opt
</b> Set the
<tt>showsTime
</tt> property to
<tt>true
</tt> if you
533 want the calendar to also provide a time selector.
</p>
536 <li><p><b>opt
</b> Set the
<tt>time24
</tt> property to
<tt>false
</tt> if you want
537 the time selector to be in
12-hour format. Default is
24-hour format. This
538 property only has effect if you also set
<tt>showsTime
</tt> to
542 <li><p><b>opt
</b> Set the range of years available for selection (see section
543 <a href=
"#node_sec_4.3.15">4.3.15</a>). The default range is [
1970.
.2050].
</p>
546 <li><p><b>opt
</b> Set the
<tt>getDateStatus
</tt> property. You should pass
547 here a function that receives a JavaScript
<tt>Date
</tt> object and returns
548 <tt>true
</tt> if the given date should be disabled, false otherwise (details in
549 section
<a href=
"#node_sec_4.3.7">4.3.7</a>).
</p>
552 <li><p><b>opt
</b> Set a date format. Your handler function, passed to the
553 calendar constructor, will be called when a date is selected with a reference
554 to the calendar and a date string in this format.
</p>
557 <li><p><em>Create
</em> the HTML elements related to the calendar. This step
558 practically puts the calendar in your HTML page. You simply call
559 <tt>Calendar.create()
</tt>. You can give an optional parameter if you wanna
560 create a flat calendar (details in section
<a href=
"#node_sec_4.3.1">4.3.1</a>).
</p>
563 <li><p><b>opt
</b> Initialize the calendar to a certain date, for instance from
567 <li><p>Show the calendar (details in section
<a href=
"#node_sec_4.3.9">4.3.9</a>).
</p>
573 <a name=
"node_sec_3.2"></a>
574 <h2><a href=
"#node_toc_node_sec_3.2">3.2 Order does matter ;-)
</a></h2><p>As you could see in the previous section, there are more steps to be followed
575 in order to setup the calendar. This happens because there are two different
576 things that need to be accomplished: first there is the JavaScript object, that
577 is created with
<tt>new Calendar(
<tt>...
</tt>)
</tt>. Secondly there are the HTML
578 elements that actually lets you see and manipulate the calendar.
</p>
581 <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
582 language and on what platform, may be familiar with this concept. First there
583 is the object in memory that lets you manipulate the UI element, and secondly
584 there is the UI element (known as
“control
”,
“window
”,
“widget
”, etc.),
585 also in memory but you don
’t usually access it directly. ]
587 By instantiating the calendar we create the JavaScript object. It lets us
588 configure some properties and it also knows how to create the UI element (the
589 HTML elements actually) that will eventually be what the end-user sees on
590 screen. Creation of the HTML element is accomplished by the function
591 <tt>Calendar.create
</tt>. It knows how to create popup or flat calendars.
592 This function is described in section
<a href=
"#node_sec_4.3.1">4.3.1</a>.
</p>
594 Some properties need to be set prior to creating the HTML elements, because
595 otherwise they wouldn
’t have any effect. Such a property is
596 <tt>weekNumbers
</tt>—it has the default value
“true
”, and if you don
’t
597 want the calendar to display the week numbers you have to set it to false. If,
598 however, you do that
<em>after
</em> calling
<tt>Calendar.create
</tt> the calendar
599 would still display the week numbers, because the HTML elements are already
600 created (including the
<tt><td
></tt>-s in the
<tt><table
></tt> element that
601 should contain the week numbers). For this reason the order of the steps above
604 Another example is when you want to show the calendar. The
“create
” function
605 does create the HTML elements, but they are initially hidden (have the style
606 “display: none
”) unless the calendar is a flat calendar that should be always
607 visible in the page. Obviously, the
<tt>Calendar.show
</tt> function should be
608 called
<em>after
</em> calling
<tt>Calendar.create
</tt>.
</p>
611 <a name=
"node_sec_3.3"></a>
612 <h2><a href=
"#node_toc_node_sec_3.3">3.3 Caching the object
</a></h2><p>Suppose the end-user has popped up a calendar and selects a date. The calendar
613 then closes. What really happens now?
</p>
615 There are two approaches. The first (used in very old versions of the
616 calendar) was to drop completely the Calendar object and when the end-user pops
617 up the calendar again to create another one. This approach is bad for more
623 <li><p>creating the JavaScript object and HTML elements is time-consuming
</p>
626 <li><p>we may loose some end-user preferences (i.e. he might prefer to have
627 Monday for the first day of week and probably already clicked it the first time
628 when the calendar was opened, but now he has to do it again)
</p>
633 The second approach, implemented by the
<tt>Calendar.setup
</tt> function, is to
634 cache the JavaScript object. It does this by checking the global variable
635 <tt>window.calendar
</tt> and if it is not null it assumes it is the created
636 Calendar object. When the end-user closes the calendar, our code will only
637 call
“<tt>hide
</tt>” on it, therefore keeping the JavaScript object and the
638 HTML elements in place.
</p>
640 <font color=
"red">CAVEAT:
</font> Since time selection support was introduced, this
641 “object caching
” mechanism has the following drawback: if you once created
642 the calendar with the time selection support, then other items that may not
643 require this functionality will still get a calendar with the time selection
644 support enabled. And reciprocal. ;-) Hopefully this will be corrected in a
645 later version, but for now it doesn
’t seem such a big problem.
</p>
648 <a name=
"node_sec_3.4"></a>
649 <h2><a href=
"#node_toc_node_sec_3.4">3.4 Callback functions
</a></h2><p>You might rightfully wonder how is the calendar related to the input field?
650 Who tells it that it has to update
<em>that
</em> input field when a date is
651 selected, or that it has to jump to
<em>that
</em> URL when a date is clicked in
654 All this magic is done through callback functions. The calendar doesn
’t know
655 anything about the existence of an input field, nor does it know where to
656 redirect the browser when a date is clicked in flat mode. It just calls your
657 callback when a particular event is happening, and you
’re responsible to handle
658 it from there. For a general purpose library I think this is the best model of
659 making a truly reusable thing.
</p>
661 The calendar supports the following user callbacks:
</p>
666 <li><p><b>onSelect
</b> — this gets called when the end-user changes the date in the
667 calendar. Documented in section
<a href=
"#node_sec_4.1">4.1</a>.
</p>
670 <li><p><b>onClose
</b> — this gets called when the calendar should close. It
’s
671 user
’s responsibility to close the calendar. Details in section
672 <a href=
"#node_sec_4.1">4.1</a>.
</p>
675 <li><p><b>getDateStatus
</b> — this function gets called for any day in a month,
676 just before displaying the month. It is called with a JavaScript
<tt>Date
</tt>
677 object and should return
<tt>true
</tt> if that date should be disabled, false
678 if it
’s an ordinary date and no action should be taken, or it can return a
679 string in which case the returned value will be appended to the element
’s CSS
680 class (this way it provides a powerful way to make some dates
“special
”,
681 i.e. highlight them differently). Details in section
682 <a href=
"#node_sec_4.3.8">4.3.8</a>.
</p>
688 <a name=
"node_sec_4"></a>
689 <h1><a href=
"#node_toc_node_sec_4">4 The Calendar object API reference
</a></h1><p></p>
692 <a name=
"node_sec_4.1"></a>
693 <h2><a href=
"#node_toc_node_sec_4.1">4.1 <tt>Calendar
</tt> constructor
</a></h2><p></p>
698 <pre class=verbatim
>var calendar = Calendar(firstDayOfWeek, date, onSelect, onClose);
701 Parameters are as follows:
</p>
706 <li><p><b>firstDayOfWeek
</b> — specifies which day is to be displayed as the first
707 day of week. Possible values are
0 to
6;
0 means Sunday,
1 means Monday,
708 ...,
6 means Saturday.
</p>
711 <li><p><b>date
</b> — a JavaScript Date object or
<tt>null
</tt>. If
<tt>null
</tt>
712 is passed then the calendar will default to today date. Otherwise it will
713 initialize on the given date.
</p>
716 <li><p><b>onSelect
</b> — your callback for the
“onChange
” event. See above.
</p>
719 <li><p><b>onClose
</b> — your callback for the
“onClose
” event. See above.
</p>
725 <a name=
"node_sec_Temp_6"></a>
726 <h3><a href=
"#node_toc_node_sec_Temp_6">The
<tt>onSelect
</tt> event
</a></h3><p></p>
728 Here is a typical implementation of this function:
</p>
731 <pre class=verbatim
>function onSelect(calendar, date) {
732 var input_field = document.getElementById(
"date
");
733 input_field.value = date;
737 <tt>date
</tt> is in the format selected with
<tt>calendar.setDateFormat
</tt>
738 (see section
<a href=
"#node_sec_4.3.5">4.3.5</a>). This code simply updates the
739 input field. If you want the calendar to be in single-click mode then you
740 should also close the calendar after you updated the input field, so we come to
741 the following version:
</p>
744 <pre class=verbatim
>function onSelect(calendar, date) {
745 var input_field = document.getElementById(
"date
");
746 input_field.value = date;
747 if (calendar.dateClicked) {
748 calendar.callCloseHandler(); // this calls
"onClose
" (see above)
753 Note that we checked the member variable
<tt>dateClicked
</tt> and
754 only hide the calendar if it
’s
<tt>true
</tt>. If this variable is
<tt>false
</tt> it
755 means that no date was actually selected, but the user only changed the
756 month/year using the navigation buttons or the menus. We don
’t want to hide
757 the calendar in that case.
</p>
760 <a name=
"node_sec_Temp_7"></a>
761 <h3><a href=
"#node_toc_node_sec_Temp_7">The
<tt>onClose
</tt> event
</a></h3><p></p>
763 This event is triggered when the calendar should close. It should hide or
764 destroy the calendar object
—the calendar itself just triggers the event, but
765 it won
’t close itself.
</p>
767 A typical implementation of this function is the following:
</p>
770 <pre class=verbatim
>function onClose(calendar) {
772 // or calendar.destroy();
777 <a name=
"node_sec_4.2"></a>
778 <h2><a href=
"#node_toc_node_sec_4.2">4.2 Useful member variables (properties)
</a></h2><p></p>
780 After creating the Calendar object you can access the following properties:
</p>
785 <li><p><tt>date
</tt> — is a JavaScript
<tt>Date
</tt> object. It will always
786 reflect the date shown in the calendar (yes, even if the calendar is hidden).
</p>
789 <li><p><tt>isPopup
</tt> — if this is true then the current Calendar object is
790 a popup calendar. Otherwise (false) we have a flat calendar. This variable is
791 set from
<tt>Calendar.create
</tt> and has no meaning before this function was
795 <li><p><tt>dateClicked
</tt> — particularly useful in the
<tt>onSelect
</tt>
796 handler, this variable tells us if a date was really clicked. That
’s because
797 the
<tt>onSelect
</tt> handler is called even if the end-user only changed the
798 month/year but did not select a date. We don
’t want to close the calendar in
802 <li><p><tt>weekNumbers
</tt> — if
<tt>true
</tt> (default) then the calendar
803 displays week numbers. If you don
’t want week numbers you have to set this
804 variable to
<tt>false
</tt> <em>before
</em> calling
<tt>Calendar.create
</tt>.
</p>
807 <li><p><tt>showsTime
</tt> – if you set this to
<tt>true
</tt> (it is
808 <tt>false
</tt> by default) then the calendar will also include a time selector.
</p>
811 <li><p><tt>time24
</tt> – if you set this to
<tt>false
</tt> then the time
812 selector will be in
12-hour format. It is in
24-hour format by default.
</p>
815 <li><p><tt>firstDayOfWeek
</tt> — specifies the first day of week (
0 to
6, pass
816 0 for Sunday,
1 for Monday, ...,
6 for Saturday). This variable is set from
817 constructor, but you still have a chance to modify it
<em>before
</em> calling
818 <tt>Calendar.create
</tt>.
</p>
823 There are lots of other member variables, but one should access them only
824 through member functions so I won
’t document them here.
</p>
827 <a name=
"node_sec_4.3"></a>
828 <h2><a href=
"#node_toc_node_sec_4.3">4.3 Public methods
</a></h2><p></p>
829 <a name=
"node_sec_4.3.1"></a>
830 <h3><a href=
"#node_toc_node_sec_4.3.1">4.3.1 <tt>Calendar.create
</tt></a></h3><p></p>
832 This function creates the afferent HTML elements that are needed to display the
833 calendar. You should call it after setting the calendar properties. Synopsis:
835 <pre class=verbatim
>calendar.create(); // creates a popup calendar
837 calendar.create(document.getElementById(parent_id)); // makes a flat calendar
840 It can create a popup calendar or a flat calendar. If the
“parent
” argument
841 is present (it should be a
<em>reference
</em>—not ID
—to an HTML element) then
842 a flat calendar is created and it is inserted in the given element.
</p>
844 At any moment, given a reference to a calendar object, we can inspect if it
’s a
845 popup or a flat calendar by checking the boolean member variable
846 <tt>isPopup
</tt>:
</p>
849 <pre class=verbatim
>if (calendar.isPopup) {
850 // this is a popup calendar
852 // this is a flat calendar
857 <a name=
"node_sec_4.3.2"></a>
858 <h3><a href=
"#node_toc_node_sec_4.3.2">4.3.2 <tt>Calendar.callHandler
</tt></a></h3><p></p>
860 This function calls the first user callback (the
861 <tt>onSelect
</tt> handler) with the required parameters.
</p>
864 <a name=
"node_sec_4.3.3"></a>
865 <h3><a href=
"#node_toc_node_sec_4.3.3">4.3.3 <tt>Calendar.callCloseHandler
</tt></a></h3><p></p>
867 This function calls the second user callback (the
868 <tt>onClose
</tt> handler). It
’s useful when you want to have a
869 “single-click
” calendar
—just call this in your
<tt>onSelect
</tt> handler,
870 if a date was clicked.
</p>
873 <a name=
"node_sec_4.3.4"></a>
874 <h3><a href=
"#node_toc_node_sec_4.3.4">4.3.4 <tt>Calendar.hide
</tt></a></h3><p></p>
876 Call this function to hide the calendar. The calendar object and HTML elements
877 will not be destroyed, thus you can later call one of the
<tt>show
</tt>
878 functions on the same element.
</p>
881 <a name=
"node_sec_4.3.5"></a>
882 <h3><a href=
"#node_toc_node_sec_4.3.5">4.3.5 <tt>Calendar.setDateFormat
</tt></a></h3><p></p>
884 This function configures the format in which the calendar reports the date to
885 your
“onSelect
” handler. Call it like this:
</p>
888 <pre class=verbatim
>calendar.setDateFormat(
"%y/%m/%d
");
891 As you can see, it receives only one parameter, the required format. The magic
892 characters are the following:
</p>
895 <table border=
0><tr><td valign=top
></td></tr>
896 <tr><td valign=top
><tt>%a
</tt> </td><td valign=top
>abbreviated weekday name
</td></tr>
897 <tr><td valign=top
><tt>%A
</tt> </td><td valign=top
>full weekday name
</td></tr>
898 <tr><td valign=top
><tt>%b
</tt> </td><td valign=top
>abbreviated month name
</td></tr>
899 <tr><td valign=top
><tt>%B
</tt> </td><td valign=top
>full month name
</td></tr>
900 <tr><td valign=top
><tt>%C
</tt> </td><td valign=top
>century number
</td></tr>
901 <tr><td valign=top
><tt>%d
</tt> </td><td valign=top
>the day of the month (
00 ..
31 )
</td></tr>
902 <tr><td valign=top
><tt>%e
</tt> </td><td valign=top
>the day of the month (
0 ..
31 )
</td></tr>
903 <tr><td valign=top
><tt>%H
</tt> </td><td valign=top
>hour (
00 ..
23 )
</td></tr>
904 <tr><td valign=top
><tt>%I
</tt> </td><td valign=top
>hour (
01 ..
12 )
</td></tr>
905 <tr><td valign=top
><tt>%j
</tt> </td><td valign=top
>day of the year (
000 ..
366 )
</td></tr>
906 <tr><td valign=top
><tt>%k
</tt> </td><td valign=top
>hour (
0 ..
23 )
</td></tr>
907 <tr><td valign=top
><tt>%l
</tt> </td><td valign=top
>hour (
1 ..
12 )
</td></tr>
908 <tr><td valign=top
><tt>%m
</tt> </td><td valign=top
>month (
01 ..
12 )
</td></tr>
909 <tr><td valign=top
><tt>%M
</tt> </td><td valign=top
>minute (
00 ..
59 )
</td></tr>
910 <tr><td valign=top
><tt>%n
</tt> </td><td valign=top
>a newline character
</td></tr>
911 <tr><td valign=top
><tt>%p
</tt> </td><td valign=top
>“PM
” or
“AM
” </td></tr>
912 <tr><td valign=top
><tt>%P
</tt> </td><td valign=top
>“pm
” or
“am
” </td></tr>
913 <tr><td valign=top
><tt>%S
</tt> </td><td valign=top
>second (
00 ..
59 )
</td></tr>
914 <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>
915 <tr><td valign=top
><tt>%t
</tt> </td><td valign=top
>a tab character
</td></tr>
916 <tr><td valign=top
><tt>%U, %W, %V
</tt> </td><td valign=top
>the week number
</td></tr>
917 <tr><td valign=top
><tt>%u
</tt> </td><td valign=top
>the day of the week (
1 ..
7,
1 = MON )
</td></tr>
918 <tr><td valign=top
><tt>%w
</tt> </td><td valign=top
>the day of the week (
0 ..
6,
0 = SUN )
</td></tr>
919 <tr><td valign=top
><tt>%y
</tt> </td><td valign=top
>year without the century (
00 ..
99 )
</td></tr>
920 <tr><td valign=top
><tt>%Y
</tt> </td><td valign=top
>year including the century ( ex.
1979 )
</td></tr>
921 <tr><td valign=top
><tt>%%
</tt> </td><td valign=top
>a literal
<tt>%
</tt> character
922 </td></tr></table><p>
923 There are more algorithms for computing the week number. All
924 three specifiers currently implement the same one, as defined by ISO
8601:
925 “the week
01 is the week that has the Thursday in the current year, which is
926 equivalent to the week that contains the fourth day of January. Weeks start on
930 <a name=
"node_sec_4.3.6"></a>
931 <h3><a href=
"#node_toc_node_sec_4.3.6">4.3.6 <tt>Calendar.setTtDateFormat
</tt></a></h3><p></p>
933 Has the same prototype as
<tt>Calendar.setDateFormat
</tt>, but refers to the
934 format of the date displayed in the
“status bar
” when the mouse is over some
938 <a name=
"node_sec_4.3.7"></a>
939 <h3><a href=
"#node_toc_node_sec_4.3.7">4.3.7 <tt>Calendar.setDisabledHandler
</tt></a></h3><p></p>
941 This function allows you to specify a callback function that checks if a
942 certain date must be disabled by the calendar. You are responsible to write
943 the callback function. Synopsis:
</p>
946 <pre class=verbatim
>function disallowDate(date) {
947 // date is a JS Date object
948 if ( date.getFullYear() ==
2003 &&
949 date.getMonth() ==
6 /* July, it's zero-based */
&&
950 date.getDate() ==
5 ) {
951 return true; // disable July
5 2003
953 return false; // enable other dates
956 calendar.setDisabledHandler(disallowDate);
959 If you change this function in
“real-time
”, meaning, without creating a new
960 calendar, then you have to call
<tt>calendar.refresh()
</tt> to make it
961 redisplay the month and take into account the new disabledHandler.
962 <tt>Calendar.setup
</tt> does this, so you have no such trouble with it.
</p>
964 Note that
<tt>disallowDate
</tt> should be very fast, as it is called for each
965 date in the month. Thus, it gets called, say,
30 times before displaying the
966 calendar, and
30 times when the month is changed. Tests I
’ve done so far show
967 that it
’s still good, but in the future I might switch it to a different design
968 (for instance, to call it once per month and to return an array of dates that
969 must be disabled).
</p>
971 This function should be considered deprecated in the favor of
972 <tt>Calendar.setDateStatusHandler
</tt>, described below.
</p>
975 <a name=
"node_sec_4.3.8"></a>
976 <h3><a href=
"#node_toc_node_sec_4.3.8">4.3.8 <tt>Calendar.setDateStatusHandler
</tt></a></h3><p></p>
978 This function obsoletes
<tt>Calendar.setDisabledHandler
</tt>. You call it with
979 a function parameter, but this function can return a boolean
980 <em>or a string
</em>. If the return value is a boolean (
<tt>true
</tt> or
981 <tt>false
</tt>) then it behaves just like
<tt>setDisabledHandler
</tt>,
982 therefore disabling the date if the return value is
<tt>true
</tt>.
</p>
984 If the returned value is a string then the given date will gain an additional
985 CSS class, namely the returned value. You can use this to highlight some dates
986 in some way. Note that you are responsible for defining the CSS class that you
987 return. If you return the string
“disabled
” then that date will be disabled,
988 just as if you returned
<tt>true
</tt>.
</p>
990 Here is a simple scenario that shows what you can do with this function. The
991 following should be present in some of your styles, or in the document head in
992 a STYLE tag (but put it
<em>after
</em> the place where the calendar styles were
996 <pre class=verbatim
>.special { background-color: #
000; color: #fff; }
999 And you would use the following code before calling
<tt>Calendar.create()
</tt>:
</p>
1002 <pre class=verbatim
>// this table holds your special days, so that we can automatize
1004 var SPECIAL_DAYS = {
1005 0 : [
13,
24 ], // special days in January
1006 2 : [
1,
6,
8,
12,
18 ], // special days in March
1007 8 : [
21,
11 ], // special days in September
1008 11 : [
25,
28 ] // special days in December
1011 // this function returns true if the passed date is special
1012 function dateIsSpecial(year, month, day) {
1013 var m = SPECIAL_DAYS[month];
1014 if (!m) return false;
1015 for (var i in m) if (m[i] == day) return true;
1019 // this is the actual date status handler. Note that it receives the
1020 // date object as well as separate values of year, month and date, for
1022 function dateStatusHandler(date, y, m, d) {
1023 if (dateIsSpecial(y, m, d)) return ``special'';
1025 // return true above if you want to disable other dates
1028 // configure it to the calendar
1029 calendar.setDateStatusHandler(dateStatusHandler);
1032 The above code adds the
“special
” class name to some dates that are defined
1033 in the SPECIAL_DAYS table. Other dates will simply be displayed as default,
1037 <a name=
"node_sec_4.3.9"></a>
1038 <h3><a href=
"#node_toc_node_sec_4.3.9">4.3.9 <tt>Calendar.show
</tt></a></h3><p></p>
1040 Call this function do show the calendar. It basically sets the CSS
“display
”
1041 property to
“block
”. It doesn
’t modify the calendar position.
</p>
1043 This function only makes sense when the calendar is in popup mode.
</p>
1046 <a name=
"node_sec_4.3.10"></a>
1047 <h3><a href=
"#node_toc_node_sec_4.3.10">4.3.10 <tt>Calendar.showAt
</tt></a></h3><p></p>
1049 Call this to show the calendar at a certain (x, y) position. Prototype:
</p>
1052 <pre class=verbatim
>calendar.showAt(x, y);
1055 The parameters are absolute coordinates relative to the top left
1056 corner
<em>of the page
</em>, thus they are
<em>page
</em> coordinates not screen
1059 After setting the given coordinates it calls Calendar.show. This function only
1060 makes sense when the calendar is in popup mode.
</p>
1063 <a name=
"node_sec_4.3.11"></a>
1064 <h3><a href=
"#node_toc_node_sec_4.3.11">4.3.11 <tt>Calendar.showAtElement
</tt></a></h3><p></p>
1066 This function is useful if you want to display the calendar near some element.
1067 You call it like this:
</p>
1070 <pre class=verbatim
>calendar.showAtElement(element, align);
1073 where element is a reference to your element (for instance it can be the input
1074 field that displays the date) and align is an optional parameter, of type string,
1075 containing one or two characters. For instance, if you pass
<tt>"Br
"</tt> as
1076 align, the calendar will appear
<em>below
</em> the element and with its right
1077 margin continuing the element
’s right margin.
</p>
1079 As stated above, align may contain one or two characters. The first character
1080 dictates the vertical alignment, relative to the element, and the second
1081 character dictates the horizontal alignment. If the second character is
1082 missing it will be assumed
<tt>"l
"</tt> (the left margin of the calendar will
1083 be at the same horizontal position as the left margin of the element).
</p>
1085 The characters given for the align parameters are case sensitive. This
1086 function only makes sense when the calendar is in popup mode. After computing
1087 the position it uses
<tt>Calendar.showAt
</tt> to display the calendar there.
</p>
1090 <a name=
"node_sec_Temp_8"></a>
1091 <h4><a href=
"#node_toc_node_sec_Temp_8">Vertical alignment
</a></h4><p>The first character in
“<tt>align
</tt>” can take one of the following values:
</p>
1096 <li><p><tt>T
</tt> — completely above the reference element (bottom margin of
1097 the calendar aligned to the top margin of the element).
</p>
1100 <li><p><tt>t
</tt> — above the element but may overlap it (bottom margin of the calendar aligned to
1101 the bottom margin of the element).
</p>
1104 <li><p><tt>c
</tt> — the calendar displays vertically centered to the reference
1105 element. It might overlap it (that depends on the horizontal alignment).
</p>
1108 <li><p><tt>b
</tt> — below the element but may overlap it (top margin of the calendar aligned to
1109 the top margin of the element).
</p>
1112 <li><p><tt>B
</tt> — completely below the element (top margin of the calendar
1113 aligned to the bottom margin of the element).
</p>
1119 <a name=
"node_sec_Temp_9"></a>
1120 <h4><a href=
"#node_toc_node_sec_Temp_9">Horizontal alignment
</a></h4><p>The second character in
“<tt>align
</tt>” can take one of the following values:
</p>
1125 <li><p><tt>L
</tt> — completely to the left of the reference element (right
1126 margin of the calendar aligned to the left margin of the element).
</p>
1129 <li><p><tt>l
</tt> — to the left of the element but may overlap it (left margin
1130 of the calendar aligned to the left margin of the element).
</p>
1133 <li><p><tt>c
</tt> — horizontally centered to the element. Might overlap it,
1134 depending on the vertical alignment.
</p>
1137 <li><p><tt>r
</tt> — to the right of the element but may overlap it (right
1138 margin of the calendar aligned to the right margin of the element).
</p>
1141 <li><p><tt>R
</tt> — completely to the right of the element (left margin of the
1142 calendar aligned to the right margin of the element).
</p>
1148 <a name=
"node_sec_Temp_10"></a>
1149 <h4><a href=
"#node_toc_node_sec_Temp_10">Default values
</a></h4><p>If the
“<tt>align
</tt>” parameter is missing the calendar will choose
1150 “<tt>Br
</tt>”.
</p>
1153 <a name=
"node_sec_4.3.12"></a>
1154 <h3><a href=
"#node_toc_node_sec_4.3.12">4.3.12 <tt>Calendar.setDate
</tt></a></h3><p></p>
1156 Receives a JavaScript
<tt>Date
</tt> object. Sets the given date in the
1157 calendar. If the calendar is visible the new date is displayed immediately.
</p>
1160 <pre class=verbatim
>calendar.setDate(new Date()); // go today
1164 <a name=
"node_sec_4.3.13"></a>
1165 <h3><a href=
"#node_toc_node_sec_4.3.13">4.3.13 <tt>Calendar.setFirstDayOfWeek
</tt></a></h3><p></p>
1167 Changes the first day of week. The parameter has to be a numeric value ranging
1168 from
0 to
6. Pass
0 for Sunday,
1 for Monday, ...,
6 for Saturday.
</p>
1171 <pre class=verbatim
>calendar.setFirstDayOfWeek(
5); // start weeks on Friday
1175 <a name=
"node_sec_4.3.14"></a>
1176 <h3><a href=
"#node_toc_node_sec_4.3.14">4.3.14 <tt>Calendar.parseDate
</tt></a></h3><p></p>
1178 Use this function to parse a date given as string and to move the calendar to
1181 The algorithm tries to parse the date according to the format that was
1182 previously set with
<tt>Calendar.setDateFormat
</tt>; if that fails, it still
1183 tries to get some valid date out of it (it doesn
’t read your thoughts, though).
</p>
1186 <pre class=verbatim
>calendar.parseDate(
"2003/
07/
06");
1190 <a name=
"node_sec_4.3.15"></a>
1191 <h3><a href=
"#node_toc_node_sec_4.3.15">4.3.15 <tt>Calendar.setRange
</tt></a></h3><p></p>
1193 Sets the range of years that are allowed in the calendar. Synopsis:
</p>
1196 <pre class=verbatim
>calendar.setRange(
1970,
2050);
1200 <a name=
"node_sec_5"></a>
1201 <h1><a href=
"#node_toc_node_sec_5">5 Side effects
</a></h1><p>The calendar code was intentionally embedded in an object to make it have as
1202 less as possible side effects. However, there are some
—not harmful, after
1203 all. Here is a list of side effects; you can count they already happened after
1204 <tt>calendar.js
</tt> was loaded.
</p>
1209 <li><p>The global variable
<tt>window.calendar
</tt> will be set to null. This
1210 variable is used by the calendar code, especially when doing drag
& drop for
1211 moving the calendar. In the future I might get rid of it, but for now it
1212 didn
’t harm anyone.
</p>
1215 <li><p>The JavaScript
<tt>Date
</tt> object is modified. We add some properties
1216 and functions that are very useful to our calendar. It made more sense to add
1217 them directly to the
<tt>Date
</tt> object than to the calendar itself.
1223 <li><p><tt>Date._MD = new Array(
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31);
</tt>
1225 <li><p><tt>Date.SECOND =
1000 /* milliseconds */;
</tt>
1227 <li><p><tt>Date.MINUTE =
60 * Date.SECOND;
</tt>
1229 <li><p><tt>Date.HOUR =
60 * Date.MINUTE;
</tt>
1231 <li><p><tt>Date.DAY =
24 * Date.HOUR;
</tt>
1233 <li><p><tt>Date.WEEK =
7 * Date.DAY;
</tt></p>
1236 <li><p><tt>Date.prototype.getMonthDays
</tt>(month)
— returns the number of days
1237 of the given month, or of the current date object if no month was given.
</p>
1240 <li><p><tt>Date.prototype.getWeekNumber
</tt>()
— returns the week number of the
1241 date in the current object.
</p>
1244 <li><p><tt>Date.prototype.equalsTo
</tt>(other_date)
— compare the current date
1245 object with
<tt>other_date
</tt> and returns
<tt>true
</tt> if the dates are
1246 equal.
<em>It ignores time
</em>.
</p>
1249 <li><p><tt>Date.prototype.print
</tt>(format)
— returns a string with the
1250 current date object represented in the given format. It implements the format
1251 specified in section
<a href=
"#node_sec_4.3.5">4.3.5</a>.
</p>
1260 <a name=
"node_sec_6"></a>
1261 <h1><a href=
"#node_toc_node_sec_6">6 Credits
</a></h1><p>The following people either sponsored, donated money to the project or bought
1262 commercial licenses (listed in reverse chronological order). Your name could
1263 be here too! If you wish to sponsor the project (for instance request a
1264 feature and pay me for implementing it) or donate some money please
1265 <em>please
</em> contact me at
<tt><a href=
"mailto:mishoo@infoiasi.ro">mishoo@infoiasi.ro
</a></tt>.
</p>
1270 <li><p>Sunny Chowdhury (
<a href=
"http://www.ex3.com">www.ex3.com
</a>)
</p>
1273 <li><p>Ian Barrack (
<a href=
"http://www.simban.com">www.simban.com
</a>)
</p>
1276 <li><p>Himanshukumar Shah
</p>
1279 <li><p>Seyhan Ersoy (
<a href=
"http://www.oocgi.com">www.oocgi.com
</a>)
</p>
1282 <li><p>Jon Stokkeland (
<a href=
"http://www.sauen.com">www.sauen.com
</a>)
</p>
1288 <div align=right
><table><tr><td>
1290 <b>Thank you!
</b><br>
1291 — <tt>mishoo@infoiasi.ro
</tt>
1292 </td></tr></table></div>
1295 <div class=footnoterule
><hr></div><p></p>
1296 <div class=footnote
><p><a name=
"footnote_Temp_2"></a><a href=
"#call_footnote_Temp_2"><sup><small>1</small></sup></a>
1297 by the term
“widget
” I understand a single element of user interface.
1298 But that
’s in Linux world. For those that did lots of Windows
1299 programming the term
“control
” might be more familiar
1301 <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
1302 not work with IE5/Mac. I don
’t have access to a Macintosh,
1303 therefore
—sorry
—I can
’t fix it.
</p>
1304 <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
1305 keyboard navigation; also Opera doesn
’t seem to allow disabling text
1306 selection when one drags the mouse on the page; despite all that, the
1307 calendar is still highly functional under Opera
7 and looks as good as
1308 in other supported browsers.
</p>
1309 <p><a name=
"footnote_Temp_5"></a><a href=
"#call_footnote_Temp_5"><sup><small>4</small></sup></a> user interface
</p>
1311 <div align=right class=colophon
>
1312 <i>Last modified: Fri, Feb
6,
2004,
8:
53 pm
<br>
1313 HTML conversion by
<a href=
"http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html">TeX2page
4r8f
</a></i>