-<html>
-<head>
- <title>The source code</title>
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
-</head>
-<body onload="prettyPrint();">
- <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-<div id="cls-Ext.data.Tree"></div>/**\r
+<html>\r
+<head>\r
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \r
+ <title>The source code</title>\r
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
+</head>\r
+<body onload="prettyPrint();">\r
+ <pre class="prettyprint lang-js"><div id="cls-Ext.data.Tree"></div>/**\r
* @class Ext.data.Tree\r
* @extends Ext.util.Observable\r
* Represents a tree data structure and bubbles all the events for its nodes. The nodes\r
/**\r
* Removes a child node from this node.\r
* @param {Node} node The node to remove\r
+ * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.\r
* @return {Node} The removed node\r
*/\r
- removeChild : function(node){\r
+ removeChild : function(node, destroy){\r
var index = this.childNodes.indexOf(node);\r
if(index == -1){\r
return false;\r
this.setLastChild(node.previousSibling);\r
}\r
\r
- node.setOwnerTree(null);\r
- // clear any references from the node\r
- node.parentNode = null;\r
- node.previousSibling = null;\r
- node.nextSibling = null;\r
+ node.clear();\r
this.fireEvent("remove", this.ownerTree, this, node);\r
+ if(destroy){\r
+ node.destroy();\r
+ }\r
return node;\r
},\r
+ \r
+ // private\r
+ clear : function(destroy){\r
+ // clear any references from the node\r
+ this.setOwnerTree(null, destroy);\r
+ this.parentNode = this.previousSibling = this.nextSibling = null\r
+ if(destroy){\r
+ this.firstChild = this.lastChild = null; \r
+ }\r
+ },\r
+ \r
+ /**\r
+ * Destroys the node.\r
+ */\r
+ destroy : function(){\r
+ this.purgeListeners();\r
+ this.clear(true); \r
+ Ext.each(this.childNodes, function(n){\r
+ n.destroy();\r
+ });\r
+ this.childNodes = null;\r
+ },\r
\r
/**\r
* Inserts the first node before the second node in this nodes childNodes collection.\r
\r
/**\r
* Removes this node from its parent\r
+ * @param {Boolean} destroy <tt>true</tt> to destroy the node upon removal. Defaults to <tt>false</tt>.\r
* @return {Node} this\r
*/\r
- remove : function(){\r
- this.parentNode.removeChild(this);\r
+ remove : function(destroy){\r
+ this.parentNode.removeChild(this, destroy);\r
return this;\r
},\r
\r
},\r
\r
// private\r
- setOwnerTree : function(tree){\r
+ setOwnerTree : function(tree, destroy){\r
// if it is a move, we need to update everyone\r
if(tree != this.ownerTree){\r
if(this.ownerTree){\r
this.ownerTree.unregisterNode(this);\r
}\r
this.ownerTree = tree;\r
- var cs = this.childNodes;\r
- for(var i = 0, len = cs.length; i < len; i++) {\r
- cs[i].setOwnerTree(tree);\r
+ // If we're destroying, we don't need to recurse since it will be called on each child node\r
+ if(destroy !== true){\r
+ Ext.each(this.childNodes, function(n){\r
+ n.setOwnerTree(tree);\r
+ });\r
}\r
if(tree){\r
tree.registerNode(this);\r
},\r
\r
/**\r
- * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
+ * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function\r
* will be the args provided or the current node. If the function returns false at any point,\r
* the bubble is stopped.\r
* @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.\r
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)\r
*/\r
bubble : function(fn, scope, args){\r
var p = this;\r
},\r
\r
/**\r
- * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
+ * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function\r
* will be the args provided or the current node. If the function returns false at any point,\r
* the cascade is stopped on that branch.\r
* @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.\r
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)\r
*/\r
cascade : function(fn, scope, args){\r
if(fn.apply(scope || this, args || [this]) !== false){\r
},\r
\r
/**\r
- * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of\r
- * function call will be the scope provided or the current node. The arguments to the function\r
+ * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function\r
* will be the args provided or the current node. If the function returns false at any point,\r
* the iteration stops.\r
* @param {Function} fn The function to call\r
- * @param {Object} scope (optional) The scope of the function (defaults to current node)\r
- * @param {Array} args (optional) The args to call the function with (default to passing the current node)\r
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node in the iteration.\r
+ * @param {Array} args (optional) The args to call the function with (default to passing the current Node)\r
*/\r
eachChild : function(fn, scope, args){\r
var cs = this.childNodes;\r
},\r
\r
/**\r
- * Finds the first child by a custom function. The child matches if the function passed\r
- * returns true.\r
- * @param {Function} fn\r
- * @param {Object} scope (optional)\r
+ * Finds the first child by a custom function. The child matches if the function passed returns <code>true</code>.\r
+ * @param {Function} fn A function which must return <code>true</code> if the passed Node is the required Node.\r
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Node being tested.\r
* @return {Node} The found child or null if none was found\r
*/\r
findChildBy : function(fn, scope){\r
},\r
\r
/**\r
- * Sorts this nodes children using the supplied sort function\r
- * @param {Function} fn\r
- * @param {Object} scope (optional)\r
+ * Sorts this nodes children using the supplied sort function.\r
+ * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.\r
+ * @param {Object} scope (optional)The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.\r
*/\r
sort : function(fn, scope){\r
var cs = this.childNodes;\r
toString : function(){\r
return "[Node"+(this.id?" "+this.id:"")+"]";\r
}\r
-});</pre>
-</body>
+});</pre> \r
+</body>\r
</html>
\ No newline at end of file