Post by Todge on Mar 20, 2006 13:33:08 GMT -8
This will add a button next to the 'New Thread' button that will allow you to start a thread with a permanent sticky post at the top, as in, the topmost message will be at the top of every page within that thread..
It goes in your Global Footer
To edit the code, find this line near the top...
var stickyButton = 'URL OF STICKY BUTTON';
and add the FULL URL of the image you'd like as your sticky button.
The code, as it is, will only allow the main admin to start threads with a sticky, if you want members to be allowed to post stickies, find this line...
if(postBar[pb].href.match('action=post') && pb_username == 'admin')
and change it to...
if(postBar[pb].href.match('action=post'))
Be aware that you can NOT edit the contents of a sticky once posted, the only way is to delete the whole thread and start again...
There is a restriction of 1750 characters for the sticky message, that may seem like a lot, but if you start using smilies etc., you'll be surprised at how fast that will be used up...
When you go to start a thread with a sticky, you can only preview the post to start with, enter your sticky message and hit preview, you can then modify it if you wish.. Once you are happy with it, you can enter a normal post and hit 'Post Message', your sticky will be at the top, and your normal message will be below..
It goes in your Global Footer
<script type="text/javascript">
<!--
/*
Permanent Sticky by Todge
Copyright © 2006
Please keep this header intact
*/
if(!document.location.href.match('action=headersfooters'))
{
// Add "Post Sticky" button..
if(document.location.href.match('board=') && !document.location.href.match('action='))
{
var stickyButton = 'URL OF STICKY BUTTON';
var postBar = document.links;
for(pb=0; pb<postBar.length; pb++)
{
if(postBar[pb].href.match('action=post') && pb_username == 'admin')
{
postBar[pb].parentNode.innerHTML += '<a href="/index.cgi?board=hidden&action=createpoll&extrapolloptions=1&question=stickyPost&answer-1=none&answer-2=none"><img src="'+stickyButton+'" border="0"></a>';
}
if(postBar[pb].innerHTML.match('~sp'))
{
postBar[pb].parentNode.parentNode.previousSibling.previousSibling.previousSibling.style.display='none';
}
}
}
// Find and create sticky post..
if(document.location.href.match('action=display'))
{
var sp = document.getElementsByTagName('b')
for(s=0; s<sp.length; s++)
{
if(sp[s].innerHTML=='Poll Question: stickyPost1')
{
var SP = sp[s].parentNode.parentNode.parentNode;
}
}
SP.style.display='none';
SP=SP.nextSibling.firstChild;
var SPCode = ' ';
var SPOpen = '&l'+'t;';
SPOpen = new RegExp(SPOpen,'g');
var SPClose = '&g'+'t;';
SPClose = new RegExp(SPClose,'g');
var getCode = SP.getElementsByTagName('input')
for(g=0; g<getCode.length; g++)
{
if(getCode[g].name=='vote')
{
if(getCode[g].parentNode.innerHTML.split('> ')[1] != 'none')
{
SPCode += getCode[g].parentNode.innerHTML.split('> ')[1].replace(SPOpen,'<').replace(SPClose,'>');
}
}
}
SP.innerHTML = SPCode.replace(/ptth/g,'http');
}
// Create post....
// Hide poll cells in post area..
if(document.postForm && document.postForm.question.value.match('stickyPost'))
{
document.getElementsByTagName('font')[1].innerHTML='« Create Sticky »';
var pButton = document.getElementsByTagName('input');
document.postForm.subject.maxLength = '47';
var hideCell = document.postForm.question.parentNode.parentNode;
hideCell.style.display = 'none';
hideCell.nextSibling.style.display='none';
// Hide Post button & rename Preview button...
for(pb=0; pb<pButton.length; pb++)
{
if(pButton[pb].value=='Post Message'&&document.postForm.question.value=='stickyPost')
{
pButton[pb].style.display='none';
pButton[pb+1].onclick = function(){if(document.postForm.subject.value!=''&&document.postForm.message.value!=''){document.postForm.question.value='stickyPost1';}document.postForm.nextaction.value='preview';}
}
if(pButton[pb].value=='Post Message' && document.postForm.question.value=='stickyPost1')
{
pButton[pb].onclick = function(){if(answer[1].value==''){answer[1].value='none';}document.postForm.subject.maxLength='50';document.postForm.subject.value+='~sp';}
pButton[pb+1].value='Modify Sticky';
}
}
// Get HTML and add to vote values..
if(document.postForm.question.value=='stickyPost1')
{
var post = document.getElementsByTagName('font');
for(f=0; f<post.length; f++)
{
if(post[f].size=='2' && post[f].innerHTML.match('google_ad_section_start'))
{
var postCode = post[f].innerHTML.split('-->')[1].split('<!--')[0].replace(/http/g,'ptth');
var postLength = postCode.length/50;
document.write(postCode.length);
if(postLength>35)
{
alert("Your sticky post is too long, please modify it to ensure it's displayed correctly");
postLength = 35;
}
var answer = new Array();
var ans=0;
for(pb=0; pb<pButton.length; pb++)
{
if(pButton[pb].name.match('answer'))
{
answer[ans] = pButton[pb];
answer[ans].value = 'none';
ans++;
}
}
for(pl=0; pl<postLength; pl++)
{
answer[pl].value = postCode.substring(pl*50,pl*50+50);
}
}
}
}
// Verify message before posting..
if(document.postForm.question.value=='stickyPost1')
{
var poll = document.getElementsByTagName('b');
for(p=0; p<poll.length; p++)
{
if(poll[p].innerHTML=='Poll')
{
poll[p].parentNode.parentNode.parentNode.style.display='none';
poll[p].parentNode.parentNode.parentNode.nextSibling.style.display='none';
poll[p].parentNode.parentNode.parentNode.nextSibling.nextSibling.firstChild.style.display='none';
}
}
}
}
// Get rid of ~sp etc. on all pages..
var Cell = document.getElementsByTagName('font');
for(t=0; t<Cell.length; t++)
{
if(Cell[t].innerHTML.match('Create Poll Error') && Cell[1].innerHTML.match('Create Sticky'))
{
Cell[t].innerHTML = '<b>Create Sticky Error</b>';
}
if(Cell[t].innerHTML.match('~sp'))
{
Cell[t].innerHTML = Cell[t].innerHTML.replace('~sp','');
}
}
if(!document.location.href.match('='))
{
var Cell = document.getElementsByTagName('a');
for(t=0; t<Cell.length; t++)
{
if(Cell[t].innerHTML.match('~sp'))
{
Cell[t].innerHTML = Cell[t].innerHTML.replace('~sp','');
}
}
}
if(document.location.href.match('action=display') || document.getElementsByTagName('font')[1].innerHTML.match('Create Sticky'))
{
var threadName = document.getElementsByTagName('font')[1].innerHTML.split(' »')[0].split('« ')[1];
threadName = document.createTextNode(' :: '+threadName);
var title = document.links;
for(t=0; t<title.length; t++)
{
if(title[t].href.match('board='))
{
title[t].parentNode.replaceChild(threadName,title[t].nextSibling);
break;
}
}
}
}
// -->
</script>
To edit the code, find this line near the top...
var stickyButton = 'URL OF STICKY BUTTON';
and add the FULL URL of the image you'd like as your sticky button.
The code, as it is, will only allow the main admin to start threads with a sticky, if you want members to be allowed to post stickies, find this line...
if(postBar[pb].href.match('action=post') && pb_username == 'admin')
and change it to...
if(postBar[pb].href.match('action=post'))
Be aware that you can NOT edit the contents of a sticky once posted, the only way is to delete the whole thread and start again...
There is a restriction of 1750 characters for the sticky message, that may seem like a lot, but if you start using smilies etc., you'll be surprised at how fast that will be used up...
When you go to start a thread with a sticky, you can only preview the post to start with, enter your sticky message and hit preview, you can then modify it if you wish.. Once you are happy with it, you can enter a normal post and hit 'Post Message', your sticky will be at the top, and your normal message will be below..