Index: trunk/extensions/VisualEditor/modules/es/bases/es.DocumentNode.js |
— | — | @@ -52,6 +52,23 @@ |
53 | 53 | throw 'DocumentNode.hasChildren not implemented in this subclass:' + this.constructor; |
54 | 54 | }; |
55 | 55 | |
| 56 | +/** |
| 57 | + * Traverse tree of nodes (model or view) upstream and for each traversed node call callback function passing traversed node as a parameter. |
| 58 | + * Callback function is called for node passed as node paramter as well. |
| 59 | + * |
| 60 | + * @param {es.DocumentNode} node Node from which to start traversing |
| 61 | + * @param {function} callback Callback method to be called for every traversed node |
| 62 | + * @method |
| 63 | + */ |
| 64 | +es.DocumentNode.traverseUpstream = function( node, callback ) { |
| 65 | + while ( node ) { |
| 66 | + if ( callback ( node ) === false ) { |
| 67 | + break; |
| 68 | + } |
| 69 | + node = node.getParent(); |
| 70 | + } |
| 71 | +}; |
| 72 | + |
56 | 73 | /* Inheritance */ |
57 | 74 | |
58 | | -es.extendClass( es.DocumentNode, es.EventEmitter ); |
| 75 | +es.extendClass( es.DocumentNode, es.EventEmitter ); |
\ No newline at end of file |