/* EventCalendar. Copyright (C) 2005-2007, Alex Tingle. $Revision: 284 $ * This file is licensed under the GNU GPL. See LICENSE file for details. */ // Set in HTML file: // var ec3.start_of_week // var ec3.month_of_year // var ec3.month_abbrev // var ec3.myfiles // var ec3.home // var ec3.hide_logo // var ec3.viewpostsfor /** Register an onload function. */ function WindowOnload(f) { var prev=window.onload; window.onload=function(){ if(prev)prev(); f(); } } // namespace function ec3() { WindowOnload( function() { // Overwrite the href links in ec3_prev & ec3_next to activate EC3. var prev=document.getElementById('ec3_prev'); var next=document.getElementById('ec3_next'); if(prev && next) { // Check for cat limit in month link var xCat=new RegExp('&cat=[0-9]+$'); var match=xCat.exec(prev.href); if(match) ec3.catClause=match[0]; // Replace links prev.href='javascript:ec3.go_prev()'; next.href='javascript:ec3.go_next()'; // Pre-load image. ec3.imgwait=new Image(14,14); ec3.imgwait.src=ec3.myfiles+'/ec_load.gif'; // Convert strings from PHP into Unicode ec3.viewpostsfor=unencode(ec3.viewpostsfor); for(var i=0; i6) { tr=document.createElement('tr'); tbody.appendChild(tr); col=0; } if(col1 && !ec3.hide_logo) { a=document.createElement('a'); a.href='http://blog.firetree.net/?ec3_version='+ec3.version; a.title='Event Calendar '+ec3.version; td.style.verticalAlign='bottom'; td.appendChild(a); div=document.createElement('div'); div.className='ec3_ec'; div.align='right'; // keeps IE happy a.appendChild(div); } // set table's element id table.id='ec3_'+year_num+'_'+month_num; return table; } // end create_calendar() /** Dispatch an XMLHttpRequest for a month of calendar entries. */ function loadDates(month_num,year_num) { var req=new XMLHttpRequest(); if(req) { ec3.reqs.push(req); req.onreadystatechange=process_xml; req.open("GET", ec3.home+'/?ec3_xml='+year_num+'_'+month_num,true); set_spinner(1); req.send(null); } } /** Obtain an array of all the calendar tables. */ function get_calendars() { var div=document.getElementById('wp-calendar'); var result=new Array(); for(var i=0; i0) return result; else return 0; } ec3.get_calendars=get_calendars; /** Changes the link text in the forward and backwards buttons. * Parameters are the 0-based month numbers. */ function rewrite_controls(prev_month0,next_month0) { var prev=document.getElementById('ec3_prev'); if(prev && prev.firstChild && prev.firstChild.nodeType==ec3.TEXT_NODE) prev.firstChild.data='\u00ab\u00a0'+ec3.month_abbrev[prev_month0%12]; var next=document.getElementById('ec3_next'); if(next && next.firstChild && next.firstChild.nodeType==ec3.TEXT_NODE) next.firstChild.data=ec3.month_abbrev[next_month0%12]+'\u00a0\u00bb'; } /** Turn the busy spinner on or off. */ function set_spinner(on) { var spinner=document.getElementById('ec3_spinner'); var publish=document.getElementById('ec3_publish'); if(spinner) { if(on) { spinner.style.display='inline'; if(publish) publish.style.display='none'; } else { spinner.style.display='none'; if(publish) publish.style.display='inline'; } } } /** Called when the user clicks the 'previous month' button. */ function go_prev() { var calendars=get_calendars(); if(!calendars) return; var pn=calendars[0].parentNode; // calculate date of new calendar var id_array=calendars[0].id.split('_'); if(id_array.length<3) return; var year_num=parseInt(id_array[1]); var month_num=parseInt(id_array[2])-1; if(month_num==0) { month_num=12; year_num--; } // Get new calendar var newcal=document.getElementById('ec3_'+year_num+'_'+month_num); if(newcal) { // Add in the new first calendar newcal.style.display=ec3.calendar_display; } else { newcal=create_calendar(calendars[0],month_num,year_num); pn.insertBefore( newcal, calendars[0] ); loadDates(month_num,year_num); } // Hide the last calendar ec3.calendar_display=calendars[calendars.length-1].style.display; calendars[calendars.length-1].style.display='none'; // Re-write the forward & back buttons. rewrite_controls(month_num+10,month_num+calendars.length-1); } ec3.go_prev=go_prev; /** Called when the user clicks the 'next month' button. */ function go_next() { var calendars=get_calendars(); if(!calendars) return; var pn=calendars[0].parentNode; var last_cal=calendars[calendars.length-1]; // calculate date of new calendar var id_array=last_cal.id.split('_'); if(id_array.length<3) return; var year_num=parseInt(id_array[1]); var month_num=1+parseInt(id_array[2]); if(month_num==13) { month_num=1; year_num++; } // Get new calendar var newcal=document.getElementById('ec3_'+year_num+'_'+month_num); if(newcal) { // Add in the new last calendar newcal.style.display=ec3.calendar_display; } else { newcal=create_calendar(calendars[0],month_num,year_num); if(last_cal.nextSibling) pn.insertBefore(newcal,last_cal.nextSibling); else pn.appendChild(newcal); loadDates(month_num,year_num); } // Hide the first calendar ec3.calendar_display=calendars[0].style.display; calendars[0].style.display='none'; // Re-write the forward & back buttons. rewrite_controls(month_num-calendars.length+11,month_num); } ec3.go_next=go_next; /** Triggered when the XML load is complete. Checks that load is OK, and then * updates calendar days. */ function process_xml() { var busy=0; for(var i=0; i