What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Javascript spoiler tag help (solved + added final code)

Javascript spoiler tag help (solved + added final code)
Author: Message:
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
34 / Male / –
Joined: Jun 2004
RE: Javascript spoiler tag help
you could use this function to get the elements background:
code:
function getBgColor(){
    var node = document.getElementById("spanOne");
    var style = document.defaultView.getComputedStyle(node, '').getPropertyValue("background-color");
    while(style == "transparent"){
        if(node.parentNode != document){
            node = node.parentNode;
            style = document.defaultView.getComputedStyle(node, '').getPropertyValue("background-color");
        }
        else{
            style = "rgb(255, 255, 255)";
        }
    }
    return style;
}

Its basically loops through the elements parents nodes, until it finds one that isn't transparent and returns the background color.

so for example you could use:
code:
var nodes, defaultColor;

function spoiler(){
    if(!nodes){//If nodes is undefined then this is the first time so set up the defaults and nodes
        nodes = document.evaluate("//*[@class='spoiler']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);//Use XPath to get all the nodes with the class 'spoiler'
        defaultColor = document.defaultView.getComputedStyle(nodes.snapshotItem(0), '').getPropertyValue("color");//Use the color of the first one as the default value
        }
    for(var i=0;i<nodes.snapshotLength;i++){//Loop through the nodes
        var node = nodes.snapshotItem(i);//Make life easy
        var color = document.defaultView.getComputedStyle(node, '').getPropertyValue("color");//Get the nodes color
        if(color == defaultColor){//If its the default color, hide it
            node.style.color = getBgColor(node);//With our cool func
        }
        else{
            node.style.color = defaultColor;//Otherwise set it back to the default color
        }
    }
}
and
code:
<a href="#" onClick="spoiler()">Spoilers (on/off)</a>

and that should work, the only limitation is it doesn't support different colors (but if they are all one class why should they be a different color :P)
Oh and you have to call the spoiler function to hide the text at the start :P

Just say if you need help :P and don't forget to include the getBgColor func in your script :P


Ignore all of that, as it won't work in IE :dodgy:

* Plik has been coding to many userscripts :P

This post was edited on 03-01-2006 at 11:32 PM by Plik.
03-01-2006 10:55 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Javascript spoiler tag help (solved + added final code) - by Ezra on 03-01-2006 at 08:06 PM
RE: Javascript spoiler tag help - by matty on 03-01-2006 at 08:08 PM
RE: Javascript spoiler tag help - by wj on 03-01-2006 at 08:09 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 08:13 PM
RE: Javascript spoiler tag help - by wj on 03-01-2006 at 08:15 PM
RE: Javascript spoiler tag help - by WDZ on 03-01-2006 at 08:22 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 08:25 PM
RE: Javascript spoiler tag help - by matty on 03-01-2006 at 09:49 PM
RE: Javascript spoiler tag help - by wj on 03-01-2006 at 10:06 PM
RE: Javascript spoiler tag help - by ShawnZ on 03-01-2006 at 10:18 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 10:42 PM
RE: Javascript spoiler tag help - by Plik on 03-01-2006 at 10:55 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 11:01 PM
RE: Javascript spoiler tag help - by Plik on 03-01-2006 at 11:06 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 11:08 PM
RE: Javascript spoiler tag help - by Plik on 03-01-2006 at 11:13 PM
RE: Javascript spoiler tag help - by Ezra on 03-01-2006 at 11:16 PM
RE: Javascript spoiler tag help - by Plik on 03-01-2006 at 11:20 PM
RE: Javascript spoiler tag help - by Ezra on 03-02-2006 at 12:03 AM
RE: Javascript spoiler tag help (solved + added final code) - by ShawnZ on 03-02-2006 at 12:31 AM
RE: Javascript spoiler tag help (solved + added final code) - by -dt- on 03-02-2006 at 02:54 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On