
Originally Posted by
jscheuer1
Why reinvent the wheel?
Reinventing the wheel can be fun and it's certainly educational, mainly because you have some functionality to aim for.
Many of the scripts available from DD as a whole are in need of updating. Both the quality of the generated markup, and the ability to script, for example, CSS according to specifications. Validity is a rising trend, and scripts should reflect this.
Following the steps the OP gave, rather liberally I might add, I get:
Code:
function calendar(date) {
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December'],
day = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
now = new Date(),
output = ['<table class="calendar">',
'<thead>',
'<tr>',
'<th colspan="7">' + month[date.getMonth()] + ', '
+ date.getFullYear() + '<\/th>',
'<\/tr>',
'<\/thead>',
'<tbody>',
'<tr>'];
function areEqual(x, y) {
return (x.getDate() == y.getDate()) && (x.getMonth() == y.getMonth())
&& (x.getFullYear() == y.getFullYear());
}
for(var i = 0, n = day.length; i < n; ++i) {
output.push('<th>' + day[i] + '<\/th>');
}
output.push('<\/tr>');
document.write(output.join('\n'));
}
The code is, of course, far from complete. Both the main body of the output needs to be included, and the tbody and table elements need to be closed.
The push method needs to be emulated for earlier IE versions:
Code:
if('function' != typeof Array.prototype.push) {
Array.prototype.push = function() {
for(var i = 0, j = this.length, n = arguments.length; i < n; ++j, ++i) {
this[j] = arguments[i];
}
return j;
};
}
Mike
Bookmarks