//
// this might help:
//
// traverse.dom(
// function() {
// // this === current_node ( inside callback )
// // doStuffWith( this );
// // return ( === )false, to break iteration
// },
//
// startNode // provide a node to start traversing from ( it is included in traversal )
//
// );
//
//
// $.ajax({
// url : 'xmlsimple.xml',
// dataType : 'xml',
// success : function( doc ) {
// traverse.dom( function() { console.log( this ); }, doc );
// }
// });
//
;
( function( w, _a ) {
var
pn = this.toString(),
F = {},
t = !0,
f = !t,
_s = _a.slice,
_d = w.document;
function _gather_nodes( node, coll ) {
coll.push( node );
node = node.firstChild;
while ( node ) {
_gather_nodes( node, coll );
node = node.nextSibling;
}
return coll;
}
_a.each = function( callback ) {
return ( function ( fn, len, k ) {
for ( ; k < len ; k++ )
if (
( function( i ) {
return fn.call( this, i, this[i] );
} ).call( this, k ) === f ) break;
return this;
} ).call( this, callback, this.length, 0 );
};
F.dom = function( callback_fn, startNode/*, ...args*/ ) {
var
args1 = _s.call( arguments, 2 );
return ( _gather_nodes( ( startNode || _d ), [] ) ).each( function ( pos, N ) {
return callback_fn.apply( N, args1 );
} );
};
w[pn] = F;
} ).call( new String('traverse'), window, Array.prototype );