// Kevin's Calendar // // // JavaScript Event Calendar // // Version: 1.0 // Date: November 15, 1998 // For information: http://members.aol.com/kevinilsen or kilsen@m-vation.com // // * This is a modification of the calendar by John Banister in mid-January 2008. // * It's available as www.John.Banister.name/Calendar2.txt (rename it to .js to use it) // * I'm building the table in the DOM fashion following the example set at // * http://developer.mozilla.org/en/docs/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces // * and many places at www.w3schools.com // * So it can be inserted in the manner suggested by James Edwards at // * http://www.sitepoint.com/blogs/2007/07/11/insert-in-place-without-documentwrite/ // * I marked added lines with //* and edited lines with //*--* // * // * Note: // * Instead of putting and // * // * // * If you use this with csvEvents2.js (available as www.John.Banister.name/csvEvents2.txt), // * you need to scroll down to just above the function ShowCalendar() below and remove one line. // * There's instructions in the comments there. If you use this with csvEvents2.js or any other // * script containing calls to DefineEvent, the tags // * have to appear in the web page AFTER the one with the reference to Calendar2.js , or else // * the browser thinks DefineEvent is a variable instead of a function, and it doesn't work. // Configurable values are set to defaults here; can override them before calling Calendar( ) from the HTML page var SpecialDay=1; // 1=Sunday, 2=Monday, . . . 7=Saturday var FontSize=25; var SmallFontSize=12; //* var ColorBackground="ffffcc"; var ColorSpecialDay = "red"; var ColorToday = "green"; var ColorEvent = "blue"; // Initialize the range of the calendar to Jan - Dec of the current year. Calls to DefineEvent( ) will change this // as needed; it is also possible to explicitly override the range before calling Calendar( ) from the HTML page. var today = new Date(); var FirstMonth=GetFullYear(today) * 100 + 1; var LastMonth=FirstMonth + 11; // Events[] is a SPARSE array; Call DefineEvent( ) to populate it var Events = new Array(); // Each event is defined by calling the DefineEvent( ) routine with the following parameters: // // DefineEvent(EventDate, EventDescription, EventLink, Image, Width, Height) // EventDate is a numeric value in the format YYYYMMDD // EvenDescription is a string that can include embedded HTML tags (e.g.,
, , etc.) // EventLink is the URL of the target page if a hyperlink is desired from this event entry // Image is the URL of the image if you want to display an image with this event // Width is the width of the image in pixels // Height is the height of the image in pixels function DefineEvent(EventDate, EventDescription, EventLink, Image, Width, Height) { var tmpPara = document.createElement('p') ; //*--* // Build the HTML string for this event: image (optional), link (optional), and description // * In this DOM version, if a paragraph already exists for that day, then it needs to // * append these objects, rather than tmpPara. If tmpLink exists, it needs to append the // * text & image first and then get appended in turn. // tmp = ""; // * When this wasn't working, the test if (EventLink = "") was the culprit, so I changed to length based tests if (Image.length > 3) { //*--* // tmp = tmp + ''; var tmpImage = document.createElement('Image') ; //* tmpImage.src = Image ; //* tmpImage.width = Width ; //* tmpImage.height = Height ; //* tmpImage.align = "left" ; //* if (EventLink.length < 3) { //* if (Events[EventDate]){ //* Events[EventDate].appendChild(tmpImage) ; //* } else { //* tmpPara.appendChild(tmpImage) ; //* } //* } //* } //*--* if (EventDescription.length > 0) { //* tmpText = document.createTextNode(EventDescription) ; //* if (EventLink.length < 3) { //* if (Events[EventDate]) { //* Events[EventDate].appendChild(document.createElement("br")) ; //* Events[EventDate].appendChild(tmpText) ; //* } else { //* tmpPara.appendChild(tmpText) ; //* } //* } //* } //* if (EventLink.length > 2) { //*--* // tmp = tmp + ''; // tmp = tmp + EventDescription; // if (EventLink != "") tmp = tmp + ''; var tmpLink = document.createElement('a') ; //* tmpLink.href = EventLink ; //* if (Image.length > 3) tmpLink.appendChild(tmpImage) ; //* if (EventDescription.length > 0) tmpLink.appendChild(tmpText) ; //* if (Events[EventDate]) { //* if (EventDescription.length > 0) { //* Events[EventDate].appendChild(document.createElement("br")) ; //* } //* Events[EventDate].appendChild(tmpLink) ; //* } else { //* tmpPara.appendChild(tmpLink) ; //* } //* } //*--* // If an event already exists for this date, append the new event to it. // * If no event already exists, then... if (!Events[EventDate]) Events[EventDate] = tmpPara ; //* // if (Events[EventDate]) // Events[EventDate] += "
" + tmp; // else // Events[EventDate] = tmp; // Adjust the minimum and maximum month & year to include this date tmp = Math.floor(EventDate / 100); if (tmp < FirstMonth) FirstMonth = tmp; if (tmp > LastMonth) LastMonth = tmp; } // Utility function to populate an array with values function arr() { for (var n=0;n 1) { yearmonth = parseInt(location.search.substring(1,location.search.length)); if ((""+yearmonth).length == 6) { mo = yearmonth % 100; yr = (yearmonth - mo) / 100; } } // Constrain to the range of months with events if (yearmonth < FirstMonth) { mo = FirstMonth % 100; yr = (FirstMonth - mo) / 100; yearmonth = FirstMonth; } if (yearmonth > LastMonth) { mo = LastMonth % 100; yr = (LastMonth - mo) / 100; yearmonth = LastMonth; } // Create a datae object for the first day of the desired month bgn = new Date(months[mo] + " 1," + yr); // Get the day-of-week of the first day, and the # days in the month dayofweek = bgn.getDay(); lastday = NumDaysIn(mo,yr); // document.write(""); TheCalendar.border = 2 ; //* TheCalendar.style.backgroundColor = "#" + ColorBackground ; //* TheCalendar.style.tableLayout = "fixed" //* var thisRow = document.createElement("tr") ; //* var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* thisCell.colSpan = 7 ; //* thisCell.style.fontSize = FontSize ; //* thisCell.style.fontWeight = 'bold' ; //* thisCellText = document.createTextNode(months[mo] + " " + yr) ; //* thisCell.appendChild(thisCellText) ; //* thisRow.appendChild(thisCell) ; //* CalendarTableBody.appendChild(thisRow) ; //* var thisRow = document.createElement("tr") ; //* for (var i=1;i<=7;i++){ // document.write(""); var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* thisCell.width = "14%" ; //* thisCell.style.fontSize = SmallFontSize ; //* thisCellText = document.createTextNode(weekdays[i]) ; //* thisCell.appendChild(thisCellText) ; //* thisRow.appendChild(thisCell) ; //* } // document.write(""); CalendarTableBody.appendChild(thisRow) ; //* var thisRow = document.createElement("tr") ; //* dy = 1; // Special handling for the first week of the month for (var i=1;i<=7;i++) { // If the day is less than the day of the // week determined to be the first day // of the month, print a space in // this cell of the table. var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* if (i <= dayofweek){ // document.write(""); thisCellText = document.createTextNode('\u00A0') ; //* thisCell.style.fontSize = FontSize ; //* thisCell.appendChild(thisCellText) ; //* } // Otherwise, write date and the event, // if any, in this cell of the table. else { ShowDate(yr,mo,dy,i,curmo,curdy,thisCell); //*--* dy++; } thisRow.appendChild(thisCell) ; //* } // document.write(""); CalendarTableBody.appendChild(thisRow) ; //* var thisRow = document.createElement("tr") ; //* // Rest of the weeks . . . while (dy <= lastday) { for (var i=1;i<=7;i++) { // If the day is greater than the last // day of the month, print a space in // this cell of the table. var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* if (dy > lastday) { // document.write(""); thisCellText = document.createTextNode('\u00A0') ; //* thisCell.appendChild(thisCellText) ; //* } // Otherwise, write date and the event, // if any, in this cell of the table. else { ShowDate(yr,mo,dy,i,curmo,curdy,thisCell); //*--* dy++; } thisRow.appendChild(thisCell) ; //* } // document.write(""); CalendarTableBody.appendChild(thisRow) ; //* var thisRow = document.createElement("tr") ; //* } // jump = ""; var jumpPara = document.createElement('p'); //* if (yearmonth > FirstMonth) { // jump += '<-- View '+months[PrevMonth(mo)]+''; var linkPrevious = document.createElement('a') ; //* linkPrevious.href = thispage + '?' + PrevYearMonth(yearmonth) ; //* var linkText = document.createTextNode("<-- View " + months[PrevMonth(mo)]) ; //* linkPrevious.appendChild(linkText) ; //* jumpPara.appendChild(linkPrevious) ; //* } if ((yearmonth > FirstMonth) && (yearmonth < LastMonth)){ // jump += "   |   "; var thisText = document.createTextNode("\u00A0 | \u00A0") ; //* jumpPara.appendChild(thisText) ; //* } if (yearmonth < LastMonth) { // jump += 'View '+months[NextMonth(mo)]+' -->'; var linkNext = document.createElement('a') ; //* linkNext.href = thispage + '?' + NextYearMonth(yearmonth) ; //* var linkText = document.createTextNode("View " + months[NextMonth(mo)] + " -->") ; //* linkNext.appendChild(linkText) ; //* jumpPara.appendChild(linkNext) ; //* } // document.write(""); CalendarTableBody.appendChild(thisRow) ; //* var thisRow = document.createElement("tr") ; //* var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* thisCell.colSpan = 7 ; //* thisCell.appendChild(jumpPara) ; //* thisRow.appendChild(thisCell) ; //* CalendarTableBody.appendChild(thisRow) ; //* // document.write("
"+months[mo]+" "+yr+"
"+weekdays[i]+"
 
 
"+jump+"
Jump to month:  "); var thisRow = document.createElement("tr") ; //* var thisCell = document.createElement("td") ; //* thisCell.align = "center" ; //* thisCell.colSpan = 7 ; //* thisCell.vAlign = "middle" ; //* var selectMonth = document.createElement("form") ; //* var formText = document.createTextNode("Jump to month:\u00A0\u00A0") ; //* selectMonth.appendChild(formText) ; //* var monthDropdown = document.createElement("select") ; //* BuildSelectionList(yearmonth, thispage, monthDropdown) ; //*--* // document.write("
"); selectMonth.appendChild(monthDropdown) ; //* thisCell.appendChild(selectMonth) ; //* thisRow.appendChild(thisCell) ; //* CalendarTableBody.appendChild(thisRow) ; //* TheCalendar.appendChild(CalendarTableBody) ; //* } // Display a date in the appropriate color, with events (if there are any) function ShowDate(yr, mo, dy, dayofweek, currentmonth, currentday, thisCell) { //*--* var ind, HighlightEvent, tmp; // document.write("

 "; thisCell.appendChild(MonthDayPara) ; //* EventText = document.createTextNode('\u00A0') ; //* var EventPara = document.createElement('p') ; //* EventPara.style.fontSize = SmallFontSize ; //* EventPara.appendChild(EventText) ; //* EventPara.appendChild(document.createElement("br")) ; //* EventPara.appendChild(EventText) ; //* thisCell.appendChild(EventPara) ; //* } // document.write(">"+dy+"

