Skip to content

Instantly share code, notes, and snippets.

@mtwstudios
Created December 30, 2010 19:56
Show Gist options
  • Save mtwstudios/760204 to your computer and use it in GitHub Desktop.
Save mtwstudios/760204 to your computer and use it in GitHub Desktop.
/* author : eric thul
* date : 2006.05.08
* title : display.js
* version : 1.0
*
* includes methods for displaying the xml
* of the webcalendar and loads the data
* via xmlhttprequest
*
* note that this file calls functions from
* minical.js
*/
/* --------------------------------------------------------
* BEGIN - general functions
* -------------------------------------------------------- */
function d_general_monname(mon)
{
var months = [
'January','February','March','April',
'May','June','July','August',
'September','October','November','December'
];
return months[mon];
}
function d_general_abbrmon_rev(mon)
{
var months = {
'Jan':0,'Feb':1,'Mar':2,'Apr':3,
'May':4,'Jun':5,'Jul':6,'Aug':7,
'Sep':8,'Oct':9,'Nov':10,'Dec':11
}
return months[mon];
}
function d_general_weeknames(day)
{
var days = [
'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'
];
return days[day];
}
function d_general_sortmil(a,b)
{
if (parseInt(a.sortby) < parseInt(b.sortby))
return -1;
else if (parseInt(a.sortby) > parseInt(b.sortby))
return 1;
else
return 0;
}
function d_general_fdate(date)
{
var day = date.day
var month = d_general_monname(date.month);
var year = date.year;
if (day < 10)
day = '0'+day;
return day+'-'+month.substring(0,3)+'-'+year;
}
function d_general_parsedate(datestr)
{
var re = /(\d{1,2})\-([a-zA-Z]+)\-(\d\d\d\d)/;
var date = re.exec(datestr);
if (date && date.length == 4)
return new Date(date[3],d_general_abbrmon_rev(date[2]),date[1]);
}
function d_general_indatespan(cal,date)
{
var date_begin = d_general_parsedate(cal.datebegin);
var date_end = d_general_parsedate(cal.dateend);
var date_today = d_general_parsedate(date);
if (date_begin <= date_today && date_today <= date_end)
{
if (d_general_validrepeat(cal.repeat,date_begin.getDay(),date_today))
return 1;
}
return 0;
}
function d_general_validrepeat(repeat,weeklyday,date)
{
if (repeat == 'Daily')
{
return 1;
}
else if (repeat == 'Mon.-Fri.')
{
if (date.getDay() > 0 && date.getDay() < 6)
return 1;
}
else if (repeat == 'Weekly')
{
if (date.getDay() == weeklyday)
return 1;
}
return 0;
}
/* from: http://www.irt.org/script/1142.htm */
function d_general_daysadd(date,days)
{
return new Date(date.getTime()+days*24*60*60*1000);
}
function d_general_mil(hour,min,ampm)
{
var milhour = '';
if (hour == 12 && ampm.toUpperCase() == "AM")
milhour = 0;
//else if (hour != 12 && ampm.toUpperCase() == "PM")
// milhour = parseInt(hour)+12;
else if (hour != 12 && ampm.toUpperCase() == "PM")
{
//pareInt returns 0 for 08 and 09 because of octals
if(hour.charAt(0) == '0')
hour = hour.substring(1, hour.length);
milhour = parseInt(hour)+12;
}
else
milhour = hour;
return ''+milhour+min;
}
function d_general_xmltohash(xml,keylist)
{
var xmltable = {};
for (var i=0; i < keylist.length; i++)
{
var node = xml.getElementsByTagName(keylist[i]);
if (node[0] && node[0].firstChild)
xmltable[keylist[i]] = node[0].firstChild.nodeValue;
else
xmltable[keylist[i]] = '';
}
return xmltable;
}
function d_general_cdata(caldata,guid)
{
var keys = new Array(
'datebegin','dateend','timebegin','timeend',
'contactname','contactphone','contactemail',
'location','sponsor','repeat'
);
var xml = '';
if (window.ActiveXObject)
{
xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async="false";
xml.loadXML(caldata);
}
else
xml = (new DOMParser()).parseFromString(caldata, "text/xml");
var cdata = d_general_xmltohash(xml,keys);
// set the id of the alert
cdata.id = guid;
// set the value to sort by
var re = /(\d+):(\d+) (AM|PM)/i;
var matches = re.exec(cdata.timebegin);
if (matches && matches.length == 4)
cdata.sorttime = d_general_mil(matches[1],matches[2],matches[3]);
return cdata;
}
function d_general_parse_uri(uri)
{
var uristr = uri+'';
var uriar = uristr.split('?');
var uriobj = {};
if (uriar.length == 2)
{
var pairs = uriar[1].split('&');
for (var i=0; i < pairs.length; i++)
{
var keyval = pairs[i].split('=');
uriobj[keyval[0]] = keyval[1];
}
}
return uriobj;
}
/* --------------------------------------------------------
* END - general functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGIN - day parsing functions
* -------------------------------------------------------- */
function d_day_getlink(date,img)
{
var html = '';
var ipath = 'https://jedi.tcnj.edu/webteam/webcal/img/';
var onclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','day',
{year:date.year,month:date.month},date.day
);
html = '<a href="#" onclick="'+onclick+'">'
+ '<img src="'+ipath+img+'_day.gif" alt="'+img+'month"'
+ ' width="16" height="16" align="absmiddle" />'
+ '</a>';
return html;
}
function d_day_captionpn(year,month,day)
{
var date = {year: '',month: '',day: ''};
// get total days in month
var totaldays = getmonthdays(year,month);
if (day > totaldays) //next month
{
tmpdate = getpndate(year,month+1);
date.year = tmpdate.year;
date.month = tmpdate.month;
date.day = 1;
}
else if (day < 1) //prev month
{
tmpdate = getpndate(year,month-1);
date.year = tmpdate.year;
date.month = tmpdate.month;
date.day = getmonthdays(date.year,date.month);
}
else
{
date.year = year;
date.month = month;
date.day = day;
}
return date;
}
function d_day_caption(date,week)
{
var odate = new Date(date.year,date.month,date.day);
var html = '';
var prev_link = d_day_getlink(
d_day_captionpn(date.year,date.month,date.day-1),'previous'
);
var next_link = d_day_getlink(
d_day_captionpn(date.year,date.month,date.day+1),'next'
);
html += d_general_weeknames(odate.getDay())+', '
+d_general_monname(odate.getMonth())+' '+date.day;
if (week)
return '<caption>'+html+'</caption>';
else
return '<caption>'+prev_link+'&nbsp;'+html+'&nbsp;'+next_link+'</caption>';
}
function d_day_head()
{
var html = '';
html += '<tr>'
+ '<th width="70px" scope="col">Time</th>'
+ '<th scope="col">Title</th>'
+ '<th width="100px" scope="col">Location</th>'
+ '</tr>';
return html;
}
function d_day_row(title,calendar_data,date,week)
{
var html = '';
var onclick = genonclick(
GLOBAL_WEBCALID,calendar_data.id,'calendar','view','event',
{year:date.year,month:date.month},date.day,week ? 'week' : 'day'
);
html += '<tr>'
+ '<td>'+calendar_data.timebegin+'</td>'
+ '<td><a href="#" onclick="'+onclick+'">'+title+'</a></td>'
+ '<td>'+calendar_data.location+'</td>';
return html;
}
/* --------------------------------------------------------
* END - day parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGIN - week parsing functions
* -------------------------------------------------------- */
function d_week_pnlinks(date)
{
var html = '';
var prevmy = new Date(date.year,date.month,date.day-7);
var nextmy = new Date(date.year,date.month,date.day+7);
var ponclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:yeartest(prevmy.getYear()),month:prevmy.getMonth()},
prevmy.getDate()
);
var nonclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:yeartest(nextmy.getYear()),month:nextmy.getMonth()},
nextmy.getDate()
);
html += '<p><a href="#" onclick="'+ponclick+'">&laquo; '
+'Previous Week</a> || ';
html += '<a href="#" onclick="'+nonclick+'">'
+' Next Week'
+' &raquo;</a></p>';
return html;
}
/* --------------------------------------------------------
* END - week parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGIN - event parsing functions
* -------------------------------------------------------- */
function d_event_genhtml_cal(cal,date)
{
var html = '';
var re = /(\d+)\-([a-zA-Z]+)\-(\d\d\d\d)/;
var odate = new Date(date.year,date.month,date.day);
/* this is so that when an event spans multiple
* days, the date shown for the event will be
* today's date, not the start date of the
* event */
var begindatestr = cal.datebegin != cal.dateend ?
odate.getDate()+'-'+
d_general_monname(odate.getMonth()).substring(0,3)+'-'+
yeartest(odate.getYear())
: cal.datebegin;
var matches = re.exec(begindatestr);
var endtimestr = cal.timeend != '12:01 AM' ?
' from '+cal.timebegin+' to '+cal.timeend : ' at '+cal.timebegin;
html += '<ul>';
if (matches.length == 4)
{
html += '<li><strong>Date &amp; Time:</strong> '
+ d_general_weeknames(odate.getDay())+', '+matches[2]+' '
+ matches[1]+endtimestr+'</li>';
}
else
{
/* this might need fixing, not sure when this code
* is reached. but the begindatestr might need
* to be used */
html += '<li><strong>Date &amp; Time:</strong> '+cal.datebegin
+ endtimestr+'</li>';
}
html += '<li><strong>Location:</strong> '+cal.location+'</li>';
html += '<li><strong>Contact:</strong> <a href="mailto:'+cal.contactemail
+'">'+cal.contactemail+'</a>'+(cal.contactphone?'; '+cal.contactphone:'')+'</li>';
html += '<li><strong>Sponsor(s):</strong> '+cal.sponsor+'</li>';
html += '</ul>';
html += '<p style="margin-top: 12px">';
html += '<a href="https://jedi.tcnj.edu/webteam/cgi-bin/webalerts/script/iCalendar.pl?id='+cal.id+'">';
html += '<img src="img/calendar_16.gif" alt="calendar icon" align="absmiddle"/>';
html += '</a>&nbsp;';
html += '<a href="https://jedi.tcnj.edu/webteam/cgi-bin/webalerts/script/iCalendar.pl?id='+cal.id+'">';
html += 'Download Event</a>';
html += '</p>';
return html;
}
function d_event_genhtml_foot(date,back)
{
var html = '';
var view = '';
var odate = '';
var returndate = '';
if (back == 'month')
{
view = 'month';
odate = new Date(date.year,date.month,1);
returndate = d_general_monname(odate.getMonth());
}
else if (back == 'week')
{
var tmpdate = {};
var monthdays;
view = 'week';
odate = new Date(date.year,date.month,date.day);
if (date.day-odate.getDay() < 1)
{
tmpdate = getpndate(yeartest(odate.getYear()),odate.getMonth()-1);
monthdays = getmonthdays(yeartest(tmpdate.year),tmpdate.month);
tmpdate.day = monthdays + (date.day-odate.getDay());
}
else
{
tmpdate.year = yeartest(odate.getYear());
tmpdate.month = odate.getMonth();
tmpdate.day = date.day - odate.getDay();
}
returndate = 'the Week of '
+ d_general_monname(tmpdate.month)+' '+tmpdate.day;
date.year = tmpdate.year;
date.month = tmpdate.month;
date.day = tmpdate.day;
}
else
{
view = 'day';
odate = new Date(date.year,date.month,date.day);
returndate = d_general_weeknames(odate.getDay())
+ ', '+d_general_monname(odate.getMonth())+' '+date.day;
}
var onclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view',view,{year:date.year,month:date.month},date.day
);
//html += '<p><a href="http://www.tcnj.edu/~it/web/rss/">'
// + ' <img src="http://www.tcnj.edu/~it/web/webalerts/media/subscribe_rss.gif"'
// + ' alt="xml icon" align="absmiddle" border="0" height="15" width="81" />'
// + ' </a></p>';
html += '<hr />';
html += '<img src="https://jedi.tcnj.edu/webteam/webcal/img/previous_day.gif"'
+ ' alt="previous" width="16" height="16" align="absmiddle" />'
+ ' <a href="#" onclick="'+onclick+'">'
+ ' <strong>Return to Events for '+returndate+'</strong></a>';
return html;
}
function d_event_genhtml(title,descr,cal,date,guid,back)
{
var html = '';
html += '<h2>'+title+'</h2>';
html += '<p>'+descr+'</p>'
// specific event information
html += d_event_genhtml_cal(cal,date,guid);
// event footer
html += d_event_genhtml_foot(date,back);
return html;
}
/* --------------------------------------------------------
* END - event parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGIN - month parsing functions
* -------------------------------------------------------- */
/* relies on minical.js */
function d_month_calcdays(date)
{
var days = {current:'',previous:'',next:'',first:''};
var cal = new Date(date.year,date.month,date.day);
var monthdays = getmonthdays(yeartest(cal.getYear()),cal.getMonth());
// day of week for next and previous month
var nextdays = 6-new Date(yeartest(cal.getYear()),cal.getMonth(),monthdays).getDay();
var prevdays = new Date(yeartest(cal.getYear()),cal.getMonth(),1).getDay();
var monthprev = '';
if (cal.getMonth() == 0)
monthprev = getmonthdays(yeartest(cal.getYear())-1,11);
else
monthprev = getmonthdays(yeartest(cal.getYear()),cal.getMonth()-1);
// fill the hash
days.current = monthdays;
days.previous = monthprev;
days.next = nextdays;
days.first = prevdays;
return days;
}
function d_month_pevents_pn(date)
{
// previous
if (date.month < 0)
return {year:date.year-1,month:11};
else if (date.month > 11)
return {year:date.year+1,month:0};
else
return {year:date.year,month:date.month};
}
function d_month_pevents_format(title,cal,date,day) //8-28-2006 - cp, added day so format would use the day for the event rather than just the first day of the month
{
var html = '';
var onclick = genonclick(
GLOBAL_WEBCALID,cal.id,'calendar','view','event',
{year:date.year,month:date.month},day,'month'
);
html += '<p><a href="#" onclick="'+onclick+'">'+title+'</a></p>';
return html;
}
function d_month_pevents_match(matches,date,cal,title,currar,prevar,nextar)
{
// get month numbers and years
var currmy = {year:date.year,month:date.month};
var prevmy = d_month_pevents_pn(
{year:date.year,month:date.month-1,day:date.day}
);
var nextmy = d_month_pevents_pn(
{year:date.year,month:date.month+1,day:date.day}
);
var item_mon = matches[1];
var item_year = matches[2];
var item_day = '';
if (matches[0].charAt(0) == '0')
item_day = parseInt(matches[0].charAt(1));
else
item_day = parseInt(matches[0]);
// cases for prev,curr,next months
if (
(item_mon == currmy.month && item_year == currmy.year)
)
{
if (typeof(currar[item_day-1]) == "undefined")
currar[item_day-1] = '';
currar[item_day-1] += d_month_pevents_format(title,cal,date,matches[0]); //8-28-2006 - cp, added matches[0] so format knows the date of the event
}
else if (item_mon == prevmy.month && item_year == prevmy.year)
{
if (typeof(prevar[item_day-1]) == "undefined")
prevar[item_day-1] = '';
prevar[item_day-1] += d_month_pevents_format(title,cal,date,matches[0]); //8-28-2006 - cp, added matches[0] so format knows the date of the event
}
else if (item_day <= nextar.length
&& item_mon == nextmy.month
&& item_year == nextmy.year
)
{
if (typeof(nextar[item_day-1]) == "undefined")
nextar[item_day-1] = '';
nextar[item_day-1] += d_month_pevents_format(title,cal,date,matches[0]); //8-28-2006 - cp, added matches[0] so format knows the date of the event
}
}
function d_month_pevents(xml,date,currar,prevar,nextar)
{
// query items from the xml
var items = xml.getElementsByTagName('item');
var re_xml = /^<\?xml version="1\.0"\?>/;
var datebegin = '';
var dateend = '';
// filter events
for (var i=0; i < items.length; i++)
{
var cdatanode = '';
var weeklyday = '';
var guid =
items[i].getElementsByTagName('guid')[0].firstChild.nodeValue;
var title =
items[i].getElementsByTagName('title')[0].firstChild.nodeValue;
var descr_node = items[i].getElementsByTagName('description');
if (descr_node && descr_node.length)
{
cdatanode =
descr_node[0].childNodes[descr_node[0].childNodes.length-1];
}
/* this would be idea, but of course IE
* does not support 'CDATASection'
* if (cdatanode instanceof CDATASection) */
if (cdatanode && re_xml.test(cdatanode.nodeValue))
{
var calendar_data = d_general_cdata(
cdatanode.nodeValue,guid
);
var count = 0;
datebegin = d_general_parsedate(calendar_data.datebegin);
dateend = d_general_parsedate(calendar_data.dateend);
// store this for a weekly repeat
weeklyday = datebegin.getDay();
// an event can span more than one day
// so add it to each day in the month view
// where the day is in the span
while (datebegin <= dateend && count < 60)
{
// this count is here so that if say an
// event spans a year, the while loop
// wont loop for 365 days. it will stop
// after 60, since we only see one month
// and a little in the next/prev month
// at a time
count++;
if (!d_general_validrepeat(
calendar_data.repeat,weeklyday,datebegin
))
{
datebegin = d_general_daysadd(datebegin,1);
continue;
}
var eventdate = new Array(
datebegin.getDate()+'',datebegin.getMonth(),
yeartest(datebegin.getYear())
);
d_month_pevents_match(
eventdate,date,calendar_data,title,
currar,prevar,nextar
);
datebegin = d_general_daysadd(datebegin,1);
}
}
}
}
function d_month_headlinks(date)
{
var html = '';
var prevmy = d_month_pevents_pn({year:date.year,month:date.month-1,day:date.day});
var nextmy = d_month_pevents_pn({year:date.year,month:date.month+1,day:date.day});
var ponclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','month',
{year:prevmy.year,month:prevmy.month},date.day
);
var nonclick = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','month',
{year:nextmy.year,month:nextmy.month},date.day
);
html += '<tr>';
html += '<td width="150"><h3><a href="#" onclick="'+ponclick+'">&laquo; '
+d_general_monname(prevmy.month)+' '+prevmy.year+'</a></h3></td>';
html += '<th><h2>'+d_general_monname(date.month)+' '+date.year+'</h2></th>';
html += '<td width="150"><h3 align="right"><a href="#" onclick="'+nonclick+'">'
+d_general_monname(nextmy.month)+' '+nextmy.year
+' &raquo;</a></h3></td>';
html += '</tr>';
return html;
}
function d_month_header()
{
var html = '';
var weeknames = [
'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'
];
html += '<tr>';
for (var i=0; i < weeknames.length; i++)
html += '<th width="14%">'+weeknames[i]+'</th>';
html += '</tr>';
return html;
}
function d_month_days(date,curr,prev,next,first)
{
var html = '';
var pndate = '';
var row = '';
var events = '';
var cal = new Date(date.year,date.month,date.day);
// loop through the calendar days
for (
var i=0,j=0,k=0,c=first-1;
i < (curr.length+first+next.length);
i++
)
{
var day = '';
// finished filling a row
if (i && i%7==0)
{
html += '<tr valign="top">'+row+'</tr>';
row = '';
}
// cases for previous, current, and next month
if (i < first)
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth()-1);
day = prev.length-c;
events = prev[day-1] ? prev[day-1] : '';
c--;
}
else if (i >= first && i < (curr.length+first))
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth());
day = j+1;
events = curr[day-1] ? curr[day-1] : '';
j++;
}
else
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth()+1);
day = k+1;
events = next[day-1] ? next[day-1] : '';
k++;
}
row += '<td><h3>'+day+events+'</h3></td>';
}
// add the last row
html += '<tr valign="top">'+row+'</tr>';
return html;
}
/* --------------------------------------------------------
* END - month parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGIN - view select parsing functions
* -------------------------------------------------------- */
function d_selectview_day(date,monthoc)
{
var html = '';
var doweek = new Date(date.year,date.month,date.day).getDay();
var odate = new Date(
date.year,date.month,parseInt(date.day)-parseInt(doweek)
);
var weekoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:yeartest(odate.getYear()),month:odate.getMonth()},odate.getDate()
);
html += '<strong>Day</strong> | <a href="#" onclick="'+weekoc+'">Week</a> | '
+ '<a href="#" onclick="'+monthoc+'">Month</a>';
return html;
}
function d_selectview_week(date,todayoc,monthoc)
{
var html = '';
/*var dayoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','day',
{year:date.year,month:date.month},date.day
);*/
html += '<a href="#" onclick="'+todayoc+'">Day</a> | <strong>Week</strong> | '
+ '<a href="#" onclick="'+monthoc+'">Month</a>';
return html;
}
function d_selectview_month(today,todayoc)
{
var html = '';
var odate = new Date(
yeartest(today.getYear()),today.getMonth(),
parseInt(today.getDate())-parseInt(today.getDay())
);
var beginweekoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:yeartest(odate.getYear()),month:odate.getMonth()},
odate.getDate()
);
html += '<a href="#" onclick="'+todayoc+'">Day</a> | '
+ '<a href="#" onclick="'+beginweekoc+'">Week</a> | '
+ '<strong>Month</strong>';
return html;
}
function d_selectview_event(today,todayoc,monthoc,date)
{
var html = '';
var beginweekoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:yeartest(today.getYear()),month:today.getMonth()},
parseInt(today.getDate())-parseInt(today.getDay())
);
/*
var beginweekoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','week',
{year:date.year,month:date.month},date.day
);*/
html += '<a href="#" onclick="'+todayoc+'">Day</a> | '
+ '<a href="#" onclick="'+beginweekoc+'">Week</a> | '
+ '<a href="#" onclick="'+monthoc+'">Month</a>';
return html;
}
/* --------------------------------------------------------
* END - view select parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGINMAIN - main parsing functions
* -------------------------------------------------------- */
function d_event_parse(xml,date,eid,back)
{
// query items from the xml
var items = xml.getElementsByTagName('item');
var html = '';
for (var i=0; i < items.length; i++)
{
guid = items[i].getElementsByTagName('guid')[0].firstChild.nodeValue;
if (guid == eid)
{
var title =
items[i].getElementsByTagName('title')[0].firstChild.nodeValue;
var descr_node = items[i].getElementsByTagName('description');
var descr = '';
var cdata = '';
if (descr_node && descr_node.length)
{
if (descr_node[0].childNodes.length == 2)
{
descr = descr_node[0].childNodes[0].nodeValue;
cdata = descr_node[0].childNodes[1].nodeValue;
}
else
cdata = descr_node[0].childNodes[0].nodeValue;
}
if (cdata)
{
calendar_data = d_general_cdata(cdata,guid);
html = d_event_genhtml(title,descr,calendar_data,date,guid,back);
}
}
}
return html;
}
function d_day_parse(xml,date,week)
{
// query items from the xml
var items = xml.getElementsByTagName('item');
var datestr = d_general_fdate(date);
var events = new Array();
var html = "";
// filter events
for (var i=0,j=0; i < items.length; i++)
{
var xmltable = d_general_xmltohash(items[i],['guid','title']);
var descr_node = items[i].getElementsByTagName('description');
var descr = '';
var cdata = '';
if (descr_node && descr_node.length)
{
if (descr_node[0].childNodes.length == 2)
{
descr = descr_node[0].childNodes[0].nodeValue;
cdata = descr_node[0].childNodes[1].nodeValue;
}
else
cdata = descr_node[0].childNodes[0].nodeValue;
}
if (cdata)
{
var calendar_data = d_general_cdata(cdata,xmltable.guid);
// display the event if the datestr is
// in the span of the event
if (d_general_indatespan(calendar_data,datestr))
{
events[j++] = {
html: d_day_row(xmltable.title,calendar_data,date,week),
sortby: calendar_data.sorttime
};
}
}
}
// sort the array by the military time
events.sort(d_general_sortmil);
// generate html
html += '<table border="0" cellspacing="0" cellpadding="0" '
+'width="75%" class="matrix1">';
html += d_day_caption(date,week);
html += d_day_head();
for (var i=0; i < events.length; i++)
html += events[i].html;
html += '</table>';
return html;
}
function d_week_parse(xml,date)
{
var html = '';
var monthdays = getmonthdays(date.year,date.month);
// generate data for a week
for (var i=date.day; i < date.day+7; i++)
{
var j = i;
var pndate = {year:date.year,month:date.month};
if (i > monthdays)
{
j -= monthdays;
pndate = getpndate(date.year,date.month+1);
}
html += d_day_parse(xml,{year:pndate.year,month:pndate.month,day:j},1);
}
html += d_week_pnlinks(date);
return html;
}
function d_month_parse(xml,date)
{
var html = '';
// create arrays to hold the items
// with len = days to display for
// that month
var days = d_month_calcdays(date);
var currar = new Array(days.current);
var prevar = new Array(days.previous);
var nextar = new Array(days.next);
// iterate through the xml and
// fill each array with events
d_month_pevents(xml,date,currar,prevar,nextar);
// generate the top head links
html += '<table width="100%">';
html += d_month_headlinks(date);
html += '</table>';
// generate calendar header
html += '<table width="100%" border="0" cellspacing="0" '+
'cellpadding="0" class="matrix1">';
html += d_month_header(date);
html += d_month_days(date,currar,prevar,nextar,days.first);
html += '</table>';
return html;
}
function d_selectview(view,date)
{
var html = '';
var today = new Date();
var todayoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','day',
{year:yeartest(today.getYear()),month:today.getMonth()},
today.getDate()
);
var monthoc = genonclick(
GLOBAL_WEBCALID,0,'calendar','view','month',
{year:date.year,month:date.month},1
);
html += '<div style="margin: 0; padding: .5em; color: #a67a00; font-size: .9em;">';
if (view != 'event')
html += 'View: ';
if (view == "day")
html += d_selectview_day(date,monthoc);
else if (view == "week")
html += d_selectview_week(date,todayoc,monthoc);
else if (view == "month")
html += d_selectview_month(today,todayoc);
//else if (view == "event")
// html += d_selectview_event(today,todayoc,monthoc,date);
html += '</div>';
return html;
}
/* --------------------------------------------------------
* ENDMAIN - main parsing functions
* -------------------------------------------------------- */
/* --------------------------------------------------------
* BEGININIT - xmlreq init function
* initializes the request and fetches the data from the xml
* file gid.xml and inserts html within the tag with
* id="target"
* -------------------------------------------------------- */
var loadedreq;
function init(gid,eid,target,vtarget,view,year,mon,day,back)
{
var spinner = document.getElementById("spinner");
spinner.style.display = "block";
var date = { year: year, month: mon, day: day };
var hdl = {
onComplete: function(xml,q) {
var tag = document.getElementById(target);
var viewtag = document.getElementById(vtarget);
var html = "";
if (view == "event")
html += d_event_parse(xml,date,eid,back);
else if (view == "day")
html += d_day_parse(xml,date);
else if (view == "week")
html += d_week_parse(xml,date);
else if (view == "month")
html += d_month_parse(xml,date);
else
alert("!!!error on view="+view);
viewtag.innerHTML = d_selectview(view,date);
tag.innerHTML = html;
spinner.style.display = "none";
}
};
// load the mini cal
load_cal('minical',date.year,date.month,date.day,view);
// load the xml document
if (loadedreq==undefined) {
//console.warn("CACHE MISS! : (");
var req = new Request;
if (GLOBAL_BEAST)
req.init('http://www.tcnj.edu/~dadt/webalerts/rss/webcal/'+gid+'.xml');
else
req.init('1059.xml');
loadedreq = req;
req.loadXMLDoc(hdl,'');
} else {
//console.info("CACHE HIT! : )");
req = loadedreq;
//console.log(req);
hdl.onComplete(req.req.responseXML,req.query);
}
}
/* --------------------------------------------------------
* ENDINIT - xmlreq init function
* -------------------------------------------------------- */
/* author : eric thul
* title : minical
* date : 2006.05.08
* version : 1.0
*
* javascript mini calendar to
* select the day/week/month
*/
// --------------------------------------
// ie returns 2006, mozilla returns 106
// from new Date().getYear()
function yeartest(year)
{
if (navigator.appName == "Microsoft Internet Explorer")
return year;
else
return year+1900;
}
function monthname(id)
{
var months = [
'January','February','March',
'April','May','June',
'July','August','September',
'October','November','December'
];
return months[id];
}
function genonclick(xml,eid,target,vtarget,view,yearmon,day,back)
{
var html = '';
var year = yearmon.year;
var month = yearmon.month;
var day = day;
html += 'init('
+xml+',\''+eid+'\',\''+target+'\',\''+vtarget+'\',\''
+view+'\','+year+','+month+','+day+',\''+(back?back:'')+'\''
+')';
return html;
}
function weekdayheads()
{
var heads = ['S','M','T','W','T','F','S'];
html = '';
for (var i=0; i < heads.length; i++)
html += '<td>'+heads[i]+'</td>';
return '<tr>'+html+'</tr>';
}
function highlightrow(cal,view,pndate,day)
{
var onclick = genonclick(GLOBAL_WEBCALID,0,'calendar','view','day',pndate,day);
var row = '';
if (view == "day")
{
if (day == cal.getDate()
&& cal.getMonth() == pndate.month
&& yeartest(cal.getYear()) == pndate.year
)
{
row = '<td style="background: #a67a00;">'
+ '<a style="color:#fff;" href="#" onclick="'+onclick+'">'+day
+ '</a></td>';
}
else
row = '<td><a href="#" onclick="'+onclick+'">'+day+'</a></td>';
}
else if (view == "week")
{
var monthdays = getmonthdays(yeartest(cal.getYear()),cal.getMonth());
var nextmy = getpndate(yeartest(cal.getYear()),cal.getMonth()+1);
var daysnextmon = -1;
// number of days from next month in week
if (cal.getDate()+6 > monthdays && pndate.month > cal.getMonth())
daysnextmon = monthdays-day;
// highlight check
if (
(
day >= cal.getDate()
&& day <= cal.getDate()+6
&& cal.getMonth() == pndate.month
&& yeartest(cal.getYear()) == pndate.year
) ||
(
day <= daysnextmon
&& pndate.month == nextmy.month
&& pndate.year == nextmy.year
)
)
{
row = '<td style="background: #a67a00;">'
+ '<a style="color:#fff;" href="#" onclick="'+onclick+'">'+day
+ '</a></td>';
}
else
row = '<td><a href="#" onclick="'+onclick+'">'+day+'</a></td>';
}
else
row = '<td><a href="#" onclick="'+onclick+'">'+day+'</a></td>';
return row;
}
function calendarcells(cal,monthdays,monthprev,prevdays,nextdays,view)
{
var html = '';
var row = '';
for (var i=0,j=0,k=0,c=prevdays-1; i < (monthdays+prevdays+nextdays); i++)
{
// finished filling a row
if (i && i%7==0)
{
html += '<tr>'+row+'</tr>';
row = '';
}
// cases for previous, current, and next month
if (i < prevdays)
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth()-1);
day = monthprev-c;
c--;
}
else if (i >= prevdays && i < (monthdays+prevdays))
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth());
day = j+1;
j++;
}
else
{
pndate = getpndate(yeartest(cal.getYear()),cal.getMonth()+1);
day = k+1;
k++;
}
row += highlightrow(cal,view,pndate,day);
}
// add the last row
html += '<tr>'+row+'</tr>';
return html;
}
// from:
// http://www.irt.org/script/533.htm
function getmonthdays(year,month)
{
return 32-(new Date(year,month,32)).getDate();
}
function getpndate(year,month)
{
var date = { month: '', year: '' };
if (month < 0)
{
date.month = 11;
date.year = year-1;
}
else if (month > 11)
{
date.month = 0;
date.year = year+1;
}
else
{
date.month = month;
date.year = year;
}
return date;
}
function getmonthlink(date,img)
{
var html = '';
var ipath = 'https://jedi.tcnj.edu/webteam/webcal/img/';
html = '<a href="#" onclick="load_cal('
+ '\'minical\','+date.year+','+date.month+',1,1'
+ ');">'
+ '<div align="center"><strong>'
+ '<img src="'+ipath+img+'_month.gif" alt="'+img+'month"'
+ ' width="16" height="16" />'
+ '</strong></div>'
+ '</a>';
return html;
}
function load_head(cal)
{
var html = '';
var month = cal.getMonth();
var year = yeartest(cal.getYear());
var link_prev = getmonthlink(getpndate(year,month-1),'previous');
var link_next = getmonthlink(getpndate(year,month+1),'next');
html += '<tr>';
html += '<td>'+link_prev+'</td>';
html += '<td colspan="5"><div align="center">'
+ monthname(month)+' '+year
+'</div></td>';
html += '<td>'+link_next+'</td>';
html += '</tr>';
return html;
}
function load_days(cal,view)
{
var html = '';
var monthdays = getmonthdays(yeartest(cal.getYear()),cal.getMonth());
var prevdays = new Date(yeartest(cal.getYear()),cal.getMonth(),1).getDay();
var nextdays = 6-new Date(yeartest(cal.getYear()),cal.getMonth(),monthdays).getDay();
var monthprev = '';
if (cal.getMonth() == 0)
monthprev = getmonthdays(yeartest(cal.getYear())-1,11);
else
monthprev = getmonthdays(yeartest(cal.getYear()),cal.getMonth()-1);
// build cells for the calendar
html += weekdayheads();
html += calendarcells(cal,monthdays,monthprev,prevdays,nextdays,view);
return html;
}
// --------------------------------------
function load_cal(target,year,month,day,view)
{
var cal = '';
var html = '';
var tag = document.getElementById(target);
// either load the cal for today
// or a user-specified cal
if (typeof(year) == "undefined"
|| typeof(month) == "undefined"
|| typeof(day) == "undefined"
)
{
cal = new Date();
}
else
{
cal = new Date();
cal.setFullYear(year,month,day);
}
// generate view based on date
html += '<table border="0" cellpadding="0" cellspacing="0" class="calendar">';
html += load_head(cal);
html += load_days(cal,view);
html += '</table>';
tag.innerHTML = html;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Campus Events Calendar :: College &amp; Community Relations :: The College of New Jersey</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="screen" href="https://www.tcnj.edu/~webtest2/calendar/screen.css" />
<link href="https://www.tcnj.edu/~it/css/lg.css" type="text/css" rel="alternate stylesheet" media="screen,print" title="Large Text" />
<link href="https://www.tcnj.edu/~it/css/lgr.css" type="text/css" rel="alternate stylesheet" media="screen,print" title="Larger Text" />
<link href="https://www.tcnj.edu/~it/css/print.css" type="text/css" rel="stylesheet" media="print" />
<script type="text/javascript" src="https://www.tcnj.edu/~it/css/global.js"></script>
<script type="text/javascript" src="https://jedi.tcnj.edu/webteam/xmlreq/Request.js"></script>
<script type="text/javascript" src="minical.js"></script>
<script type="text/javascript" src="display.js"></script>
<style>
div#spinner {
background-image: url("spinner.gif");
background-position:center center;
background-repeat:no-repeat;
padding:50px;
}
</style>
</head>
<body>
<div class="wrap">
<div class="head">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="header"><a href="http://www.tcnj.edu/"><img src="https://www.tcnj.edu/media/tcnj-header.gif" alt="tcnj logo" border="0" /></a></td>
</tr>
</table>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200" valign="top" class="lside">
<div class="lsidecontent">
<div class="leftnavlevel3">
<div id="minical"></div>
</div>
</div>
<div style="padding: .8em;">
<h2 style="padding-top: .1em; font-size: .9em; color: #293f6f; text-transform: uppercase;">ADD Events </h2>
<p class="small"><img src="https://www.tcnj.edu/~webtest2/calendar/media/icons/lock2.gif" alt="login" width="16" height="16" align="absmiddle" /> <a href="https://jedi.tcnj.edu/webteam/cgi-bin/webalerts/wa.pl">Login</a></p>
<p class="small"><img src="https://www.tcnj.edu/~webtest2/calendar/media/icons/pencil.gif" alt="sponsor" width="16" height="16" align="absmiddle" /> <a href="https://jedi.tcnj.edu/webteam/cgi-bin/webalerts/wa.pl?state=request">Sign Up for Account </a></p>
</div>
</td>
<td class="main" valign="top">
<div class="maincontent">
<div class="bcnavlinks">
<!--<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><a href="http://www.tcnj.edu/">TCNJ Home</a> : <a href="../calendars/index.html">Calendars</a> : </td>
<td align="right" valign="top"><img src="https://www.tcnj.edu/media/label_textsize.gif" alt="textsize" height="18" width="50" /><a onclick="setActiveStyleSheet('default');return false;" href="#"><img src="https://www.tcnj.edu/media/icon_text_med.gif" alt="medium" height="18" width="18" /></a><a onclick="setActiveStyleSheet('Large Text');return false;" href="#"><img src="https://www.tcnj.edu/media/icon_text_lg.gif" alt="large" height="18" width="18" /></a><a onclick="setActiveStyleSheet('Larger Text');return false;" href="#"><img src="https://www.tcnj.edu/media/icon_text_lg2.gif" alt="larger" height="18" width="18" /></a></td>
</tr>
</table>-->
</div>
<h1>Calendars</h1>
<ul class="tabs">
<li><a id="current" href="https://jedi.tcnj.edu/webteam/webcal/wc.html">Campus Events</a></li>
<li><a href="http://www.tcnj.edu/~ccr/calendars/academic.html">Academic Calendars</a></li>
<li><a href="http://www.tcnj.edu/~ccr/calendars/admissions.html">Admissions &amp; Aid Dates</a></li>
<li><a href="http://www.tcnj.edu/~ccr/calendars/holidays.html">Holidays</a></li>
</ul>
<script type="text/javascript">
var GLOBAL_WEBCALID = 1059;
var GLOBAL_BEAST = 0;
var oldate = new Date();
var uriobj = d_general_parse_uri(document.location);
/* browser test */
if (navigator.appName == "Microsoft Internet Explorer")
year = oldate.getYear();
else
year = oldate.getYear()+1900;
window.onload = function () {
/* specific event view */
if (uriobj.type && uriobj.eid && uriobj.y && uriobj.m && uriobj.d)
{
init(
GLOBAL_WEBCALID,uriobj.eid,'calendar','view',uriobj.type,
uriobj.y,uriobj.m-1,uriobj.d,'day'
);
}
else
{
init(
GLOBAL_WEBCALID,0,'calendar','view','day',
year,oldate.getMonth(),oldate.getDate()
);
}
}
</script>
<div id="view"></div>
<div id="calendar"></div>
<div id="spinner" width=75%></div>
</div>
</td>
</tr>
</table>
</div>
<div class="foot">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="botnavbar">
<td>
<div class ="botnav"></div>
<div class="footer">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="205" valign="top"><a href="http://www.tcnj.edu/"><img src="https://www.tcnj.edu/media/tcnj_logo-small.gif" alt="tcnj logo" width="196" height="35" border="0" /></a></td>
<td valign="middle">
<span class="footer">
&copy; 2003, All Rights Reserved.&nbsp;&nbsp;<a href="http://www.tcnj.edu/digital/index.html">WWW
Disclaimer</a>&nbsp;&nbsp;
<script type="text/javascript" language="JavaScript">
<!--
document.write('Updated: ' + document.lastModified + '');
//-->
</script><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? " https://ssl ." : " http://www .");
document.write(unescape("%3Cscript src='" + gaJsHost + " google-analytics.com/ga.js ' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-775940-6");
pageTracker._trackPageview();
} catch(err) {}</script>
</span> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment