Neil wrote:
> Neil wrote:
> 
>> Tobias L�fgren wrote:
>>
>>> I decided last night to dive into the wonderful world of XUL and 
>>> mozilla  programming and can now present a small XUL-application 
>>> (based on the patch by Gervase Markham) that adds rot13 to the 
>>> mail/news-reader in a nice and modular way. Take a look at:
>>>
>>> http://www.pinkroom.biz/owl/minirot13/
>>>
>>> It can both decode in the reader and encode a selection in the composer.
>>
>>
>> There might be a more efficient way to do ROT13
> 
> 
> And there's also XPath iterators to get the text nodes...
> 
> function rot13tree(doc)
> {
>  var iterator = new XPathEvaluator();
>  var path = iterator.evaluate("//text()", doc, null, 
> XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
>  while (var node = path.iterateNext()) {
>    var data = rot13(node.data);
>    if (data != node.data)
>      node.replaceData(0, data.length, data); // node.data = data
>  }
> }
> 

Ah this is nice! I'm new at programming for the mozilla environment. But 
using the iteratior doesn't really seem that much efficient for this 
simple traversal of the entire tree? (I imagine the iterator itself will 
recurse behind the scenes?)

My main problem is in dealing with selections/ranges in a proper way in 
the composer. Right now I only to a simple toString() of the entire 
selection and replace the text with InsertText(), which of course 
destroys anything more advanced than plain text.

/tobias


Reply via email to