falaina

Untitled

Oct 27th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function traverseDOM(start){
  2.   var cc = function(){return scanNode(start, stop);};
  3.   function stop(){
  4.     cc = stop;
  5.     throw StopIteration;
  6.   }
  7.   function yield(value, c){
  8.     cc = c;
  9.     return value;
  10.   }
  11.  
  12.   function scanNode(node, c){
  13.     if (node.nextSibling)
  14.       var nextc = function(){return scanNode(node.nextSibling, c);};
  15.     else
  16.       var nextc = c;
  17.  
  18.     if (/* node is proper span element */)
  19.       return yield(node.firstChild.nodeValue, nextc);
  20.     else if (/* node is proper br element */)
  21.       return yield("\n", nextc);
  22.     else
  23.       /* flatten node, yield its textual content */;
  24.   }
  25.  
  26.   return {next: function(){return cc();}};
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment