Simple Calendar Widget by Anthony Garrett
| Hi, I spend a lot of time developing this just because I enjoy it. However, I have costs keeping it available and need to repay my family for all those hours hacking the code by taking them out for a meal once in a blue moon. Any and all contributions are welcome. |
| Description | Praise | About Demo | Live Demo | How to... | Download | Versions |
|---|---|---|---|---|---|---|
Description | |||||||
|---|---|---|---|---|---|---|---|
|
This flexible, simple pop-up calendar is written to
work across browsers. It's fully commented and
customisable for language, colours and date format.
The pop-up displays a month at a time from a specified
range of years. The optional input date determines the
initial month displayed. The year can be in two or four
digits while the month can be digits or a month name
abbreviation that can easily be set up for
any language. Any date or day of the week can be disabled
(and re-enabled) using JavaScript on the calling page.
This is ideal for combination with server-side
technologies to produce a professional application.
|
|||||||
| Features |
|
||||||
| The script isn't... | This is not a diary application (i.e. you can't book
events etc. in it). Please see my new calendar JACS for advanced features including: Multiple calendar instances on one page, Static calendars and greater flexibility in calendar positioning. |
||||||
| Rights | This script is published under the
GNU Lesser General
Public License. The License gives you wide-ranging
rights to use the script. Please read it to ensure
that your use of the script falls within your rights.
if you have any questions or requests
in relation to the license. I am also happy to discuss licensing if you wish to use the script outside the terms of the GNU LGPL. |
||||||
| Contact | I can't offer formal support for this but if you
find a problem (or just want to tell me how much
you like the script), please
. I will try to fix problems and deliver improvements quickly but this is a spare time thing for me (if it wasn't, it wouldn't be free! ). |
||||||
| Credits | I wrote this from scratch myself but I couldn't have
done it without the superb "JavaScript The Definitive
Guide" [The Rhino Book] by David Flanagan (Pub. O'Reilly
ISBN 0-596-00048-0). I also recognise a contribution from
my experience with PopCalendar 4.1 by Liming (Victor)
Weng. I am very grateful to those users who have
given their time to let me know their ideas and
enhancements. When I use those, individuals are
credited in the script. |
||||||
| Link back | If your use of the script allows, please give me credit
and link back to my page. Your links will help the
script to gain and keep a good ranking with search
engines. Please add the following HTML to any indexed
page on your web site:
<A HREF="http://www.tarrget.info/calendar/scw.htm"> Simple Calendar Widget </A> by Anthony Garrett |
||||||
| Ideas | If you would like a new feature that might suit a
wider audience,
.
I like a challenge so
all
ideas are welcome. |
||||||
| Test limitations | I test this script against the most recent versions
of every mainstream browser I can find. That means
(in alphabetical order) Firefox, Internet Explorer,
Konqueror, Opera and Safari (for Windows). I don't
have the resources to maintain test beds for old
browser versions nor do I have an Apple Mac. If you
find a problem in the Mac version of Safari
to me. |
||||||
| Known Issues | No current bugs Working with Applets and Objects This script is designed to be as robust as possible. However, in many implementations the canvas for objects and applets is not drawn by the browser. If the object/applet is refreshed it will overwrite anything displayed in the same location, including the calendar. There is no way to prevent this issue in JavaScript. If you wish to use both dynamic objects and the calendar on the same page then the only option is to position them carefully so that they cannot overlap. Working with .NET Most complex JavaScripts can have problems in .NET applications when SmartNavigation is turned on. If you encounter odd problems with the calendar on PostBack, turn SmartNavigation off. This should fix your issue. If it does but you need SmartNavigation turned on for your application, you should experiment with the position of the calendar object in relation to Forms on the page. Reports suggest that the script must be outside any forms. |
||||||
Some selected feedback from current users... |
|---|
| "I've just integrated your code to my web site I thank you for this valuable piece of code..." - France, 17 Mar 2006 |
| "I have tried out your calendar widget, and find it clean written, easy to use, and to integrate." - Deutschland, 27 Feb 2006 |
| "I love your calendar widget. Super easy to integrate and very flexible." - USA, 10 Feb 2006 |
| "Just wanted to say thanks for a job well done. ...Thanks again for a great little widget!" - USA, 17 Dec 2005 |
| "Great job!" - Australia, 28 Nov 2005 |
|
These comments are all taken from emails I have received. The only reason they are anonymous is that I haven't asked the senders if I could use their names. |
About the Demo | |||||||
|---|---|---|---|---|---|---|---|
| Explanation | |||||||
| The examples demonstrate some ways of using the calendar. I don't recommend any one method, but I do suggest that you avoid using the roll-over as a few minutes trying it out on this page will prove how annoying it can be (NOTE: This is a general comment, not related to the Firefox 1.5 bug). | |||||||
|
The strict date processing option:
|
|||||||
|
If a day portion of a date is entered, it is
validated and must be between 1 and 31
inclusive. With the "strict" option turned on, the script generates an error for dates that are invalid in a specific month (e.g. 31 April). The calendar is then opened on the selected month but without a day selected. With it turned off, no error is generated and the calendar will open the following month with a day selected (e.g. entering 31 April would select 1 May, i.e. 30 April + 1 day). Normally you just decide which you will use and set it in the script but for this demo I have provided a button to let you try both options. |
|||||||
|
The on-calendar click to hide option:
|
|||||||
|
The very earliest versions of the calendar did not
allow a click on the calling page to close the calendar
(the technique was to click on a dead space in the calendar).
Since adding that feature I have left the original method in place. From version 2.4 this became optional. The default behaviour now does not allow a calendar click to close it. |
|||||||
|
Calendar dragging:
|
|||||||
|
You can allow the calendar to be dragged around the screen.
As with strict date processing, there is a button for
you to try out the calendar with dragging turned on or off.
For obvious reasons, clicking the drag handle does not hide the calendar when you have both dragging and the on-calendar click to hide features turned on. |
|||||||
|
Week Numbering:
|
|||||||
|
Week numbers can be displayed. The script, as supplied,
defines a year's first week using two factors; The day
that starts the week and, the day of the week that has
to be in the current year (I call the second
factor, the Base day). In the script, the day that
starts the week for numbering purposes is always the
same as the first day displayed (this prevents two week
numbers from appearing on one line). The script is initially set to comply with ISO 8601 which states that Monday is the start of the week and Thursday is the Base day. However, as this script already allows you to choose the week's start day (and Company rules may vary widely), you can also choose the Base day. There are so many different rules that can define the first week of the year that it is impossible to allow for all possibilities. The script calculates each week's number in a function (scwWeekNumber) so, if you have different rules to apply, you can modify that function and so use the script's week number display. As with Strict dates and Dragging, this demonstration allows you to turn the week display on and off. The Base day and Week start day can also be chosen. In normal use all of these would simply be set in the script. |
|||||||
|
Disabling Dates:
|
|||||||
|
This demonstration page shows date disabling in action
and allows you to try out the day-of-the-week enabling
and disabling. Several dates are disabled for each example. They are; 14th of this month, the range 28th of this - 4th of next month and Good Friday and Easter Monday of each year (based on a JavaScript calculation of Easter Day that you might find useful). Since Version 2.7 you have been able to use optional arguments to the entry routine (scwShow) to make disabling days of the week for an individual input field extra easy. See the description in the 'How to' section. Wednesday is disabled in one of the demonstration inputs (the one that starts with the value 'feb,98') using this method. The disabling of the "Today" selector (below the month display) is controlled by the script when the current day is disabled by date (individually or in a range) and by day when you use the scwShow arguments method. However, if you use javascript on your calling page to control disabling, you have control of whether the selector is active or not. To see this in action; disable today's day of the week in the check boxes below then bring up a calendar, you will see that the selector is inactive. |
|||||||
|
Language selection:
|
|||||||
|
Since Version 3.3, the language-dependent parts of the
calendar are set when the calendar is made visible
(previous versions set them when the page loaded).
So, you can dynamically choose the calendar
language without being forced to refresh the page,
this benefits users with multilingual pages.
The demo allows you to choose English and a few languages that contributors have kindly sent to me. Right-click here and select your browser's "Save" option to downloaded them. If you would like to add your own language to the list then to me. Note that on this demo page, the language setting applies only to the calendar, not the rest of the demo. |
|||||||
|
Browser Bug Warnings for this page:
|
|||||||
How to... | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| How to add the calendar to your page | Download the
script (scw.js) from this page and place it
somewhere in your site's directory/folder structure.
This script needs to be defined for your page
so add the following line immediately after
the BODY tag;
<script type='text/JavaScript'
src='<<script location>>'></script>
where <<script location>> is the URI of the script, e.g. scw.js if the script is in the same location as the page or /scripts/scw.js if it is in a "scripts" sub-folder of the web site's root directory. Your root directory of the web site should also contain an empty file called "scwblank.html". Click here for a full explanation. |
|||||||||||||||||||||||||||||||||||||||||
| How to use the calendar once it is defined for your page | Simply choose an event to trigger the calendar (like an
onClick or an onMouseOver) and an element to work on
(for the calendar to take its initial date from and
write its output date to) then write it like this;
<<event>>= "scwShow (<<element>>,event);"
scwShow (<<element>>,event,5,1);
Finally, you can use the following technique to run a function when the calendar closes:
Where <<function>> is a function defined on the calling page and <<arguments>> is the list of arguments being passed to that function. Here's an extremely trivial but fully functioning example;
|
|||||||||||||||||||||||||||||||||||||||||
Download |
|||||||
|---|---|---|---|---|---|---|---|
| Right click here and choose "Save Link/Target As..." to download the script. | |||||||
|
|||||||
|
This calendar has been submitted to the
following sites for free download, please take a moment to rate it. |
|||||||
| Big Webmaster Directory (Originally listed 2005-10-18) | |||||||
| JS Made Easy.Com (Originally listed 2005-12-12) | |||||||
| HotScripts.com (Originally listed 2006-02-19) | |||||||
| Web Scripts Directory (Originally listed 2006-02-19) | |||||||
| AllTheScripts (Originally listed 2006-07-03) | |||||||
| ScriptSearch (Originally listed 2006-07-03) | |||||||
Version History | ||
|---|---|---|
| Version | Date | Changes |
| 3.90 | 2008-05-05 |
|
| 3.80 | 2008-04-29 |
|
| 3.73 | 2008-04-11 |
|
| 3.72 | 2008-02-24 |
|
| 3.71 | 2008-01-14 |
|
| 3.70 | 2007-09-21 |
|
| 3.60 | 2007-07-31 |
|
| 3.59 | 2007-06-13 |
|
| 3.58 | 2007-04-04 |
|
| 3.57 | 2007-03-03 |
|
| 3.56 | 2006-12-13 |
|
| 3.55 | 2006-10-28 |
|
| 3.54 | 2006-10-13 |
|
| 3.53 | 2006-10-12 |
|
| 3.52 | 2006-10-10 |
|
| 3.51 | 2006-09-09 |
|
| 3.5 | 2006-04-04 |
|
| 3.4 | 2006-03-27 |
|
| 3.31 | 2006-03-20 |
|
| 3.3 | 2006-03-10 |
|
| 3.23 | 2006-03-08 |
|
| 3.22 | 2006-03-06 |
|
| 3.21 | 2006-02-27 |
|
| 3.2 | 2006-02-25 |
|
| 3.11 | 2006-02-20 |
|
| 3.1 | 2006-02-15 |
|
| 3.0 | 2006-02-10 |
|
| 2.9 | 2006-02-01 |
|
| 2.8 | 2006-01-31 |
|
| 2.7 | 2006-01-18 |
|
| 2.62 | 2006-01-14 |
|
| 2.61 | 2006-01-11 |
|
| 2.6 | 2006-01-04 |
|
| 2.5 | 2005-12-23 |
|
| 2.42 | 2005-12-15 |
|
| 2.41 | 2005-12-12 |
|
| 2.4 | 2005-12-10 |
|
| 2.3 | 2005-11-23 |
|
| 2.2 | 2005-11-17 |
|
| 2.1 | 2005-11-10 |
|
| 2.0 | 2005-11-03 |
|
| 1.2 | 2005-10-26 |
|
| 1.1 | 2005-10-17 |
|
| 1.0 | 2004-08-02 |
|
| Copyright 2005- © Anthony Garrett. All rights reserved. | |
|---|---|
| This page was last updated on . | |