|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
Introduction
BackgroundI have used some calendars written in JavaScript, most of all they are very complex, one or more separated CSS file(s) was bound with that calendar. When I need to customize the calendar, I have to read details of JavaScript code and CSS code, then modify them according to my ideas. On the other hand, the code of those calendars isn't adequately compact, more source code isn't based on OOP(Objective Oriented Programming), and I have often encountered namespace conflicts for my own code, some of which are still an existing compatibility problem. Thus, I decided to write a calendar class to make it easy to port to any browser, and its code is very compact and extended since it is completely based on OOP. The Key Features
Using the CodeHere's only a small snippet that tells you how to use the <input type="text" id="mycalendar" />
<script type="text/javascript">
// We create a new instance of XCalender here.
var c = new XCalendar();
// Before creating calendar, we'd want to customize the calendar.
// c.setDateRange(2008,1,5,2008,2,6); c.setSelDate(2008,2,2); c.setStyle(3);
// it works now.
c.create(document.getElementById("mycalendar"));
</script>
For more details, see the sample - test.html zipped in xcalendar.zip. Class Specificationcreate(_textbox, _width, _height, _parent, _id);
setSelDate(_year,_month,_day);
setDateRange(_startyear,_startmonth,_startday,_endyear,_endmonth,_endday);
setStyle(style);
enableTooltip(ok);
setFormat(format);
Class Static SpecificationQ: What's 'class static specification'? XCalendar.setValue(oEditor, value);
<script type="text/javascript">
function foo()
{
// We created the instance of XCalendar in 'foo' function.
var mycal = new XCalendar;
mycal.create(document.getElementById('input_element'));
}
function foo2()
{
/*
Now, we'd need to change a new date - 2007-12-12 with the
instance 'mycal' created in 'foo' function.
A question is 'mycal' isn't a global variable, How do we get it?
In other hand, you might want to set 'mycal' to be global,
then via like mycql.setNewDate to change the date of the calendar,
it's good idea. A best way that all you only have do is like the below code:
*/
XCalendar.setValue(document.getElementById('input_element'), '2007-12-12');
}
</script>
Similarly with the XCalendar.getValue(oEditor, format);
Utility method for getting days in a month of the year: XCalendar.getDaysInMonth(year, month);
Utility method for validating date: XCalendar.isDate(_year,_month,_day);
Namespace ConflictsFor preventing namespace conflicts, some variable names shouldn't be called // XCalendar is re-defined to an integer, so the class - XCalendar is overridden now.
var XCalendar = 1;
// Error! XCalendar has been overridden, so you never create the calendar somewhere.
var mycal = new XCalendar;
History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||