Template:Team:KULeuven/Notebook/DayNavigator

From 2009.igem.org

(Difference between revisions)
(New page: <html> <script type="text/javascript"> - * @author KULeuven: var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',...)
Line 7: Line 7:
'June', 'July', 'August', 'September', 'October', 'November', 'December');
'June', 'July', 'August', 'September', 'October', 'November', 'December');
-
document.write(pageDate().toString().substring(0,11));
+
var dayNames = new Array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
 +
 
 +
 
/* Extracts the corresponding calendar date out of the page url */
/* Extracts the corresponding calendar date out of the page url */
Line 36: Line 38:
}
}
-
/* Retrieves date ndays before this page date */
+
function dateDaysFrom(d, ndays) {
-
function datePast(ndays) {
+
var newDate = new Date();
-
var pastDate = new Date();
+
var ntime = d.getTime() + ndays*86400*1000;
-
// getDate, setDate methods are rubbish, stick to numeric substraction!
+
newDate.setTime(ntime);
-
var ntime = pageDate().getTime() - ndays*86400*1000;
+
return newDate;
-
pastDate.setTime(ntime);
+
-
 
+
-
return pastDate;
+
}
}
-
/* Searches date ndays after this page date */
+
function getWeekMonday(d) {
-
function dateFuture(ndays) {
+
var dayOfWeek = d.getDay();
-
var futureDate = new Date();
+
-
// getDate, setDate methods are rubbish, stick to numeric adding!
+
-
var ntime = pageDate().getTime() + ndays*86400*1000;
+
-
futureDate.setTime(ntime);
+
-
 
+
-
return futureDate;
+
-
}
+
-
 
+
-
/* Returns the date of Friday previous week */
+
-
function previousWeekFriday() {
+
-
var dayOfWeek = pageDate().getDay();
+
-
var previousWeekFriday = new Date();
+
switch(dayOfWeek) {
switch(dayOfWeek) {
-
// case 0 is Sunday, substract 9 days
+
// case 0 is Sunday
-
case 0: previousWeekFriday = datePast(9); break;
+
case 0: return dateDaysFrom(d, -6); break;
-
default: previousWeekFriday = datePast(dayOfWeek + 2); break;
+
default: return dateDaysFrom(d, -dayOfWeek + 1); break;
}
}
-
 
-
return previousWeekFriday;
 
}
}
-
/* Returns the date of Monday next week */
 
-
function nextWeekMonday() {
 
-
var dayOfWeek = pageDate().getDay();
 
-
var nextWeekMonday = new Date();
 
-
switch(dayOfWeek) {
+
function printDate(d) {
-
// case 0 is Sunday, add 1 day
+
    document.write(d.toUTCString());
-
case 0: nextWeekMonday = dateFuture(1); break;
+
    document.write('<br>');
-
default: nextWeekMonday = dateFuture(8 - dayOfWeek); break;
+
}
-
}
+
-
return nextWeekMonday;
+
function getLink(d) {
 +
    return d.getDate() + '_' + monthNames[d.getMonth()] + '_' + d.getFullYear() + '.html';
}
}
-
/* Returns the date of Friday this week */
+
function printLink(d, t) {
-
function thisFriday() {
+
    document.write('<a href="'+getLink(d)+'">'+t+'</a>');
-
var dayOfWeek = pageDate().getDay();
+
}
-
var thisFriday;
+
-
switch(dayOfWeek) {
+
function printDayCell(d,t, tod) {
-
// case 0 is Sunday, substract 2 days
+
    document.write('<td class="'+dayNames[d.getDay()])
-
case 0: thisFriday = datePast(2); break;
+
    if(d.getDay() == tod.getDay()) {
-
// case 6 is Saturday, substract 1 day, can also be merged into default, in which case we look -1 day // ahead, corresponding to going 1 day back in the past
+
        document.write(' selected');
-
case 6: thisFriday = datePast(1); break;
+
    }
-
default: thisFriday = dateFuture(5 - dayOfWeek); break;
+
    document.write('">');
-
}
+
    printLink(d,t);
-
 
+
    document.write('</td>');
-
return thisFriday;
+
}
}
-
/* Converts a date into a valid url for the KULeuven wiki and loads the page */
+
today = pageDate();
-
function goToDate(date) {
+
dmon = getWeekMonday(today);
-
// base wiki url of KULeuven
+
dprev = dateDaysFrom(dmon, -1);
-
var URL = "https://2009.igem.org/Team:KULeuven/";
+
dtue = dateDaysFrom(dmon, 1);
-
URL += date.getDate();
+
dwed = dateDaysFrom(dmon, 2);
-
URL += '_';
+
dthu = dateDaysFrom(dmon, 3);
-
// month indexing of Date object index matching to array monthNames indexing
+
dfri = dateDaysFrom(dmon, 4);
-
URL += monthNames[date.getMonth()];
+
dsat = dateDaysFrom(dmon, 5);
-
URL += '_';
+
dsun = dateDaysFrom(dmon, 6);
-
URL += date.getFullYear();
+
dnext = dateDaysFrom(dmon, 7);
-
// redirect browser to desired day
+
 
-
window.location.href = URL;
+
-
}
+
</script>
</script>
<center>
<center>
-
<table width="70%">
+
<table id='NBNav'>
-
<tr align="center">
+
<tr>
-
<td align="left" width="25%"><a href="javascript:void(0);" onClick="goToDate(previousWeekFriday());">&lt; previous friday</a></td>
+
<td rowspan=3 class='prev'><script type="text/javascript">printLink(dprev, '&lt;&lt;&lt;');</script></td>
-
<td width="25%"><a href="javascript:void(0);" onClick="goToDate(datePast(1));">← yesterday</a></td>
+
<th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> <th>Sun</th>
-
<td width="25%"><a href="javascript:void(0);" onClick="goToDate(dateFuture(1));">tomorrow →</a></td>
+
<td rowspan=3 class='next'><script type="text/javascript">printLink(dnext, '&gt;&gt;&gt;');</script></td>
-
<td align="right" width="25%"><a href="javascript:void(0);" onClick="goToDate(nextWeekMonday());">next monday &gt;</a></td>
+
</tr>
</tr>
 +
<tr>
 +
<script type="text/javascript">printDayCell(dmon, dmon.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dtue, dtue.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dwed, dwed.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dthu, dthu.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dfri, dfri.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dsat, dsat.getDate(), today);</script>
 +
<script type="text/javascript">printDayCell(dsun, dsun.getDate(), today);</script>
 +
</tr>
 +
 +
<script type="text/javascript">
 +
<!--
 +
  if(dmon.getMonth() == dsun.getMonth()) {
 +
      m1 = "";
 +
      m2 = monthNames[dmon.getMonth()];
 +
  } else {
 +
      m1 = monthNames[dmon.getMonth()];
 +
      m2 = monthNames[dsun.getMonth()];
 +
  }
 +
 +
  document.write('<tr><th class="left" colspan=4>'+m1+'</th><th class="right" colspan=3>'+m2+'</th></tr>');
 +
-->
 +
</script>
 +
</table>
</table>
</center>
</center>
-
 
</html>
</html>

Revision as of 09:51, 9 July 2009

Mon Tue Wed Thu Fri Sat Sun