vForums Support > Programming & Coding :: Code Requests & Support :: > [ROSS] Something Odd

[ROSS] Something Odd - Posted By CåñåÐå™ (canada) on 12th Jul 09 at 4:42am
Code:
 
  1. .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
  2. .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
  3. </style>
  4. <script type="text/javascript">
  5. //Dice Rolls In Posts v1.1
  6. //Copyright 4-23-2007 ~Wonder
  7. //May be reposted anywhere as long as this header remains in tact
  8. //Modified by Ross of vForums Support for vForums compatibility
  9. //Do you want the dice to line of horizontally(true) or vertically(false)
  10. diceAlignment=true;
  11. //Enter URL of the image you want to appear as the dice ubbc button
  12. UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
  13. //Enter the default # of sides
  14. defaultSides=20;
  15. //Enable dice in preview? true or false
  16. enablePreview=false;
  17. rs="";
  18. mainForm="";
  19. if(document.post_form || document.quick_reply_form) {
  20. if(document.post_form) {
  21. mainForm=document.post_form;
  22. if(location.href.match(/action\/modify/)){enablePreview=true;}
  23. ubbc_holder = document.createElement('span');
  24. get('ubbc_buttons', ID).appendChild(ubbc_holder);
  25. } else {
  26. ubbc_holder = get('quick_reply_ubbc', ID);
  27. mainForm=document.quick_reply_form;
  28. }
  29. ubbc_holder.innerHTML+="<a href=javascript:add_ubbc(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
  30. mainForm.onsubmit=addRand;
  31. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  32. rs=RegExp. ; rs=(/\[rand\=/.test(rs))?rs:"";
  33. if(location.href.match(/quote\/\d+/))
  34. {
  35. mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
  36. rs="";
  37. }
  38. }
  39. ///////////////////////
  40. if(location.href.match(/action\/(view_topic|search|recent|pm_view|post|modify|create_poll)/)) {
  41. td=document.getElementsByTagName("td");
  42. topic_summary = false;
  43. for(i=0;i<td.length;i++) {
  44. if(td.item(i).className == 'post' || topic_summary) {
  45. // Remove from message preview
  46. if(td.item(i).className == 'post' && location.href.match(/action\/(post|modify|create_poll)/) && !enablePreview) {
  47. td.item(i).innerHTML=td.item(i).innerHTML.replace(/\[rand\=(\d|\w|<|>|\/|\s)+\]/gi,"");
  48. }
  49. rand=td.item(i).innerHTML.match(/\[rand\=(\d|\w|<|>|\/|\s)+\]/);
  50. if(rand!=null) {
  51. td.item(i).innerHTML=td.item(i).innerHTML.replace(rand[0],"");
  52. rand=rand[0].replace(/[^\d]/g,"");
  53. dice=td.item(i).innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
  54. if(dice!=null) {
  55. for(k=0;k<dice.length;k++) {
  56. numb=dice[k].match(/\d+(\+\d+)?/);
  57. numb=numb[0].split("+");
  58. addon=numb.length>1?parseInt(numb[1],10):0;
  59. numb=parseInt(numb[0],10);
  60. roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
  61. td.item(i).innerHTML=td.item(i).innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table>  ");
  62. }
  63. }
  64. }
  65. } else if(td.item(i).className == 'title1' && td.item(i).innerHTML.match(/>Topic Summary</i)) {
  66. topic_summary = true;
  67. }
  68. }
  69. }
  70. function addRand() {
  71. tinyMCE.triggerSave(true, true);
  72. mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
  73. if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/))) {
  74. mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
  75. } else {
  76. mainForm.message.value+=rs;
  77. }
  78. disable(mainForm);
  79. }
  80. </script>
  81.  
 


I'm using this code on my forum :  http://tropolis.virtualforums.co.uk/  
and since the v2 update it stopped working .
But only for members if you view my dice game thread as an guest , you will see the dice fine , but once you login as an member the dice no longer show/work .

Re: Something Odd - Posted By Graham (amusedtodeath) on 12th Jul 09 at 5:18pm
Unless one of the coders can work this out, then this might have to wait for Ross when he gets back from holiday.

Re: Something Odd - Posted By Michael (wrighty) on 12th Jul 09 at 6:00pm
http://support.virtualforums.co.uk/board/coderequest/topic/27937/action/view_topic/dice-rolls-in-posts-code-fix-needed#reply-2

This code was fixed during the beta. {Smile}

Re: Something Odd - Posted By ManGoneMad (mgm) on 12th Jul 09 at 9:30pm
Wrighty, sorry to say , but no it wasn't, the post you pointed me to, in that thread,
was from before the up-grade to v2, (Tue, June 9th to be exact)
and it does not fix the problem.

I think the trouble is code adds a UBBC button, & function,
and in v2 we have the new WYSIWYG posting set-up. {Confused}

Just my $.02 worth. {Wink}

Re: Something Odd - Posted By Michael (wrighty) on 12th Jul 09 at 10:44pm
Yes, that would be the problem. So what I need you two to tell me is - how you'd like to go ahead with this? {Unsure} {Smile}

Re: Something Odd - Posted By CåñåÐå™ (canada) on 13th Jul 09 at 4:06am
I would like the code to work . If it can't i'll remove it.

But i think i did read on here you were going to write an code to change it to UBBC if members would have it the old way . Which i would like since i have no idea what most of the WYSIWYG really does.
If you do make the code , shouldn't/wouldn't the dice code go back to be in working order ?

Re: Something Odd - Posted By CåñåÐå™ (canada) on 17th Jul 09 at 2:50am
Does anyone have an idea ??

Why ?