Hi,

Element#select[1] will only return elements, not other kinds of
nodes.  To get the text nodes, you'll have to use the DOM directly.
Assuming 'el' references the element you want to process, this
recursive-descent function should do it (I've used 'otherparams' where
you'll probably want replacement information):

* * * *
function process(el, otherparams)
{
    var child;
    for (child = el.firstChild; child; child = child.nextSibling)
    {
        switch (child.nodeType)
        {
            case Node.TEXT_NODE:
                // ...process it...
                log('Node: ' + child.nodeValue);
                break;
            case Node.ELEMENT_NODE:
                process(child, otherparams);
                break;
        }
    }
}
* * * *
Also on pastie: http://pastie.org/319505

Note that since that's recursive descent, you may want to handle the
possibility of one of these things you're targeting containing
something else you're targeting, or containing a 'doNotDisturb'
element.  I was going to post a single-layer version (basically just
ditch the second case from the switch, probably make the switch an
if), but the thing with single-layer is that <strong>, <em>, etc. are
all elements and you will (I assume) want to process their contents.

Re Jay's comment:  If you're using a proper doctype (we've found out
subsequently), you're fine with the upper case in the selector.  There
was a Safari problem, but it was only in quirks mode.  (There's an IE
problem where it matches things case-insensitive, but I suspect you
don't have both 'systemMessage' and 'systemmessage'...)

HTH,
--
T.J. Crowder
tj / crowder software / com

On Nov 19, 11:22 pm, lskatz <[EMAIL PROTECTED]> wrote:
> Hi,
> I want to automatically set up abbreviation tags everywhere in my
> document, and it works great, except I am altering the innerHTML to do
> so and sometimes some crazy results happen.  For instance, an input's
> value should be untouched because the value should not be value="<abbr
> title='united states of america'>USA</abbr>"
>
> I believe the way to go would be to select for textnodes but I cannot
> figure out why that wouldn't work.  Anyway, any help to fix my code
> would be appreciated (I hope the indentation is preserved when I post
> this).
>
> // find and add in abbr all over the place!
> var replacing={
>                 'TSV':'Tab-Separated Values',
>                 'CSV':'Comma-Separated Values',
>                'STs?':'Sequence Type',
>                'CCs?':'Clonal Complex',
>                'MGIP':'Meningococcus Genome Informatics Platform',
>                'MLST':'Multilocus Sequence Typing',
>                'GIT':'Georgia Institute of Technology',
>                'CDC':'Centers for Disease Control and Prevention',
>                'OMP':'Outer Membrane Protein'
>             };
> $$('.systemMessage, .body p,.body
> div,label,h1,h2,h3,h4,.menu.firefox').each(function(el){
>   if(el.hasClassName('doNotDisturb')){
>     return; // equivalent to a continue inside of an each loop
>   }
>   el.select('text').each(function(s){
>     debug('textNode: '+s);
>   });
>   for(var k in replacing){
>     var v=replacing[k];
>         var find=new RegExp('\\b('+k+')\\b','g');
>         // I should use something like innerContext or innerText
> instead of innerHTML
>         el.update(el.innerHTML.replace(find,"<acronym title='"+v+"'>
> $1</acronym>",''));
>    }
>
> });
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to