Post by uzi on Aug 27, 2011 3:15:52 GMT -8
Code: Thread Descriptions
Version: 0.5
Author: Devin Froseth
Installation
Place this in your global footers (or one board's specific footers). Edit the variable tdesc_maxChars if you want to change the maximum number of characters to allow.
Preview
devinfroseth.proboards.com/index.cgi?board=tdesc
Notes
I've disabled the ability to use HTML in the descriptions so that users can't do malicious things like creating huge bits of text or hiding the page. UBBC, Smilies, and Censored Words aren't enabled either, because ProBoards can't parse them after the page has already loaded. It is possible for me to add these in the future, but they would have to be hard-coded by me and wouldn't operate necessarily the same way that it does on the internal ProBoards software.
Warning
This code is in version 0.5 - this means that it hasn't been completely tested yet. It appears to work fine on my test forum, but it has not been extensively tested on a major production forum. Use it at your own risk - though there shouldn't be any major problems.
If you decide to remove this code in the future, you'll see some unsightly strings of text in certain posts. This is how the code stores data, and unfortunately there is no workaround at this time. To remove this strings of text, you can simply edit the post and delete it. This problem will only occur if you decide to remove the script - similar to profile modification codes leaving text in the personal text when removed, for example.
Version: 0.5
Author: Devin Froseth
<script type="text/javascript">
/**
* Thread Descriptions
* Written by Devin Froseth
* devinfroseth.proboards.com
*/
var tdesc_maxChars = 100;
var td = document.getElementsByTagName("td");
var tdesc = {
init: function()
{
if ( document.postForm )
tdesc.gui();
if ( location.href.match(/board=/i) )
tdesc.boardDisplay();
if ( location.href.match(/action=display.*&thread=/i) )
tdesc.threadDisplay();
},
reg: /\{.{0}desc=(.+?)\}/i,
bbc: function(val)
{
if ( val.length > 0 )
{
if ( val.length > tdesc_maxChars )
val = val.substring(0, tdesc_maxChars-1);
return "{" + "desc=" + val + "}";
}
else return '';
},
boardDisplay: function()
{
for ( i = 0; i < td.length; i++ )
{
if ( td[i].width == "48%" && td[i].className == "windowbg" && td[i].style.cursor == "pointer" )
{
if ( td[i].title.match(tdesc.reg) )
{
var desc = RegExp.$1;
desc = (desc.length > tdesc_maxChars) ? desc.substring(0, tdesc_maxChars - 3) + '...' : desc;
desc = desc.replace(/\</g, "&"+"lt;").replace(/\>/g, "&"+"gt;"); // prevent html
td[i].getElementsByTagName("font")[0].innerHTML += "<br /><span class='tdesc_board'>" + desc + "</span>";
td[i].title = td[i].title.replace(tdesc.reg, '');
}
}
}
},
threadDisplay: function()
{
for ( font = document.getElementsByTagName("font"), i = 0; i < font.length; i++ )
if ( font[i].innerHTML.match(tdesc.reg) )
font[i].innerHTML = font[i].innerHTML.replace(tdesc.reg, '');
},
gui: function()
{
if ( document.postForm && document.postForm.message && document.postForm.board )
{
var val = (document.postForm.message.value.match(tdesc.reg)) ? RegExp.$1 : '';
document.postForm.message.value = document.postForm.message.value.replace(tdesc.reg, '');
if ( !document.postForm.thread || (document.postForm.thread && !document.postForm.subject.value.match(/^Re:\s/)) )
{
for ( i = 0; i < td.length; i++ )
{
if ( td[i].width == "30%" && td[i].className == "windowbg" && td[i].innerHTML.match(/Subject:/) )
{
tbl = td[i].parentNode.parentNode.parentNode;
descRow = tbl.insertRow(td[i].parentNode.rowIndex+1);
descTitle = descRow.insertCell(0);
descTitle.className = "windowbg";
descTitle.innerHTML = "<font size='2'>Description:</font>";
descInput = descRow.insertCell(1);
descInput.className = "windowbg";
descInput.innerHTML = "<font size='2'><input id='tdesc_input' type='text' maxlength='50' size='40' value='" + val + "' /></font>";
if ( document.addEventListener )
document.postForm.addEventListener('submit', tdesc.update, false);
else
document.postForm.attachEvent('onsubmit', tdesc.update);
break;
}
}
}
}
},
update: function()
{
if ( descIn = document.getElementById('tdesc_input') )
{
var val = descIn.value;
var descBBC = tdesc.bbc(val);
// max limit
if ( val.length > tdesc_maxChars )
{
alert("Your thread description must be 50 characters or less.");
return false;
}
var msg = document.postForm.message.value;
// check if desc is already in post message
if ( msg.match(tdesc.reg) )
{
// min
if ( val.length < 1 )
{
document.postForm.message.value = msg.replace(tdesc.reg, '');
return;
}
document.postForm.message.value = msg.replace(tdesc.reg, descBBC);
}
else
{
if ( val.length < 1) return; // min
document.postForm.message.value = descBBC + msg;
}
return;
}
}
};
tdesc.init();
</script>
Installation
Place this in your global footers (or one board's specific footers). Edit the variable tdesc_maxChars if you want to change the maximum number of characters to allow.
Preview
devinfroseth.proboards.com/index.cgi?board=tdesc
Notes
I've disabled the ability to use HTML in the descriptions so that users can't do malicious things like creating huge bits of text or hiding the page. UBBC, Smilies, and Censored Words aren't enabled either, because ProBoards can't parse them after the page has already loaded. It is possible for me to add these in the future, but they would have to be hard-coded by me and wouldn't operate necessarily the same way that it does on the internal ProBoards software.
Warning
This code is in version 0.5 - this means that it hasn't been completely tested yet. It appears to work fine on my test forum, but it has not been extensively tested on a major production forum. Use it at your own risk - though there shouldn't be any major problems.
If you decide to remove this code in the future, you'll see some unsightly strings of text in certain posts. This is how the code stores data, and unfortunately there is no workaround at this time. To remove this strings of text, you can simply edit the post and delete it. This problem will only occur if you decide to remove the script - similar to profile modification codes leaving text in the personal text when removed, for example.