Template:Team:KULeuven/Common/JSLibrary

From 2009.igem.org

Revision as of 10:25, 12 July 2009 by Deepstar (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

/*

  • @author KULeuven
  • /

var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var monthLengths=[31,0,31,30,31,30,31,31,30,31,30,31];

var dayNames = new Array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');

/* Extracts the corresponding calendar date out of the page url */ function pageDate() { // Retrieve page url var urlTokens = location.href.split("/"); var urlLast = urlTokens[urlTokens.length - 1];

// Retrieve page date var wikiTokens = urlLast.split("#"); var wikiFirst = wikiTokens[0];

// Retrieve seperate date components var dateTokens = wikiFirst.split("_");

var day = parseInt(dateTokens[0]); var month; for (x in monthNames) { if(dateTokens[1] == monthNames[x]) {month = x; break;} } var year = parseInt(dateTokens[2]);

// Construct a Date object and return the result var date = new Date(); date.setFullYear(year, month, day);

return date; }

function dateDaysFrom(d, ndays) { var newDate = new Date(); var ntime = d.getTime() + ndays*86400*1000; newDate.setTime(ntime); return newDate; }

function getWeekMonday(d) { var dayOfWeek = d.getDay();

switch(dayOfWeek) { // case 0 is Sunday case 0: return dateDaysFrom(d, -6); break; default: return dateDaysFrom(d, -dayOfWeek + 1); break; } }


function printDate(d) {

   document.write(d.toUTCString());
   document.write('
');

}

function getLink(d) {

   return d.getDate() + '_' + monthNames[d.getMonth()] + '_' + d.getFullYear();

}

function printLink(d, t) {

   document.write('<a href="'+getLink(d)+'">'+t+'</a>');

}

function printDayCell(d,t, tod) {

   document.write('<td class="'+dayNames[d.getDay()])
   if(d.getDay() == tod.getDay()) {
       document.write(' selected');
   }
   document.write('">');
   printLink(d,t);
   document.write('</td>');

}


   function makeCalendar(mon, year, data) {

var out = "";

       var day = new Date();
       var today = new Date();
       var maxdays = 6 * 7; // max 6 rows in a month
   
       // calculate february's days
       monthLengths[1] = ( ((year%4==0) && (year%100 != 0)) || (year % 400 == 0) ) ? 29 : 28;


out += ""; out += ""; out += ""; out += ""; // how many cells to skip ? day = new Date(year, mon - 1, 1); switch(day.getDay()) { case 0: // sunday out += "";

break; case 1: // monday break; default:

out += "";

break; }

var linkprefix = "/Team:KULeuven/"; var linksuffix = "_"+monthNames[mon - 1]+"_"+year;

       for(var d = 1; d <= monthLengths[mon - 1]; d++) {

day = new Date(year, mon - 1, d); var datai = year * 10000 + mon * 100 + d;

// mark today if(today.getFullYear() == year && today.getMonth() == mon - 1 && today.getDate() == d) {

out += ""; if(day.getDay() == 0 && d != monthLengths[mon - 1]) { out += ""; } } if(day.getDay() != 0) { out += "";

}

out += "
"+monthNames[mon - 1]+"
MTWTFSS
   ";

} else {

out += "
";

}

// mark days that are tagged in the data matrix var tag = "day-not-selected"; if(data[datai] == 1) { tag = "day-selected"; }

out += "<a href='"+ linkprefix + d + linksuffix +"' class='external text'>"+d+"</a>
 
";

return out;

   }
   function convertMonthnameToNumber(mn) {
       for(var i = 0; i < monthNames.length; i++) {
           if(mn == monthNames[i]) 
               return i;
       }
       return -1;
   }
   
   
   function retrieveDatesHash() {

var data = new Array();; var re = new RegExp("Team:KULeuven/([0-9]+)_([a-zA-Z]+)_(2009)"); var links = document.getElementById('mw-pages').getElementsByTagName('a');

for (var i=0; i < links.length; i++) { var m = re.exec(links[i].href); if(m != null) {

var y = parseInt(m[3]); var d = parseInt(m[1]); var m = convertMonthnameToNumber(m[2]) + 1;

var s = y * 10000 + m * 100 + d;

data[s] = 1; } }

return data;

   }