vForums Support Banner


Visit Base Classics - Gaming Chairs

 

Welcome Guest! Please Login or Register
vForums Support :: Programming & Coding :: Database of Codes/Hacks/Mods :: Spoiler Script - View Topic
Topic Rating: *****
Printable View
Dranew
New Member
*

Posts: 10
Status: Offline
Gender: Male
Location: Michigan, U.S.A.
Age: 37
Joined:  
Reputation: 0%  


pmwwwmsnyahooaim
Spoiler Script (21st Mar 08 at 4:38am UTC)
Tested in: IE, Firefox, and Opera

look at the preview to see what this does

Preview: http://img.photobucket.com/albums/v102/Dark_Sage/vForums/spoilerpreview2.gif

Place in Global Footer:
Code:
 
  1. <style type="text/css">
  2. #spoiler {
  3. background: #dddddd;
  4. border: #000000 1px solid;
  5. }
  6.  
  7. #spoiler .head {
  8. background: #e0e0e0;
  9. display: block;
  10. padding: 3px;
  11. font-weight: bold;
  12. }
  13.  
  14. #spoiler .text {
  15. display: block;
  16. border-top: #000000 1px solid;
  17. padding: 5px;
  18. }
  19. </style>
  20.  
  21. <script type="text/javascript">
  22. <!--
  23. //Spoiler Script
  24. //Written by Dranew
  25. //Do not rip or claim as your own.
  26.  
  27. if(location.href.match(/view_topic/)) {
  28.   var post = get('td','tag');
  29.   var sid = 0;
  30.   for(a=0;a<post.length;a++) {
  31.     if(post[a].className == "post") {
  32.       post[a].innerHTML = post[a].innerHTML.replace(/\[spoiler\]/g, "<div id='spoiler'>").replace(/\[\/spoiler\]/g, "</div>");
  33.     }
  34.   }
  35.   for(b=0;b<post.length;b++) {
  36.     if(post[b].className == "post") {
  37.       var div = post[b].getElementsByTagName('div')
  38.       for(c=0;c<div.length;c++) {
  39.         if(div[c].id == "spoiler") {
  40.           var spoil = div[c].innerHTML
  41.           div[c].innerHTML = "<span class='head''><a href='javascript:dispSpoil("+sid+")' id='sl"+sid+"'>Open Spoiler</a></span><span class='text' style='display: none;' id='s"+sid+"'>"+spoil+"</span>";
  42.           sid++
  43.         }
  44.       }
  45.     }
  46.   }
  47.   function dispSpoil(ID) {
  48.     var spoilText = document.getElementById("s"+ID)
  49.     var spoilLabel = document.getElementById("sl"+ID)
  50.     spoilLabel.innerHTML = (spoilLabel.innerHTML == "Open Spoiler")? 'Close Spoiler' : 'Open Spoiler';
  51.     spoilText.style.display = (spoilText.style.display == "none")? '' : 'none';
  52.   }
  53. }
  54.  
  55. //-->
  56. </script>
 


to edit:

Only edit the styles

#spoiler { edit the background: to the background of the spoiler
#spoiler .head { change the background: of where it says "Open Spoiler"

if you have knowledge of CSS then make your own style {Tongue Out}

o_O
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: Spoiler Script (21st Mar 08 at 10:04am UTC)
looks like a cool code. Does it just expand/collapse? {Smile}
Dranew
New Member
*

Posts: 10
Status: Offline
Gender: Male
Location: Michigan, U.S.A.
Age: 37
Joined:  
Reputation: 0%  


pmwwwmsnyahooaim
Re: Spoiler Script (21st Mar 08 at 7:42pm UTC)
yup, thats about it.
I've seen other spoiler scripts that you have to highlight the code. I wanted to be different {Tongue Out}

o_O
Michael
Moderator
*****

[Avatar]
Recoding the future

Posts: 4,043
Status: Offline
Gender: Male
Location: UK
Joined:  

Additional Groups:
Coding Team
***


Reputation: 58%  


pmtwittervForum
Re: Spoiler Script (21st Mar 08 at 7:44pm UTC)
No, that's fine. It's cool to be different! {Smile}
 Printable View

All times are GMT+0 :: The current time is 7:44am
Page generated in 0.2832 seconds
This Forum is Powered By vForums (v2.4)
Create a Forum for Free | Find Forums