// Marty Stepp's CSE 14x course web site script // Sets up various things on my course web site pages, // such as zebra striping for some table rows, // links to files, email addresses and campus buildings. // max number of files that will be shown before initially collapsing var MAX_FILES_LENGTH = 99; document.observe("dom:loaded", function() { if ($("maximizelink")) { $("maximizelink").href = "#"; $("maximizelink").observe("click", maximizeClick); } var rows = $$("table.color_alternating_rows tr"); for (var i = 0; i < rows.length; i += 2) { // color every other row gray rows[i].addClassName("evenrow"); } // place links around email addresses var cells = $$(".ema"); for (var i = 0; i < cells.length; i++) { var addr = cells[i].textContent ? cells[i].textContent : cells[i].innerText; var linkText = addr; if (cells[i].hasClassName("showema")) { linkText += "@cs.washington.edu"; } cells[i].update("" + linkText + ""); } cells = $$(".building"); for (var i = 0; i < cells.length; i++) { var addr = cells[i].innerHTML; var tokens = addr.split(/[ ]+/); if (tokens.length < 2) { continue; } var building = tokens[0]; var roomNumber = tokens[1]; var area = "southcentral"; if (cells[i].hasClassName("north")) { area = "northcentral"; } cells[i].update("" + building + " " + roomNumber); } $$(".plusicon").each(function(el) { var a = el.up("a"); a.href = "#"; if (!a || a.id == "expandall") { return; } a.observe("click", collapseableClick); var collapse = el.up(".collapseable"); if (collapse && collapse.select("li").length > MAX_FILES_LENGTH) { collapseableClick(null, el); // initially collapsed } }); if ($("expandall")) { $("expandall").observe("click", expandAllClick); } // inject each date's month/day into "date" spans sequentially // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec var daysInMonth = [-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var month = 0; var day = 0; var year = 2010; if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { daysInMonth[2]++; // leap years } var today = new Date(); var tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); var yesterday = new Date(); yesterday.setDate(today.getDate() - 1); $$(".date").each(function(element) { if (element.innerHTML) { var tokens = element.innerHTML.split(/\//); month = parseInt(tokens[0]); day = parseInt(tokens[1]); } else if (month > 0 && day > 0) { day++; if (day > daysInMonth[month]) { day = 1; month = (month % 12) + 1; } element.innerHTML = month + "/" + day; } var td = element.up("td"); if (td) { var thisDate = new Date(year, month - 1, day); if (thisDate > yesterday && thisDate <= today) { td.addClassName("today"); if (typeof(td.id) === "undefined" || !td.id) { td.id = "today"; location.hash = "today"; } } } }); }); function expandAllClick(event) { if (event) { event.stop(); } var img = this.select("img.plusicon")[0]; if (!img) { return; } var expand = !!img.src.match(/plus/); swapPlusMinus(img); $$(".collapseable").each(function(collapse) { // .select("ul").each(Element.toggle); var img = collapse.select("img.plusicon")[0]; if (!!isExpanded(img) !== expand) { toggleCollapsed(collapse); } }); } function maximizeClick() { this.siblings().each(Element.toggle); } // handles click on a link around a plusicon image function collapseableClick(event, element) { if (event) { event.stop(); } if (!element) { element = this; } var collapse = element.up(".collapseable"); if (!collapse) { return; } toggleCollapsed(collapse); } function toggleCollapsed(collapse) { collapse.select("ul").each(Element.toggle); var img = collapse.select("img.plusicon")[0]; swapPlusMinus(img); } function isExpanded(img) { return img.src.match(/minus/); } function swapPlusMinus(img) { if (isExpanded(img)) { img.src = img.src.replace(/minus/, "plus"); } else { img.src = img.src.replace(/plus/, "minus"); } } /* // old functions I used before Prototype getElementsByClassName = function(tagName, className, root) { var elements; if (!root) { root = document; } elements = root.getElementsByTagName(tagName); if (!(className instanceof Array)) { className = [className]; } var result = []; for (var i = 0; i < elements.length; i++) { for (var j = 0; j < className.length; j++) { if (hasClass(elements[i], className[j])) { result.push(elements[i]); } } } return result; }; hasClass = function(element, className) { if (!element) { return false; } else if (!className || className == "*") { return true; } else if (!element.className) { return false; } var classes = getClasses(element); for (var i = 0; i < classes.length; i++) { if (classes[i] == className) { return true; } } return false; }; getClasses = function(element) { return element.className.split(/\s+/); }; */