Index: trunk/parsers/wikidom/lib/hype/bases/es.ModelNode.js |
— | — | @@ -23,6 +23,10 @@ |
24 | 24 | node.emit( 'update' ); |
25 | 25 | }; |
26 | 26 | |
| 27 | + // Properties |
| 28 | + node.parent = null; |
| 29 | + node.root = node; |
| 30 | + |
27 | 31 | // Children |
28 | 32 | if ( es.isArray( children ) ) { |
29 | 33 | for ( var i = 0; i < children.length; i++ ) { |
— | — | @@ -30,10 +34,6 @@ |
31 | 35 | } |
32 | 36 | } |
33 | 37 | |
34 | | - // Properties |
35 | | - node.parent = undefined; |
36 | | - node.root = node; |
37 | | - |
38 | 38 | return node; |
39 | 39 | }; |
40 | 40 | |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | es.ModelNode.prototype.attach = function( parent ) { |
218 | 218 | this.emit( 'beforeAttach', parent ); |
219 | 219 | this.parent = parent; |
220 | | - this.root = parent.getRoot(); |
| 220 | + this.setRoot( parent.getRoot() ); |
221 | 221 | this.emit( 'afterAttach', parent ); |
222 | 222 | }; |
223 | 223 | |
— | — | @@ -228,12 +228,37 @@ |
229 | 229 | */ |
230 | 230 | es.ModelNode.prototype.detach = function() { |
231 | 231 | this.emit( 'beforeDetach' ); |
232 | | - this.parent = undefined; |
233 | | - this.root = this; |
| 232 | + this.parent = null; |
| 233 | + this.clearRoot(); |
234 | 234 | this.emit( 'afterDetach' ); |
235 | 235 | }; |
236 | 236 | |
237 | 237 | /** |
| 238 | + * Sets the root node to this and all of it's children. |
| 239 | + * |
| 240 | + * @method |
| 241 | + * @param {es.ModelNode} root Node to use as root |
| 242 | + */ |
| 243 | +es.ModelNode.prototype.setRoot = function( root ) { |
| 244 | + this.root = root; |
| 245 | + for ( var i = 0; i < this.length; i++ ) { |
| 246 | + this[i].setRoot( root ); |
| 247 | + } |
| 248 | +}; |
| 249 | + |
| 250 | +/** |
| 251 | + * Clears the root node from this and all of it's children. |
| 252 | + * |
| 253 | + * @method |
| 254 | + */ |
| 255 | +es.ModelNode.prototype.clearRoot = function() { |
| 256 | + this.root = null; |
| 257 | + for ( var i = 0; i < this.length; i++ ) { |
| 258 | + this[i].clearRoot(); |
| 259 | + } |
| 260 | +}; |
| 261 | + |
| 262 | +/** |
238 | 263 | * Creates a view for this node. |
239 | 264 | * |
240 | 265 | * @method |