Post by Peter on Apr 29, 2006 13:24:58 GMT
This script will add a button in the title bars inside boards, you will have the option of selecting to have threads for every page you view to be alphabetical, or have the option to switch back. The option is stored, so everytime you visit the forum it will remember your last selection.
<script type="text/javascript">
<!--
/*
Alphabetical Threads
Created by Peter
This code cannot be reposted at anywhere other than SSDesigns or ProBoards, without permission.
This header must stay intact at all times.
*/
// Image urls for the 2 images
var iAZ = "http://www.ssdsitetest.elixant.com/pbv4/alphathreads/az.gif";
var iNormal = "http://www.ssdsitetest.elixant.com/pbv4/alphathreads/normal.gif";
// Array of icons, change them if needed
var icons = [
"sticky.gif",
"poll_icon.gif",
"poll_icon_closed.gif",
"stickylock.gif"
];
var pollRow = {
got: null,
poll: 0,
row: 1
};
var sortedRows = document.createDocumentFragment();
var sPlace = document.createElement("span");
function putBack(nTR, obj){
nTR.sort();
obj.insertBefore(sPlace, obj.rows.item(obj.rows.length - pollRow.row));
for(a = 0; a < nTR.length; a ++){
if(obj.nodeName.toLowerCase() == "tbody"){
sortedRows.appendChild(nTR[1]);
if(pollRow.got != null && nTR[0].match(/\{-poll-\}/)){
var nRow = document.createElement("tr");
nRow.appendChild(pollRow.got.cloneNode(true));
sortedRows.appendChild(nTR[1]);
}
}
}
obj.replaceChild(sortedRows, obj.getElementsByTagName("span").item(0));
}
function setCookie(name,value,expires,domain){
document.cookie = name + "=" + encodeURI(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((domain == null) ? "" : "; domain=" + domain);
}
function getCook(){
if(document.cookie.match(/alphathreads=(\w)/)){
return RegExp.$1;
} else {
return false;
}
}
function doAlpha(obj){
var iDomain = location.hostname;
var ExpDate = new Date ();
ExpDate.setTime(ExpDate.getTime() + (180 * 24 * 3600 * 1000));
if(obj){
if(obj.firstChild.id == "az"){
setCookie("alphathreads", "a", ExpDate, iDomain);
location.href = location.href;
} else {
setCookie("alphathreads", "n", ExpDate, iDomain);
location.href = location.href;
}
}
}
function alphaThreads(){
var iAlp = [];
var iLetter = iPRow = "";
var re1 = new RegExp(icons[0] + "|" + icons[3]);
var iTable = document.getElementsByTagName("table");
var iCell = document.getElementsByTagName("td");
var mId = mSrc = mTitle = "";
if(getCook() == "a"){
mId = "n";
mSrc = iNormal;
mTitle = "Order threads by default";
} else {
mId = "az";
mSrc = iAZ;
mTitle = "Order threads alphbetical";
}
var imgAZ = '<a href="#" onclick="doAlpha(this); return false">';
imgAZ += '<img id="' + mId + '" src="' + mSrc + '" border="0" title="' + mTitle + '"></a>';
for(c = 0; c < iCell.length; c ++){
if(iCell.item(c).width == "60%" && iCell.item(c).firstChild && iCell.item(c).firstChild.className == "titletext"){
iCell.item(c).innerHTML += "&nb" + "sp;&nb" + "sp;&nb" + "sp;" + imgAZ;
}
}
for(t = 0; t < iTable.length; t ++){
if(iTable.item(t).cellPadding == "4" && iTable.item(t).cellSpacing == "1" && getCook() == "a"){
if(iTable.item(t).rows.item(0).cells.item(0).className == "titlebg" && !iTable.item(t).rows.item(0).innerHTML.match(/Sub-Boards/)){
var iRow = iTable.item(t).getElementsByTagName("tr");
for(r = (iRow.length - 1); r > 0; r --){
if(iRow.item(r).cells.item(0).className == "windowbg2" && iRow.item(r).cells.item(0).innerHTML != ""){
if(iRow.item(r).cells.item(0).colSpan == "8"){
pollRow.row = 2;
continue;
}
var iNum = (iRow.item(r).cells.item(0).firstChild.nodeName.match(/^input/i))? 1 : 0;
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re1)){
continue;
}
var re3 = new RegExp(icons[1] + "|" + icons[2]);
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re3)){
if(iRow.item(r - 1).cells.item(iNum).firstChild.firstChild.src.match(re1)){
continue;
}
}
var re2 = new RegExp(icons[1] + "|" + icons[2]);
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re2)){
if(!iRow.item(r - 1).cells.item(1).firstChild.firstChild.src.match(re1)){
if(iRow.item(r - 1).cells.item(1).rowSpan == "2"){
iRow.item(r).insertCell(iRow.item(r).cells.length)
pollRow.got = iRow.item(r).cells.item(iNum).cloneNode(true);
iRow.item(r).parentNode.removeChild(iRow.item(r));
pollRow.poll = 1;
continue;
} else {
pollRow.poll = 0;
}
}
}
if(iRow.item(r).getElementsByTagName("b").item(0)){
iPRow = (pollRow.poll == 1)? "{-poll-}" : "";
if(iRow.item(r).getElementsByTagName("b").item(0).hasChildNodes()){
var theNode = iRow.item(r).getElementsByTagName("b").item(0).firstChild;
iLetter = theNode.innerHTML.substr(0,1) + iPRow;
}
}
if(iRow.item(r) && !iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re3)){
iAlp.push([iLetter.toLowerCase(), iRow.item(r).cloneNode(true)]);
iRow.item(r).parentNode.removeChild(iRow.item(r));
pollRow.poll = 0;
}
}
}
iTable.item(t).id = "alphathreads";
}
}
}
if(document.getElementById("alphathreads")){
putBack(iAlp, document.getElementById("alphathreads").childNodes.item(0));
}
}
if(!location.href.match(/(action=(display|post|modify)|index.cgi$)/i)){
alphaThreads();
}
//-->
</script>
Add this to your global footers.
<script type="text/javascript">
<!--
/*
Alphabetical Threads
Created by Peter
This code cannot be reposted at anywhere other than SSDesigns or ProBoards, without permission.
This header must stay intact at all times.
*/
// Image urls for the 2 images
var iAZ = "http://www.ssdsitetest.elixant.com/pbv4/alphathreads/az.gif";
var iNormal = "http://www.ssdsitetest.elixant.com/pbv4/alphathreads/normal.gif";
// Array of icons, change them if needed
var icons = [
"sticky.gif",
"poll_icon.gif",
"poll_icon_closed.gif",
"stickylock.gif"
];
var pollRow = {
got: null,
poll: 0,
row: 1
};
var sortedRows = document.createDocumentFragment();
var sPlace = document.createElement("span");
function putBack(nTR, obj){
nTR.sort();
obj.insertBefore(sPlace, obj.rows.item(obj.rows.length - pollRow.row));
for(a = 0; a < nTR.length; a ++){
if(obj.nodeName.toLowerCase() == "tbody"){
sortedRows.appendChild(nTR[1]);
if(pollRow.got != null && nTR[0].match(/\{-poll-\}/)){
var nRow = document.createElement("tr");
nRow.appendChild(pollRow.got.cloneNode(true));
sortedRows.appendChild(nTR[1]);
}
}
}
obj.replaceChild(sortedRows, obj.getElementsByTagName("span").item(0));
}
function setCookie(name,value,expires,domain){
document.cookie = name + "=" + encodeURI(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((domain == null) ? "" : "; domain=" + domain);
}
function getCook(){
if(document.cookie.match(/alphathreads=(\w)/)){
return RegExp.$1;
} else {
return false;
}
}
function doAlpha(obj){
var iDomain = location.hostname;
var ExpDate = new Date ();
ExpDate.setTime(ExpDate.getTime() + (180 * 24 * 3600 * 1000));
if(obj){
if(obj.firstChild.id == "az"){
setCookie("alphathreads", "a", ExpDate, iDomain);
location.href = location.href;
} else {
setCookie("alphathreads", "n", ExpDate, iDomain);
location.href = location.href;
}
}
}
function alphaThreads(){
var iAlp = [];
var iLetter = iPRow = "";
var re1 = new RegExp(icons[0] + "|" + icons[3]);
var iTable = document.getElementsByTagName("table");
var iCell = document.getElementsByTagName("td");
var mId = mSrc = mTitle = "";
if(getCook() == "a"){
mId = "n";
mSrc = iNormal;
mTitle = "Order threads by default";
} else {
mId = "az";
mSrc = iAZ;
mTitle = "Order threads alphbetical";
}
var imgAZ = '<a href="#" onclick="doAlpha(this); return false">';
imgAZ += '<img id="' + mId + '" src="' + mSrc + '" border="0" title="' + mTitle + '"></a>';
for(c = 0; c < iCell.length; c ++){
if(iCell.item(c).width == "60%" && iCell.item(c).firstChild && iCell.item(c).firstChild.className == "titletext"){
iCell.item(c).innerHTML += "&nb" + "sp;&nb" + "sp;&nb" + "sp;" + imgAZ;
}
}
for(t = 0; t < iTable.length; t ++){
if(iTable.item(t).cellPadding == "4" && iTable.item(t).cellSpacing == "1" && getCook() == "a"){
if(iTable.item(t).rows.item(0).cells.item(0).className == "titlebg" && !iTable.item(t).rows.item(0).innerHTML.match(/Sub-Boards/)){
var iRow = iTable.item(t).getElementsByTagName("tr");
for(r = (iRow.length - 1); r > 0; r --){
if(iRow.item(r).cells.item(0).className == "windowbg2" && iRow.item(r).cells.item(0).innerHTML != ""){
if(iRow.item(r).cells.item(0).colSpan == "8"){
pollRow.row = 2;
continue;
}
var iNum = (iRow.item(r).cells.item(0).firstChild.nodeName.match(/^input/i))? 1 : 0;
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re1)){
continue;
}
var re3 = new RegExp(icons[1] + "|" + icons[2]);
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re3)){
if(iRow.item(r - 1).cells.item(iNum).firstChild.firstChild.src.match(re1)){
continue;
}
}
var re2 = new RegExp(icons[1] + "|" + icons[2]);
if(iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re2)){
if(!iRow.item(r - 1).cells.item(1).firstChild.firstChild.src.match(re1)){
if(iRow.item(r - 1).cells.item(1).rowSpan == "2"){
iRow.item(r).insertCell(iRow.item(r).cells.length)
pollRow.got = iRow.item(r).cells.item(iNum).cloneNode(true);
iRow.item(r).parentNode.removeChild(iRow.item(r));
pollRow.poll = 1;
continue;
} else {
pollRow.poll = 0;
}
}
}
if(iRow.item(r).getElementsByTagName("b").item(0)){
iPRow = (pollRow.poll == 1)? "{-poll-}" : "";
if(iRow.item(r).getElementsByTagName("b").item(0).hasChildNodes()){
var theNode = iRow.item(r).getElementsByTagName("b").item(0).firstChild;
iLetter = theNode.innerHTML.substr(0,1) + iPRow;
}
}
if(iRow.item(r) && !iRow.item(r).cells.item(iNum).firstChild.firstChild.src.match(re3)){
iAlp.push([iLetter.toLowerCase(), iRow.item(r).cloneNode(true)]);
iRow.item(r).parentNode.removeChild(iRow.item(r));
pollRow.poll = 0;
}
}
}
iTable.item(t).id = "alphathreads";
}
}
}
if(document.getElementById("alphathreads")){
putBack(iAlp, document.getElementById("alphathreads").childNodes.item(0));
}
}
if(!location.href.match(/(action=(display|post|modify)|index.cgi$)/i)){
alphaThreads();
}
//-->
</script>
Add this to your global footers.