|
Post by Wormopolis on Feb 18, 2010 3:51:54 GMT -8
Browser Tested: IE and FF placement: 3 parts, global header/footer and main footer.
This code will let you set up an announcement to show only in boards of a specified category, and hidden everywhere else. It will not override the "show announcements" settings in the board setups.
On the first post of an announcement, it will provide a list of checkboxes for each category). replies will not have access to the checkboxes - modifications can only be made from the first post.
Global Header portion: (place as high up as possible)
<script type="text/javascript"> <!-- // Category specific announcements v 1.0 // By Wormopolis - www.wormocodes.com // Do not repost - keep header intact // GLOBAL HEADER PIECE
// no need to edit below function deCode(enc) { str=""; curflag=enc.split(''); for (c=1; c<curflag.length; c++) { temp=(parseInt(curflag[c])-8000).toString(2); while (temp.length<10) temp='0'+temp; str+=temp; } return str; } function deCode2(enc) { str=""; for (c=0; c<enc.length; c++) { temp=(parseInt(enc.charCodeAt(c))-8000).toString(2); while (temp.length<10) temp='0'+temp; str+=temp; } return str; }
if (document.title.match(/±(.+?)±/)) document.title=document.title.replace(/±(.+?)±/,''); for (tds=document.getElementsByTagName('td'), t=0; t<tds.length; t++) { if (tds[t].height==50 && tds[t].className=='welcomebg' && tds[t].innerHTML.match(/±(.+?)±/)) { tds[t].lastChild.firstChild.nodeValue=tds[t].lastChild.firstChild.nodeValue.replace(/±(.+?)±/,''); } } // --> </script>
Global Footer portion: (place as high up as possible)
<script type="text/javascript"> <!-- // Category specific announcements v 1.0 // By Wormopolis - www.wormocodes.com // Do not repost - keep header intact // GLOBAL FOOTER PIECE
// no need to edit below
if (document.postForm && document.postForm.announcements) { curflag=flagstore=""; if (postForm.subject.value.match(/±(.+?)±/)) { curflag=RegExp.$1; postForm.subject.value=postForm.subject.value.replace(/±(.+?)±/,''); } flagstore=deCode(curflag); fpost=false; if (document.cookie.match(/annFlag=true/)) { fpost=true; expDate=new Date(); expDate.setYear(expDate.getFullYear()-1); document.cookie="annFlag=true; expires="+expDate; } document.postForm.announcements.nextSibling.nextSibling.firstChild.nodeValue=(location.href.match(/page=/) || (location.href.match(/action=modifypost/) && !fpost) ? "Keep this box clicked to keep as an announcement. Category selection can only be done from first post." : "To make this post an announcement, click this box. Then select the categories below:"); document.postForm.announcements.onclick= (location.href.match(/page=/) || (location.href.match(/action=modifypost/) && !fpost) ? '' : function() {tt=document.getElementById('announcebox'); tt.style.display=(tt.style.display=='none' ? '' : 'none');}); fj=document.getElementById('forumjump'); nwdv=document.createElement('div'); nwdv.id='announcebox'; nwdv.style.display=(!location.href.match(/page=/) && !(location.href.match(/action=modifypost/) && !fpost) && postForm.announcements.checked ? "" : "none"); nwchkbx=document.createElement('input'); nwchkbx.id="cat_all"; nwchkbx.type="checkbox"; nwchkbx.onclick=function() {for (bxs=document.getElementById('announcebox').getElementsByTagName('input'), b=1; b<bxs.length; b++) {bxs[b].checked=false; bxs[b].disabled=this.checked;}} nwdv.appendChild(nwchkbx); nwchkbx.checked=(postForm.announcements.checked && flagstore==''); nwdv.appendChild(document.createTextNode(" ALL")); nwdv.appendChild(document.createElement('br')); nwdv.appendChild(document.createElement('br')); plc=flagstore.length-1; for (opts=0; opts<fj.options.length; opts++) { if (fj.options[opts].value.match(/index.cgi#(.*?)/)) { nwchkbx=document.createElement('input'); nwchkbx.id='cat_'+RegExp.$1; nwchkbx.type="checkbox"; nwchkbx.disabled=(postForm.announcements.checked && curflag==''); nwdv.appendChild(nwchkbx); nwchkbx.checked=(flagstore.length>0 && flagstore.charAt(plc--)=='1'); nwdv.appendChild(document.createTextNode(" "+fj.options[opts].innerHTML)); nwdv.appendChild(document.createElement('br')); } } document.postForm.announcements.parentNode.appendChild(nwdv);
function getCats() { getems=document.getElementById('announcebox').getElementsByTagName('input'); catchstring=finalstring=anychecked=""; for (i=1; i<getems.length; i++) { catchstring=(getems[i].checked ? '1' : '0' ) + catchstring; anychecked=(anychecked || getems[i].checked); if (catchstring.length==10) { finalstring=(parseInt(catchstring,2)>0 ? ''+(parseInt(catchstring,2)+8000)+';' : ''+parseInt(8000)+';') + finalstring; catchstring=""; } } finalstring=(catchstring.length>0 && parseInt(catchstring,2)>0 ? ''+(parseInt(catchstring,2)+8000)+';' : ''+parseInt(8000)+';') + finalstring; if (!document.getElementById('cat_all').checked) { if (!anychecked) { document.postForm.announcements.checked=false; } else { postForm.subject.value='±'+finalstring+'±'+postForm.subject.value; } } }
if (document.addEventListener) { document.postForm.addEventListener('submit',getCats,false); } else { document.postForm.attachEvent('onsubmit',getCats); }
}
fj=document.getElementById('forumjump'); var ann_locsave=location.href.match(/board=(.*?)(&|$)/) ? RegExp.$1 : ''; hold=0; for (opts=0; opts<fj.options.length; opts++) { if (fj.options[opts].value.match(/index.cgi#(.*?)/)) hold++; if (fj.options[opts].value.match(new RegExp('board='+ann_locsave,'i'))) break; } if (location.href.match(/(action|board)=(display)?/)) { for (lk=document.getElementsByTagName('a'), a=0; a<lk.length; a++) { if (lk[a].className=='nav') { tmp=lk[a].nextSibling; while (!tmp.nodeName.match(/table/i)) { if (tmp.nodeName.match(/text/) && tmp.nodeValue.match(/±(.+?)±/)) tmp.nodeValue=tmp.nodeValue.replace(/±(.+?)±/,''); tmp=tmp.nextSibling; } } } for (tds=document.getElementsByTagName('td'), t=0; t<tds.length; t++) { if (tds[t].width.match(/(43|48)%/) && tds[t].innerHTML.match(/Announcement: /) && tds[t].innerHTML.match(/±(.+?)±/)) { chkflag=deCode2(RegExp.$1); if (chkflag.charAt(chkflag.length-hold) == '0') { tds[t].parentNode.style.display="none"; } else { tds[t].innerHTML=tds[t].innerHTML.replace(/±(.+?)±/,''); } } if (tds[t].width.match(/(55|80|43|48|24)%/) && tds[t].innerHTML.match(/±(.+?)±/)) { tds[t].innerHTML=tds[t].innerHTML.replace(/±(.+?)±/,''); } if (tds[t].width.match(/55%/) && tds[t].innerHTML.match(/« Thread Started on/)) { for (btns=tds[t].nextSibling.getElementsByTagName('a'), b=0; b<btns.length; b++) { if (btns[b].href.match(/action=modifypost/)) { btns[b].onclick= function() {document.cookie="annFlag=true;";} } } } } }
// --> </script>
Main Footer portion: (place as high up as possible, especially above remodels)
<script type="text/javascript"> <!-- // Category specific announcements v 1.0 // By Wormopolis - www.wormocodes.com // Do not repost - keep header intact // MAIN FOOTER PIECE
for (tds=document.getElementsByTagName('td'), t=0; t<tds.length; t++) { if (tds[t].width.match(/(24|16|60)%/) && tds[t].innerHTML.match(/±(.+?)±/)) { tds[t].innerHTML=tds[t].innerHTML.replace(/±(.+?)±/,''); } } // --> </script>
Preview: eventually, but basically it hides the announcement unless you click the checkboxes telling it to show it.
|
|
|
Post by Wormopolis on Apr 17, 2010 6:20:21 GMT -8
ok.. so something I hadn't considered. if you have categories that only certain members can see, this code wont work for you. It basically takes note of the order your categories appear in the forum jump. so if you say you want an announcement to appear in the first 3 categories, then it will for you. if another member doesnt have access to that category for whatever reason, then it will show in the first 3 categories that THEY have.
there is no way to store categories by name because the thread title can only hold so many characters. that is why I went with the order they appear.
|
|