Witam, przerobiłem troszeczkę pewien skrypt kalendarza.
Jest to skrypt, który generuje kalendarz na aktualny miesiącvar now = new Date;
var MyMonth = new Array("Styczeń", "Luty", "Marzec", "Kwiecień", "Maj",
"Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik",
"Listopad", "Grudzień");
var MyYear = now.getFullYear();
var Days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var DaysinWeek = 7;
var Today = now.getDate();
var ThisMonth = now.getMonth();
var MonthStart = now.setDate(1);
var AddDays = now.getDate();
var DayofWeek = now.getDay();
var DaysinMonth = Days[now.getMonth()];
function CreateCurrMonth(TableBG,CellBG){
// Checks Leap Year
if ((((MyYear % 4)==0) && ((MyYear % 100)!=0) || ((MyYear % 400)==0)) && (DaysinMonth == 28)) {
DaysinMonth = 29;
}else{
DaysinMonth = Days[now.getMonth()];
}
document.write ("<table><caption>" + MyMonth[now.getMonth()] + " " + now.getFullYear() + "</caption>");
document.write ("<tr>");
// Build rows in a month
for (i = 0; AddDays < DaysinMonth + 1; i++){
if (i < DayofWeek){
document.write ("<td></td>");
} else {
if ((AddDays == Today) && (now.getMonth() == ThisMonth)){
document.write ("<td><a href=\"index.php\" class=\"current\">" + AddDays + "</a></td>");
AddDays = AddDays + 1
} else {
if ((i % 7) == 0){
document.write ("</tr>");
document.write ("<tr>");
}
if((i % 7) == 0) {
document.write ("<td><a href=\"index.php\" class=\"sunday\">" + AddDays + "</a></td>");
} else {
document.write ("<td><a href=\"index.php\">" + AddDays + "</a></td>");
}
AddDays = AddDays + 1
}
}
}
document.write ("</tr></table>");
}
function AddCalendar(addmonth,TableBG,CellBG){
var NewMonth = ThisMonth + addmonth
if (NewMonth > 11){
NewMonth=(NewMonth-12);
now.setYear(MyYear + 1);
}
now.setMonth(NewMonth);
DayofWeek = now.getDay();
AddDays = now.getDate();
DaysinMonth = Days[now.getMonth()];
CreateCurrMonth(TableBG,CellBG);
}
Skrypt jest generalnie bardzo prosty, ale nie mogę sobie poradzić z przestawieniem go tak, aby to niedziele były na końcu. Próbowałem kombinować, aby pętla for zaczynała się od i=1, ew. zmienną
DayofWeek ustawiać na now.getDay()
+1;
Czy ktoś ma pomysł w jaki sposób to zrobić?
Z góry dzięki.
Ten post edytował Kaloryfer 20.04.2011, 09:12:58