Andrew Dupont wrote:
>> Do we want to address pseudo-elements that normally refer to text nodes
>> or fragments such as :first-letter, :first-line, and ::selection?
>>     
>
> I'd rather walk barefoot across a barbecue.
>   
Oh come now, I don't know how useful it would be :D, but it would 
certainly be smooth to be able to manipulate the DOM using something 
like this:

$$('#story p:first-letter').each(function(element) { 
element.morph('dramatic-cap'); });

<!--With html like this,-->
<div id="story"><p>It was the best of times, it was the worst of 
times<p></div>
<!--You would end up with a document equivalent to this-->
<div id="story"><p><span class="dramatic-cap">I</span><span>t was the 
best of times, it was the worst of times</span><p></div>

// :first-letter $$ selector
Selector.criteria.firstLetter = 'n = h.firstLetter(n, r); d= false;';
Selector.patterns.firstLetter = '/:first-letter(\b|$)/';
Selector.handler.firstLetter = function(nodes, root) {
  // collect matching nodes
  return nodes.collect(function(node) {
    // travel down the DOM until a node containing text is found
    while( typeof node.nodeValue == 'undefined' && node = node.down() ) {}
    // get the first letter
    var first = node.nodeValue.substring(0,1);
    // if the text!='', get the rest
    if( first ) {
      var rest = node.nodeValue.substring(1);
      // wrap the first character and the rest of the text in respective 
spans
      node.update('<span>'+first+'</span><span>'+rest+'</span>');
      // return the span containing the first character
      return node.down();
  });
}

Regards,
Ken




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to