Post by Peter on Apr 29, 2006 13:34:19 GMT
Well, after about 3 rewrites, 1 large pizza, several angry out bursts about Internet Explorer, I finally finished v2 which fixes the "can't vote in polls" bug. Not only that, it doesn't use any innerHTML replacing this time, much nicer. ;D
Doesn't support head/base images, but I will most likely post a version that does.
Code goes into your global footer.
<script type="text/javascript">
<!--
/*
Split Posts v2
Created By Peter
Copyright © 2005 - expertsonline.pixeldepth.net
All Rights Reserved
This code may not be redistributed without express permission from the creator.
This header must stay intact at all times.
*/
// Set gap size here
var iGapSize = 25;
function bTable(tbobj, att){
var nTable = document.createElement("table");
for(a = 0; a < att.length; a ++){
nTable.setAttribute(att[0], att[1]);
}
nTable.appendChild(tbobj);
return nTable;
}
function splitPosts(){
var obj = new Object();
var iInc = 0, cInc = 0;
var attArray = [["width", "100%"], ["cellSpacing", 1], ["cellPadding", 4]];
var docFragment = document.createDocumentFragment();
var iTable = document.getElementsByTagName("table");
for(t = 0; t < iTable.length; t ++){
if(iTable.item(t).cellPadding == "4" && iTable.item(t).cellSpacing == "1"){
var iRows = iTable.item(t).rows;
for(r = 0; r < iRows.length; r ++){
r = (r < 0)? 0 : r;
var nTb = document.createElement("tbody");
var rNode = iRows.item(r);
if(rNode && rNode.firstChild.colSpan == "2" && rNode.firstChild.className == "titlebg" && r == 0){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.width == "20%" && rNode.innerHTML.match(/>Poll Question: /)){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.colSpan == "2" && rNode.firstChild.className == "windowbg2"){
// lets nest that form correctly so people can vote
if(rNode.firstChild.getElementsByTagName("form").item(0) && !document.all){
var pForm = rNode.firstChild.getElementsByTagName("form").item(0);
var fNode = pForm.cloneNode(false);
pForm.parentNode.removeChild(pForm);
while(rNode.firstChild.hasChildNodes()){
pForm.appendChild(rNode.firstChild.childNodes.item(0));
}
rNode.firstChild.appendChild(pForm);
}
obj[(iInc - 1)].tobj.firstChild.appendChild(rNode);
r --;
}
if(rNode && rNode.firstChild.className == "catbg" && rNode.firstChild.innerHTML.match(/Author/)){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.width == "20%" && rNode.firstChild.className.match(/^windowbg/i) && rNode.firstChild.innerHTML.match(/member is|guest/i)){
if(cInc == 0){
obj[(iInc - 1)].tobj.firstChild.appendChild(rNode);
r --;
} else {
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
}
cInc ++;
r --;
}
}
iTable.item(t).parentNode.parentNode.parentNode.id = "marker";
}
}
var iCount = 0;
for(var o in obj){
var hDiv = document.createElement("div");
var nDiv = document.createElement("div");
hDiv.style.height = iGapSize;
nDiv.className = "bordercolor";
nDiv.style.width = "100%";
nDiv.appendChild(obj[o].tobj);
if(iCount > 0){
docFragment.appendChild(hDiv);
}
docFragment.appendChild(nDiv);
iCount ++;
}
if(document.getElementById("marker")){
var iMarker = document.getElementById("marker");
iMarker.parentNode.parentNode.insertBefore(docFragment, iMarker.parentNode);
}
}
if(location.href.match(/action=display/i)){
splitPosts();
}
//-->
</script>
Doesn't support head/base images, but I will most likely post a version that does.
Code goes into your global footer.
<script type="text/javascript">
<!--
/*
Split Posts v2
Created By Peter
Copyright © 2005 - expertsonline.pixeldepth.net
All Rights Reserved
This code may not be redistributed without express permission from the creator.
This header must stay intact at all times.
*/
// Set gap size here
var iGapSize = 25;
function bTable(tbobj, att){
var nTable = document.createElement("table");
for(a = 0; a < att.length; a ++){
nTable.setAttribute(att[0], att[1]);
}
nTable.appendChild(tbobj);
return nTable;
}
function splitPosts(){
var obj = new Object();
var iInc = 0, cInc = 0;
var attArray = [["width", "100%"], ["cellSpacing", 1], ["cellPadding", 4]];
var docFragment = document.createDocumentFragment();
var iTable = document.getElementsByTagName("table");
for(t = 0; t < iTable.length; t ++){
if(iTable.item(t).cellPadding == "4" && iTable.item(t).cellSpacing == "1"){
var iRows = iTable.item(t).rows;
for(r = 0; r < iRows.length; r ++){
r = (r < 0)? 0 : r;
var nTb = document.createElement("tbody");
var rNode = iRows.item(r);
if(rNode && rNode.firstChild.colSpan == "2" && rNode.firstChild.className == "titlebg" && r == 0){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.width == "20%" && rNode.innerHTML.match(/>Poll Question: /)){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.colSpan == "2" && rNode.firstChild.className == "windowbg2"){
// lets nest that form correctly so people can vote
if(rNode.firstChild.getElementsByTagName("form").item(0) && !document.all){
var pForm = rNode.firstChild.getElementsByTagName("form").item(0);
var fNode = pForm.cloneNode(false);
pForm.parentNode.removeChild(pForm);
while(rNode.firstChild.hasChildNodes()){
pForm.appendChild(rNode.firstChild.childNodes.item(0));
}
rNode.firstChild.appendChild(pForm);
}
obj[(iInc - 1)].tobj.firstChild.appendChild(rNode);
r --;
}
if(rNode && rNode.firstChild.className == "catbg" && rNode.firstChild.innerHTML.match(/Author/)){
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
r --;
}
if(rNode && rNode.firstChild.width == "20%" && rNode.firstChild.className.match(/^windowbg/i) && rNode.firstChild.innerHTML.match(/member is|guest/i)){
if(cInc == 0){
obj[(iInc - 1)].tobj.firstChild.appendChild(rNode);
r --;
} else {
nTb.appendChild(rNode);
obj[(iInc ++)] = {
tobj: bTable(nTb, attArray)
};
}
cInc ++;
r --;
}
}
iTable.item(t).parentNode.parentNode.parentNode.id = "marker";
}
}
var iCount = 0;
for(var o in obj){
var hDiv = document.createElement("div");
var nDiv = document.createElement("div");
hDiv.style.height = iGapSize;
nDiv.className = "bordercolor";
nDiv.style.width = "100%";
nDiv.appendChild(obj[o].tobj);
if(iCount > 0){
docFragment.appendChild(hDiv);
}
docFragment.appendChild(nDiv);
iCount ++;
}
if(document.getElementById("marker")){
var iMarker = document.getElementById("marker");
iMarker.parentNode.parentNode.insertBefore(docFragment, iMarker.parentNode);
}
}
if(location.href.match(/action=display/i)){
splitPosts();
}
//-->
</script>