Hello there ! Nice website!
I've been having a problem with a calendar a friends of mine made for me. I cannot seem to figure out what the parameters stands for. Could anyone please help? I would be very happy :)
----------------------------------------------------------------
function buildCal(m, y, cM, cH, cDW, cD, brdr){
var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
var oD = new Date(y, m-1, 1);
oD.od=oD.getDay()+1;
var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
t+='</tr><tr align="center">';
for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : ' ';
if (x==scanfortoday) //DD added
x='<span id="today">'+x+'</span>' //DD added
t+='<td class="'+cD+'">'+x+'</td>';
if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
}
---------------------------------------------------------------
Anyone?
4 replies to this topic
#1
Posted 07 March 2011 - 11:35 PM
|
|
|
#2
Posted 07 March 2011 - 11:53 PM
That was not too hard to look through (it is simpler than you think if you look where the variables are. The prototype would be like this:
buildCal(month, year, classname, classname, classname, classname , borderwidth);
classnames being class names for the table (like <table class="...">) , td, span (you can see where they are to find what you want to edit);
buildCal(month, year, classname, classname, classname, classname , borderwidth);
classnames being class names for the table (like <table class="...">) , td, span (you can see where they are to find what you want to edit);
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 08 March 2011 - 03:30 AM
Thanks for the reply Alexander - The problem is the codes inside the script.. I dont get what: dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28; - Means, as i dont know what oD and % and ? is doing in there.. This code is mean to me to: oD.od=oD.getDay()+1; I dont get it.
#4
Posted 08 March 2011 - 12:54 PM
oD appears to be the date object, oD.od appears to be the day of the date, but + 1 days.
% is the modulus operator, 5 % 4 = 1 as 1 is the remainder of 5 / 4.
? and : are ternary operators, think of IF statements
% is the modulus operator, 5 % 4 = 1 as 1 is the remainder of 5 / 4.
? and : are ternary operators, think of IF statements
If(name == 'John') {
age = 23;
} else {
age = 0;
}
Can be written as:age = (name == 'John') ? 23 : 0;This code is very poorly written, so I do not blame you for not getting what it does.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 08 March 2011 - 11:52 PM
Olain said:
Thanks for the reply Alexander - The problem is the codes inside the script.. I dont get what: dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28; - Means, as i dont know what oD and % and ? is doing in there.. This code is mean to me to: oD.od=oD.getDay()+1; I dont get it.
That first line calculates number of days in February, whether it is a leap year or not
dim[1] means it addresses the second post in dim variable, and if you look at it above in your code, it keeps number of days in each month, but February is set to 0, as its recalculated with this line.
The rules of whether there is a leap year or not is if it's evenly dividable with four, but not if it's evenly dividable with 100, but it is if it's evenly dividable with 400
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









