Post by Jay on Jun 9, 2007 16:58:49 GMT -8
I got bored, so I completely rewrote my old Exp/Col script in OOP. It's a simple script and I figured it'd be a good way for people to learn OOP, so it's open source- edit at your own will. If your interested in a specific explanation of certain parts, let me know and I'll break it down.
Main Footer:
<script type="text/javascript">
<!--
// Expand/Collapse Categories - OOP Style
// Open Source, use and distribute freely
EXPAND_COLLAPSE = {
// loose home page check
loc: eval(location.href.match(/\?(action|board)=[^home]/)),
go: function() {
return !this.loc? this.data.run() : null;
},
data: {
re: /[^\b]bnames=(.+?)(;|$)/i,
td: document.getElementsByTagName("TD"),
run: function() {
for (var t = 0; t < this.td.length; t ++) {
if (this.td[t].colSpan > 4 && this.td[t].align != "right") {
var sp = document.cookie.split(/,/);
for (var s = 0; s < sp.length; s ++) {
if (sp.match(this.td[t].getElementsByTagName("B")[0].innerHTML)) {
this.col(this.td[t].parentNode);
}
}
this.td[t].onmouseover = new Function("this.style.cursor = 'pointer'");
this.td[t].onclick = function() {
var bo = this.getElementsByTagName("B")[0].innerHTML;
/* begin category cookies */
var ar = [];
if (!document.cookie.match(bo)) {
// build array
ar.push(bo);
}
if (document.cookie.match(EXPAND_COLLAPSE.data.re)) {
// build array
ar.push(RegExp.$1.replace(bo, "").replace(/,/g, ""));
}
document.cookie = "bnames=" + ar.join(",");
/* end category cookies */
EXPAND_COLLAPSE.data.col(this.parentNode);
}
}
}
},
col: function(cat) {
var clen = cat.parentNode.rows.length;
for (var r = parseInt(cat.rowIndex + 1); r < clen; r ++) {
if (cat.parentNode.rows[r].firstChild.className == "catbg") {
break;
}
else {
var obj = cat.parentNode.rows[r].style;
obj.display = obj.display != "none"? "none" : "";
}
}
}
}
};
EXPAND_COLLAPSE.go();
//-->
</script>
Have fun.
Main Footer:
<script type="text/javascript">
<!--
// Expand/Collapse Categories - OOP Style
// Open Source, use and distribute freely
EXPAND_COLLAPSE = {
// loose home page check
loc: eval(location.href.match(/\?(action|board)=[^home]/)),
go: function() {
return !this.loc? this.data.run() : null;
},
data: {
re: /[^\b]bnames=(.+?)(;|$)/i,
td: document.getElementsByTagName("TD"),
run: function() {
for (var t = 0; t < this.td.length; t ++) {
if (this.td[t].colSpan > 4 && this.td[t].align != "right") {
var sp = document.cookie.split(/,/);
for (var s = 0; s < sp.length; s ++) {
if (sp
this.col(this.td[t].parentNode);
}
}
this.td[t].onmouseover = new Function("this.style.cursor = 'pointer'");
this.td[t].onclick = function() {
var bo = this.getElementsByTagName("B")[0].innerHTML;
/* begin category cookies */
var ar = [];
if (!document.cookie.match(bo)) {
// build array
ar.push(bo);
}
if (document.cookie.match(EXPAND_COLLAPSE.data.re)) {
// build array
ar.push(RegExp.$1.replace(bo, "").replace(/,/g, ""));
}
document.cookie = "bnames=" + ar.join(",");
/* end category cookies */
EXPAND_COLLAPSE.data.col(this.parentNode);
}
}
}
},
col: function(cat) {
var clen = cat.parentNode.rows.length;
for (var r = parseInt(cat.rowIndex + 1); r < clen; r ++) {
if (cat.parentNode.rows[r].firstChild.className == "catbg") {
break;
}
else {
var obj = cat.parentNode.rows[r].style;
obj.display = obj.display != "none"? "none" : "";
}
}
}
}
};
EXPAND_COLLAPSE.go();
//-->
</script>
Have fun.