Hi everyone,
I have just created a calendar which highlights days IF an event is planend for that day.
I read the content of a text file using a XMLHttpRequest for Firefox and an ActiveXObject. Its working just fine as I can have the content of the file showing into a div element.
Now when I'm parsing that file I change boolean flags in an array of 31 elements. When I draw the calendar I check for each day, if the flag for that day is true I do something special.
It's working very well in IE, however in Firefox for some reason the calendar get drawn first! Then the flags are changed according to my data in the files. Needless to say it doesn't work at all that way. It just seems that Firefox isn't waiting for my for loop to finish before moving on.
Any suggestion?
Here is the function I use to parse the text file and draw the calendar. Again this would work just fine if Firefox would wait for the getFile to be over...yes getFile is called before makeCalendar(...)
Sorry for the crappy code, I'm in the middle of debugging (or trying to)
Thanks for any reply, suggestions, answers. I appreciate it.
I have just created a calendar which highlights days IF an event is planend for that day.
I read the content of a text file using a XMLHttpRequest for Firefox and an ActiveXObject. Its working just fine as I can have the content of the file showing into a div element.
Now when I'm parsing that file I change boolean flags in an array of 31 elements. When I draw the calendar I check for each day, if the flag for that day is true I do something special.
It's working very well in IE, however in Firefox for some reason the calendar get drawn first! Then the flags are changed according to my data in the files. Needless to say it doesn't work at all that way. It just seems that Firefox isn't waiting for my for loop to finish before moving on.
Any suggestion?
Here is the function I use to parse the text file and draw the calendar. Again this would work just fine if Firefox would wait for the getFile to be over...yes getFile is called before makeCalendar(...)
Sorry for the crappy code, I'm in the middle of debugging (or trying to)
Thanks for any reply, suggestions, answers. I appreciate it.
Code:
//=============================================================================
function makeCalendar(mth, year, cssFrame, cssHeading, cssDOfWeek, cssDay,
brdWidth)
//=============================================================================
/*Parameters :
* mth : identify which mth do you want the calendar for
*/
{
//Create a date object with the current date passed as param
var oD = new Date(year, mth-1, 1);
//Workaround if the month have 31 days
oD.od=oD.getDay()+1;
//Get the current date
var todaydate=new Date()
//Set scantoday to the today's date IF today is in the current year/month
//else set to 0
var scantoday=(
year==todaydate.getFullYear() && mth==todaydate.getMonth()+1
) ? todaydate.getDate() : 0
//Check for leap year and set the number of days in February
//according to the result. A year is a leap year IF
//Its a multiple of 100, 4 or 400
daysInMth[1]=( ( (oD.getFullYear()%100!=0) && (oD.getFullYear()%4==0) )
|| (oD.getFullYear()%400==0) )
?29:28;
//Now we prepare the HTML to construct the calendar
//Define the main layout table
var t='<div class="'+cssFrame+'"><table class="'+cssFrame+'" cols="7" cellpadding="0" border="'+ brdWidth+'" cellspacing="0">';
//Open a new table row
t+='<tr align="center">';
t+='<td colspan="7" align="center" class="'+cssHeading+'">'+mthOfYr[mth-1]+' - '+year+'</td></tr> <tr align="center">';
for(i=0;i<7;i++)
t+='<td class="'+cssDOfWeek+'"><em>'+daysOfTheWeek[i]+'</em></td>';
t+='</tr><tr align="center">';
for(i=1;i<=42;i++){
var x=( (i-oD.od >= 0) && (i-oD.od < daysInMth[mth-1]) ) ? i-oD.od+1 : ' ';
//alert(arrEvents[i]);
if (x == scantoday){
x='<span id="today">'+x+'</span>';
t+='<td class="'+cssDay+'">'+x+'</td>';
}
else if( (x!=' ') && (arrEvents[x-1]) ){
var day = x;
x='<span id="events">'+x+'</span>';
t+='<td class="'+daysEvents+'" onClick="showDesc('+day+')">'+x+'</td>';
}
else
t+='<td class="'+cssDay+'">'+x+'</td>';
if( ((i)%7==0) && (i<36) )
t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
} //END FUNCTION makeCalendar
//=============================================================================
function displayEvents()
//=============================================================================
{
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
var tmpArr=xmlhttp.responseText.split('\n');
for (var idx = 0; idx < tmpArr.length; idx++) {
tmp=tmpArr[idx];
if(tmp.substring(0,1) == '['){
var evYear = tmp.substring(1,5);
var evMonth = tmp.substring(6,8);
var evDay = tmp.substring(9,11);
if(evYear==curyear && evMonth==curmonth){
//alert(evDay+' '+tmpArr[idx+1])
//alert('changing to true now!!');
arrEvents[(evDay-1)] = true;
arrEventsDesc[(evDay-1)] = tmpArr[(idx+1)];
}
}
}
for(var i=0; i < arrEvents.length; i++){
//alert('i = '+(i+1)+' '+arrEvents[i][0]+' '+arrEvents[i][1]);
if(arrEvents[i]){
var description = arrEventsDesc[i].split('//');
for(var j=0; j<description.length; j++)
out += description[j]+'<br>';
}
}
//document.getElementById('theExample').innerHTML=out;
}
}
}