"+tmp+""); } // Remaining routines are utilities used above function NumDaysIn(mo,yr) { if (mo==4 || mo==6 || mo==9 || mo==11) return 30; else if ((mo==2) && LeapYear(yr)) return 29; else if (mo==2) return 28; else return 31; } function LeapYear(yr) { if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0) return true; else return false; } // fixes a Netscape 2 and 3 bug function GetFullYear(d) { // d is a date object var yr; yr = d.getYear(); if (yr < 1000) yr +=1900; return yr; } function PrevMonth(mth) { if (mth == 1) return 12; else return (mth-1); } function NextMonth(mth) { if (mth == 12) return 1; else return (mth+1); } function PrevYearMonth(yrmth) { if ((yrmth % 100) == 1) return ((yrmth-100)+11); else return (yrmth-1); } function NextYearMonth(yrmth) { if ((yrmth % 100) == 12) return ((yrmth-11)+100); else return (yrmth+1); } // My brother-in-law, a professional programmer with // strong Java skills working for University of Syracuse // commended to me a tutorial page: // http://sharkysoft.com/tutorials/jsa/content/025.html // so I changed document.location to window.location below function JumpTo(calendar, thispage) { var sel, yrmo; sel = calendar.selectedIndex; yrmo = calendar.form.jumpmonth[sel].value; window.location = thispage + "?" + yrmo; //*--* } function BuildSelectionList(current,thispage, monthDropdown) { //*--* var mo, yr, yearmonth; yearmonth = FirstMonth; // document.write(""); }