function searchArray(src, key) { var rc = 0; for (var i=0; i < src.length; i++) { if (src[i] == key) { rc = i + 1; break; } } return rc; } function Reset_Toc() // define a reset method { parent.frames[0].document.forms[0].cats.options[0].text = "all"; parent.frames[0].document.forms[0].cats.options[0].value = ""; parent.frames[0].document.forms[0].cats.options.length = this.cats.length + 1; for (var i = 0; i < this.cats.length; i++) { parent.frames[0].document.forms[0].cats.options[i+1].text = this.cats[i]; parent.frames[0].document.forms[0].cats.options[i+1].value = this.cats[i]; } var f = parent.frames[0].document.getElementById("to"); f.setAttribute("value", this.lines[this.lines.length - 1].date); f = parent.frames[0].document.getElementById("key"); f.setAttribute("value", ""); f = parent.frames[0].document.getElementById("from"); f.setAttribute("value", this.lines[0].date); parent.frames[2].location.href = "toc.html"; } function Write_Toc(latest, oldest, key, track) // define a write method { var destination = parent.frames[2].document; var replace = parent.frames[2].document.getElementById("placeholder"); var d = destination.createElement("div"); // create a new div element to render toc for (var i = 0; i < this.lines.length; i++) // loop thru all lines in toc { if (latest != "") { if (this.lines[i].date > latest) { continue; } } if (oldest != "") { if (this.lines[i].date < oldest) { continue; } } if (key != "") { var pattern = new RegExp(key,"i"); // convert key to regular expression var result = pattern.test(this.lines[i].text); if (result == false) { continue; } } if (track != "") { var pattern = new RegExp(track); // convert track to regular expression var result = pattern.test(this.lines[i].cats); if (result == false) { continue; } } var p = destination.createElement("p"); var a = destination.createElement("a"); var x = destination.createTextNode(this.lines[i].text); var l = this.lines[i].date; if (this.lines[i].cats != "") { l = l + " - " + this.lines[i].cats; } a.setAttribute("href", "javascript:load('" + this.lines[i].href + "',top.opener)"); a.setAttribute("title", l); a.className = "toc"; a.appendChild(x); p.appendChild(a); p.className = "toc"; d.appendChild(p); } d.setAttribute("id", "placeholder"); replace.parentNode.replaceChild(d, replace); } function Line(node) // table of contents's line object constructor { this.href = node.getAttribute("href"); // post url this.text = node.firstChild.data; // post title var pattern = /^\d{4}\/\d\d\/\d\d/; this.date = pattern.exec(node.getAttribute("title")); // post date var pattern = /^\d{4}\/\d\d\/\d\d - (.*)/; var result = pattern.exec(node.getAttribute("title")); if (result != null) { this.cats = result[1]; } else { this.cats=""; } // post categories, separated by ' / ' } function Toc() // table of contents object constructor { var l = new Array(); // lines var c = new Array(); // categories var anchorList = parent.frames[1].document.getElementsByTagName("a"); // get a list of the toc html page's links var j = 0; var m = 0; for (var i = 0; i < anchorList.length; i++) // populate the lines array property { if (anchorList[i].className == "toc") // a Toc is an array of Lines objects { l[j] = new Line(anchorList[i]); if (l[j].cats != "") { var ca = l[j].cats.split(" / "); // split categories into temp array for (var k = 0; k < ca.length; k++) { if (! searchArray(c, ca[k])) { c[m] = ca[k]; m++; } } } j++; // with all the links which have toc content } } this.lines = l; this.cats = c; } Toc.prototype.reset = Reset_Toc; Toc.prototype.write = Write_Toc;