You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

846 lines
32 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-data-Tree-method-constructor'><span id='Ext-data-Tree'>/**
  19. </span></span> * @class Ext.data.Tree
  20. * @extends Ext.util.Observable
  21. * Represents a tree data structure and bubbles all the events for its nodes. The nodes
  22. * in the tree have most standard DOM functionality.
  23. * @constructor
  24. * @param {Node} root (optional) The root node
  25. */
  26. Ext.data.Tree = Ext.extend(Ext.util.Observable, {
  27. constructor: function(root){
  28. this.nodeHash = {};
  29. <span id='Ext-data-Tree-property-root'> /**
  30. </span> * The root node for this tree
  31. * @type Node
  32. */
  33. this.root = null;
  34. if(root){
  35. this.setRootNode(root);
  36. }
  37. this.addEvents(
  38. <span id='Ext-data-Tree-event-append'> /**
  39. </span> * @event append
  40. * Fires when a new child node is appended to a node in this tree.
  41. * @param {Tree} tree The owner tree
  42. * @param {Node} parent The parent node
  43. * @param {Node} node The newly appended node
  44. * @param {Number} index The index of the newly appended node
  45. */
  46. &quot;append&quot;,
  47. <span id='Ext-data-Tree-event-remove'> /**
  48. </span> * @event remove
  49. * Fires when a child node is removed from a node in this tree.
  50. * @param {Tree} tree The owner tree
  51. * @param {Node} parent The parent node
  52. * @param {Node} node The child node removed
  53. */
  54. &quot;remove&quot;,
  55. <span id='Ext-data-Tree-event-move'> /**
  56. </span> * @event move
  57. * Fires when a node is moved to a new location in the tree
  58. * @param {Tree} tree The owner tree
  59. * @param {Node} node The node moved
  60. * @param {Node} oldParent The old parent of this node
  61. * @param {Node} newParent The new parent of this node
  62. * @param {Number} index The index it was moved to
  63. */
  64. &quot;move&quot;,
  65. <span id='Ext-data-Tree-event-insert'> /**
  66. </span> * @event insert
  67. * Fires when a new child node is inserted in a node in this tree.
  68. * @param {Tree} tree The owner tree
  69. * @param {Node} parent The parent node
  70. * @param {Node} node The child node inserted
  71. * @param {Node} refNode The child node the node was inserted before
  72. */
  73. &quot;insert&quot;,
  74. <span id='Ext-data-Tree-event-beforeappend'> /**
  75. </span> * @event beforeappend
  76. * Fires before a new child is appended to a node in this tree, return false to cancel the append.
  77. * @param {Tree} tree The owner tree
  78. * @param {Node} parent The parent node
  79. * @param {Node} node The child node to be appended
  80. */
  81. &quot;beforeappend&quot;,
  82. <span id='Ext-data-Tree-event-beforeremove'> /**
  83. </span> * @event beforeremove
  84. * Fires before a child is removed from a node in this tree, return false to cancel the remove.
  85. * @param {Tree} tree The owner tree
  86. * @param {Node} parent The parent node
  87. * @param {Node} node The child node to be removed
  88. */
  89. &quot;beforeremove&quot;,
  90. <span id='Ext-data-Tree-event-beforemove'> /**
  91. </span> * @event beforemove
  92. * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
  93. * @param {Tree} tree The owner tree
  94. * @param {Node} node The node being moved
  95. * @param {Node} oldParent The parent of the node
  96. * @param {Node} newParent The new parent the node is moving to
  97. * @param {Number} index The index it is being moved to
  98. */
  99. &quot;beforemove&quot;,
  100. <span id='Ext-data-Tree-event-beforeinsert'> /**
  101. </span> * @event beforeinsert
  102. * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
  103. * @param {Tree} tree The owner tree
  104. * @param {Node} parent The parent node
  105. * @param {Node} node The child node to be inserted
  106. * @param {Node} refNode The child node the node is being inserted before
  107. */
  108. &quot;beforeinsert&quot;
  109. );
  110. Ext.data.Tree.superclass.constructor.call(this);
  111. },
  112. <span id='Ext-data-Tree-cfg-pathSeparator'> /**
  113. </span> * @cfg {String} pathSeparator
  114. * The token used to separate paths in node ids (defaults to '/').
  115. */
  116. pathSeparator: &quot;/&quot;,
  117. <span id='Ext-data-Tree-method-proxyNodeEvent'> // private
  118. </span> proxyNodeEvent : function(){
  119. return this.fireEvent.apply(this, arguments);
  120. },
  121. <span id='Ext-data-Tree-method-getRootNode'> /**
  122. </span> * Returns the root node for this tree.
  123. * @return {Node}
  124. */
  125. getRootNode : function(){
  126. return this.root;
  127. },
  128. <span id='Ext-data-Tree-method-setRootNode'> /**
  129. </span> * Sets the root node for this tree.
  130. * @param {Node} node
  131. * @return {Node}
  132. */
  133. setRootNode : function(node){
  134. this.root = node;
  135. node.ownerTree = this;
  136. node.isRoot = true;
  137. this.registerNode(node);
  138. return node;
  139. },
  140. <span id='Ext-data-Tree-method-getNodeById'> /**
  141. </span> * Gets a node in this tree by its id.
  142. * @param {String} id
  143. * @return {Node}
  144. */
  145. getNodeById : function(id){
  146. return this.nodeHash[id];
  147. },
  148. <span id='Ext-data-Tree-method-registerNode'> // private
  149. </span> registerNode : function(node){
  150. this.nodeHash[node.id] = node;
  151. },
  152. <span id='Ext-data-Tree-method-unregisterNode'> // private
  153. </span> unregisterNode : function(node){
  154. delete this.nodeHash[node.id];
  155. },
  156. <span id='Ext-data-Tree-method-toString'> toString : function(){
  157. </span> return &quot;[Tree&quot;+(this.id?&quot; &quot;+this.id:&quot;&quot;)+&quot;]&quot;;
  158. }
  159. });
  160. <span id='Ext-data-Node-method-constructor'><span id='Ext-data-Node-cfg-id'><span id='Ext-data-Node-cfg-leaf'><span id='Ext-data-Node'>/**
  161. </span></span></span></span> * @class Ext.data.Node
  162. * @extends Ext.util.Observable
  163. * @cfg {Boolean} leaf true if this node is a leaf and does not have children
  164. * @cfg {String} id The id for this node. If one is not specified, one is generated.
  165. * @constructor
  166. * @param {Object} attributes The attributes/config for the node
  167. */
  168. Ext.data.Node = Ext.extend(Ext.util.Observable, {
  169. constructor: function(attributes){
  170. <span id='Ext-data-Node-property-attributes'> /**
  171. </span> * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
  172. * @type {Object}
  173. */
  174. this.attributes = attributes || {};
  175. this.leaf = this.attributes.leaf;
  176. <span id='Ext-data-Node-property-id'> /**
  177. </span> * The node id. @type String
  178. */
  179. this.id = this.attributes.id;
  180. if(!this.id){
  181. this.id = Ext.id(null, &quot;xnode-&quot;);
  182. this.attributes.id = this.id;
  183. }
  184. <span id='Ext-data-Node-property-childNodes'> /**
  185. </span> * All child nodes of this node. @type Array
  186. */
  187. this.childNodes = [];
  188. <span id='Ext-data-Node-property-parentNode'> /**
  189. </span> * The parent node for this node. @type Node
  190. */
  191. this.parentNode = null;
  192. <span id='Ext-data-Node-property-firstChild'> /**
  193. </span> * The first direct child node of this node, or null if this node has no child nodes. @type Node
  194. */
  195. this.firstChild = null;
  196. <span id='Ext-data-Node-property-lastChild'> /**
  197. </span> * The last direct child node of this node, or null if this node has no child nodes. @type Node
  198. */
  199. this.lastChild = null;
  200. <span id='Ext-data-Node-property-previousSibling'> /**
  201. </span> * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
  202. */
  203. this.previousSibling = null;
  204. <span id='Ext-data-Node-property-nextSibling'> /**
  205. </span> * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
  206. */
  207. this.nextSibling = null;
  208. this.addEvents({
  209. <span id='Ext-data-Node-event-append'> /**
  210. </span> * @event append
  211. * Fires when a new child node is appended
  212. * @param {Tree} tree The owner tree
  213. * @param {Node} this This node
  214. * @param {Node} node The newly appended node
  215. * @param {Number} index The index of the newly appended node
  216. */
  217. &quot;append&quot; : true,
  218. <span id='Ext-data-Node-event-remove'> /**
  219. </span> * @event remove
  220. * Fires when a child node is removed
  221. * @param {Tree} tree The owner tree
  222. * @param {Node} this This node
  223. * @param {Node} node The removed node
  224. */
  225. &quot;remove&quot; : true,
  226. <span id='Ext-data-Node-event-move'> /**
  227. </span> * @event move
  228. * Fires when this node is moved to a new location in the tree
  229. * @param {Tree} tree The owner tree
  230. * @param {Node} this This node
  231. * @param {Node} oldParent The old parent of this node
  232. * @param {Node} newParent The new parent of this node
  233. * @param {Number} index The index it was moved to
  234. */
  235. &quot;move&quot; : true,
  236. <span id='Ext-data-Node-event-insert'> /**
  237. </span> * @event insert
  238. * Fires when a new child node is inserted.
  239. * @param {Tree} tree The owner tree
  240. * @param {Node} this This node
  241. * @param {Node} node The child node inserted
  242. * @param {Node} refNode The child node the node was inserted before
  243. */
  244. &quot;insert&quot; : true,
  245. <span id='Ext-data-Node-event-beforeappend'> /**
  246. </span> * @event beforeappend
  247. * Fires before a new child is appended, return false to cancel the append.
  248. * @param {Tree} tree The owner tree
  249. * @param {Node} this This node
  250. * @param {Node} node The child node to be appended
  251. */
  252. &quot;beforeappend&quot; : true,
  253. <span id='Ext-data-Node-event-beforeremove'> /**
  254. </span> * @event beforeremove
  255. * Fires before a child is removed, return false to cancel the remove.
  256. * @param {Tree} tree The owner tree
  257. * @param {Node} this This node
  258. * @param {Node} node The child node to be removed
  259. */
  260. &quot;beforeremove&quot; : true,
  261. <span id='Ext-data-Node-event-beforemove'> /**
  262. </span> * @event beforemove
  263. * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
  264. * @param {Tree} tree The owner tree
  265. * @param {Node} this This node
  266. * @param {Node} oldParent The parent of this node
  267. * @param {Node} newParent The new parent this node is moving to
  268. * @param {Number} index The index it is being moved to
  269. */
  270. &quot;beforemove&quot; : true,
  271. <span id='Ext-data-Node-event-beforeinsert'> /**
  272. </span> * @event beforeinsert
  273. * Fires before a new child is inserted, return false to cancel the insert.
  274. * @param {Tree} tree The owner tree
  275. * @param {Node} this This node
  276. * @param {Node} node The child node to be inserted
  277. * @param {Node} refNode The child node the node is being inserted before
  278. */
  279. &quot;beforeinsert&quot; : true
  280. });
  281. this.listeners = this.attributes.listeners;
  282. Ext.data.Node.superclass.constructor.call(this);
  283. },
  284. <span id='Ext-data-Node-method-fireEvent'> // private
  285. </span> fireEvent : function(evtName){
  286. // first do standard event for this node
  287. if(Ext.data.Node.superclass.fireEvent.apply(this, arguments) === false){
  288. return false;
  289. }
  290. // then bubble it up to the tree if the event wasn't cancelled
  291. var ot = this.getOwnerTree();
  292. if(ot){
  293. if(ot.proxyNodeEvent.apply(ot, arguments) === false){
  294. return false;
  295. }
  296. }
  297. return true;
  298. },
  299. <span id='Ext-data-Node-method-isLeaf'> /**
  300. </span> * Returns true if this node is a leaf
  301. * @return {Boolean}
  302. */
  303. isLeaf : function(){
  304. return this.leaf === true;
  305. },
  306. <span id='Ext-data-Node-method-setFirstChild'> // private
  307. </span> setFirstChild : function(node){
  308. this.firstChild = node;
  309. },
  310. <span id='Ext-data-Node-method-setLastChild'> //private
  311. </span> setLastChild : function(node){
  312. this.lastChild = node;
  313. },
  314. <span id='Ext-data-Node-method-isLast'> /**
  315. </span> * Returns true if this node is the last child of its parent
  316. * @return {Boolean}
  317. */
  318. isLast : function(){
  319. return (!this.parentNode ? true : this.parentNode.lastChild == this);
  320. },
  321. <span id='Ext-data-Node-method-isFirst'> /**
  322. </span> * Returns true if this node is the first child of its parent
  323. * @return {Boolean}
  324. */
  325. isFirst : function(){
  326. return (!this.parentNode ? true : this.parentNode.firstChild == this);
  327. },
  328. <span id='Ext-data-Node-method-hasChildNodes'> /**
  329. </span> * Returns true if this node has one or more child nodes, else false.
  330. * @return {Boolean}
  331. */
  332. hasChildNodes : function(){
  333. return !this.isLeaf() &amp;&amp; this.childNodes.length &gt; 0;
  334. },
  335. <span id='Ext-data-Node-method-isExpandable'> /**
  336. </span> * Returns true if this node has one or more child nodes, or if the &lt;tt&gt;expandable&lt;/tt&gt;
  337. * node attribute is explicitly specified as true (see {@link #attributes}), otherwise returns false.
  338. * @return {Boolean}
  339. */
  340. isExpandable : function(){
  341. return this.attributes.expandable || this.hasChildNodes();
  342. },
  343. <span id='Ext-data-Node-method-appendChild'> /**
  344. </span> * Insert node(s) as the last child node of this node.
  345. * @param {Node/Array} node The node or Array of nodes to append
  346. * @return {Node} The appended node if single append, or null if an array was passed
  347. */
  348. appendChild : function(node){
  349. var multi = false;
  350. if(Ext.isArray(node)){
  351. multi = node;
  352. }else if(arguments.length &gt; 1){
  353. multi = arguments;
  354. }
  355. // if passed an array or multiple args do them one by one
  356. if(multi){
  357. for(var i = 0, len = multi.length; i &lt; len; i++) {
  358. this.appendChild(multi[i]);
  359. }
  360. }else{
  361. if(this.fireEvent(&quot;beforeappend&quot;, this.ownerTree, this, node) === false){
  362. return false;
  363. }
  364. var index = this.childNodes.length;
  365. var oldParent = node.parentNode;
  366. // it's a move, make sure we move it cleanly
  367. if(oldParent){
  368. if(node.fireEvent(&quot;beforemove&quot;, node.getOwnerTree(), node, oldParent, this, index) === false){
  369. return false;
  370. }
  371. oldParent.removeChild(node);
  372. }
  373. index = this.childNodes.length;
  374. if(index === 0){
  375. this.setFirstChild(node);
  376. }
  377. this.childNodes.push(node);
  378. node.parentNode = this;
  379. var ps = this.childNodes[index-1];
  380. if(ps){
  381. node.previousSibling = ps;
  382. ps.nextSibling = node;
  383. }else{
  384. node.previousSibling = null;
  385. }
  386. node.nextSibling = null;
  387. this.setLastChild(node);
  388. node.setOwnerTree(this.getOwnerTree());
  389. this.fireEvent(&quot;append&quot;, this.ownerTree, this, node, index);
  390. if(oldParent){
  391. node.fireEvent(&quot;move&quot;, this.ownerTree, node, oldParent, this, index);
  392. }
  393. return node;
  394. }
  395. },
  396. <span id='Ext-data-Node-method-removeChild'> /**
  397. </span> * Removes a child node from this node.
  398. * @param {Node} node The node to remove
  399. * @param {Boolean} destroy &lt;tt&gt;true&lt;/tt&gt; to destroy the node upon removal. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  400. * @return {Node} The removed node
  401. */
  402. removeChild : function(node, destroy){
  403. var index = this.childNodes.indexOf(node);
  404. if(index == -1){
  405. return false;
  406. }
  407. if(this.fireEvent(&quot;beforeremove&quot;, this.ownerTree, this, node) === false){
  408. return false;
  409. }
  410. // remove it from childNodes collection
  411. this.childNodes.splice(index, 1);
  412. // update siblings
  413. if(node.previousSibling){
  414. node.previousSibling.nextSibling = node.nextSibling;
  415. }
  416. if(node.nextSibling){
  417. node.nextSibling.previousSibling = node.previousSibling;
  418. }
  419. // update child refs
  420. if(this.firstChild == node){
  421. this.setFirstChild(node.nextSibling);
  422. }
  423. if(this.lastChild == node){
  424. this.setLastChild(node.previousSibling);
  425. }
  426. this.fireEvent(&quot;remove&quot;, this.ownerTree, this, node);
  427. if(destroy){
  428. node.destroy(true);
  429. }else{
  430. node.clear();
  431. }
  432. return node;
  433. },
  434. <span id='Ext-data-Node-method-clear'> // private
  435. </span> clear : function(destroy){
  436. // clear any references from the node
  437. this.setOwnerTree(null, destroy);
  438. this.parentNode = this.previousSibling = this.nextSibling = null;
  439. if(destroy){
  440. this.firstChild = this.lastChild = null;
  441. }
  442. },
  443. <span id='Ext-data-Node-method-destroy'> /**
  444. </span> * Destroys the node.
  445. */
  446. destroy : function(/* private */ silent){
  447. /*
  448. * Silent is to be used in a number of cases
  449. * 1) When setRootNode is called.
  450. * 2) When destroy on the tree is called
  451. * 3) For destroying child nodes on a node
  452. */
  453. if(silent === true){
  454. this.purgeListeners();
  455. this.clear(true);
  456. Ext.each(this.childNodes, function(n){
  457. n.destroy(true);
  458. });
  459. this.childNodes = null;
  460. }else{
  461. this.remove(true);
  462. }
  463. },
  464. <span id='Ext-data-Node-method-insertBefore'> /**
  465. </span> * Inserts the first node before the second node in this nodes childNodes collection.
  466. * @param {Node} node The node to insert
  467. * @param {Node} refNode The node to insert before (if null the node is appended)
  468. * @return {Node} The inserted node
  469. */
  470. insertBefore : function(node, refNode){
  471. if(!refNode){ // like standard Dom, refNode can be null for append
  472. return this.appendChild(node);
  473. }
  474. // nothing to do
  475. if(node == refNode){
  476. return false;
  477. }
  478. if(this.fireEvent(&quot;beforeinsert&quot;, this.ownerTree, this, node, refNode) === false){
  479. return false;
  480. }
  481. var index = this.childNodes.indexOf(refNode);
  482. var oldParent = node.parentNode;
  483. var refIndex = index;
  484. // when moving internally, indexes will change after remove
  485. if(oldParent == this &amp;&amp; this.childNodes.indexOf(node) &lt; index){
  486. refIndex--;
  487. }
  488. // it's a move, make sure we move it cleanly
  489. if(oldParent){
  490. if(node.fireEvent(&quot;beforemove&quot;, node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
  491. return false;
  492. }
  493. oldParent.removeChild(node);
  494. }
  495. if(refIndex === 0){
  496. this.setFirstChild(node);
  497. }
  498. this.childNodes.splice(refIndex, 0, node);
  499. node.parentNode = this;
  500. var ps = this.childNodes[refIndex-1];
  501. if(ps){
  502. node.previousSibling = ps;
  503. ps.nextSibling = node;
  504. }else{
  505. node.previousSibling = null;
  506. }
  507. node.nextSibling = refNode;
  508. refNode.previousSibling = node;
  509. node.setOwnerTree(this.getOwnerTree());
  510. this.fireEvent(&quot;insert&quot;, this.ownerTree, this, node, refNode);
  511. if(oldParent){
  512. node.fireEvent(&quot;move&quot;, this.ownerTree, node, oldParent, this, refIndex, refNode);
  513. }
  514. return node;
  515. },
  516. <span id='Ext-data-Node-method-remove'> /**
  517. </span> * Removes this node from its parent
  518. * @param {Boolean} destroy &lt;tt&gt;true&lt;/tt&gt; to destroy the node upon removal. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  519. * @return {Node} this
  520. */
  521. remove : function(destroy){
  522. if (this.parentNode) {
  523. this.parentNode.removeChild(this, destroy);
  524. }
  525. return this;
  526. },
  527. <span id='Ext-data-Node-method-removeAll'> /**
  528. </span> * Removes all child nodes from this node.
  529. * @param {Boolean} destroy &lt;tt&gt;true&lt;/tt&gt; to destroy the node upon removal. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  530. * @return {Node} this
  531. */
  532. removeAll : function(destroy){
  533. var cn = this.childNodes,
  534. n;
  535. while((n = cn[0])){
  536. this.removeChild(n, destroy);
  537. }
  538. return this;
  539. },
  540. <span id='Ext-data-Node-method-item'> /**
  541. </span> * Returns the child node at the specified index.
  542. * @param {Number} index
  543. * @return {Node}
  544. */
  545. item : function(index){
  546. return this.childNodes[index];
  547. },
  548. <span id='Ext-data-Node-method-replaceChild'> /**
  549. </span> * Replaces one child node in this node with another.
  550. * @param {Node} newChild The replacement node
  551. * @param {Node} oldChild The node to replace
  552. * @return {Node} The replaced node
  553. */
  554. replaceChild : function(newChild, oldChild){
  555. var s = oldChild ? oldChild.nextSibling : null;
  556. this.removeChild(oldChild);
  557. this.insertBefore(newChild, s);
  558. return oldChild;
  559. },
  560. <span id='Ext-data-Node-method-indexOf'> /**
  561. </span> * Returns the index of a child node
  562. * @param {Node} node
  563. * @return {Number} The index of the node or -1 if it was not found
  564. */
  565. indexOf : function(child){
  566. return this.childNodes.indexOf(child);
  567. },
  568. <span id='Ext-data-Node-method-getOwnerTree'> /**
  569. </span> * Returns the tree this node is in.
  570. * @return {Tree}
  571. */
  572. getOwnerTree : function(){
  573. // if it doesn't have one, look for one
  574. if(!this.ownerTree){
  575. var p = this;
  576. while(p){
  577. if(p.ownerTree){
  578. this.ownerTree = p.ownerTree;
  579. break;
  580. }
  581. p = p.parentNode;
  582. }
  583. }
  584. return this.ownerTree;
  585. },
  586. <span id='Ext-data-Node-method-getDepth'> /**
  587. </span> * Returns depth of this node (the root node has a depth of 0)
  588. * @return {Number}
  589. */
  590. getDepth : function(){
  591. var depth = 0;
  592. var p = this;
  593. while(p.parentNode){
  594. ++depth;
  595. p = p.parentNode;
  596. }
  597. return depth;
  598. },
  599. <span id='Ext-data-Node-method-setOwnerTree'> // private
  600. </span> setOwnerTree : function(tree, destroy){
  601. // if it is a move, we need to update everyone
  602. if(tree != this.ownerTree){
  603. if(this.ownerTree){
  604. this.ownerTree.unregisterNode(this);
  605. }
  606. this.ownerTree = tree;
  607. // If we're destroying, we don't need to recurse since it will be called on each child node
  608. if(destroy !== true){
  609. Ext.each(this.childNodes, function(n){
  610. n.setOwnerTree(tree);
  611. });
  612. }
  613. if(tree){
  614. tree.registerNode(this);
  615. }
  616. }
  617. },
  618. <span id='Ext-data-Node-method-setId'> /**
  619. </span> * Changes the id of this node.
  620. * @param {String} id The new id for the node.
  621. */
  622. setId: function(id){
  623. if(id !== this.id){
  624. var t = this.ownerTree;
  625. if(t){
  626. t.unregisterNode(this);
  627. }
  628. this.id = this.attributes.id = id;
  629. if(t){
  630. t.registerNode(this);
  631. }
  632. this.onIdChange(id);
  633. }
  634. },
  635. <span id='Ext-data-Node-method-onIdChange'> // private
  636. </span> onIdChange: Ext.emptyFn,
  637. <span id='Ext-data-Node-method-getPath'> /**
  638. </span> * Returns the path for this node. The path can be used to expand or select this node programmatically.
  639. * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
  640. * @return {String} The path
  641. */
  642. getPath : function(attr){
  643. attr = attr || &quot;id&quot;;
  644. var p = this.parentNode;
  645. var b = [this.attributes[attr]];
  646. while(p){
  647. b.unshift(p.attributes[attr]);
  648. p = p.parentNode;
  649. }
  650. var sep = this.getOwnerTree().pathSeparator;
  651. return sep + b.join(sep);
  652. },
  653. <span id='Ext-data-Node-method-bubble'> /**
  654. </span> * Bubbles up the tree from this node, calling the specified function with each node. The arguments to the function
  655. * will be the args provided or the current node. If the function returns false at any point,
  656. * the bubble is stopped.
  657. * @param {Function} fn The function to call
  658. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the current Node.
  659. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  660. */
  661. bubble : function(fn, scope, args){
  662. var p = this;
  663. while(p){
  664. if(fn.apply(scope || p, args || [p]) === false){
  665. break;
  666. }
  667. p = p.parentNode;
  668. }
  669. },
  670. <span id='Ext-data-Node-method-cascade'> /**
  671. </span> * Cascades down the tree from this node, calling the specified function with each node. The arguments to the function
  672. * will be the args provided or the current node. If the function returns false at any point,
  673. * the cascade is stopped on that branch.
  674. * @param {Function} fn The function to call
  675. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the current Node.
  676. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  677. */
  678. cascade : function(fn, scope, args){
  679. if(fn.apply(scope || this, args || [this]) !== false){
  680. var cs = this.childNodes;
  681. for(var i = 0, len = cs.length; i &lt; len; i++) {
  682. cs[i].cascade(fn, scope, args);
  683. }
  684. }
  685. },
  686. <span id='Ext-data-Node-method-eachChild'> /**
  687. </span> * Interates the child nodes of this node, calling the specified function with each node. The arguments to the function
  688. * will be the args provided or the current node. If the function returns false at any point,
  689. * the iteration stops.
  690. * @param {Function} fn The function to call
  691. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the current Node in the iteration.
  692. * @param {Array} args (optional) The args to call the function with (default to passing the current Node)
  693. */
  694. eachChild : function(fn, scope, args){
  695. var cs = this.childNodes;
  696. for(var i = 0, len = cs.length; i &lt; len; i++) {
  697. if(fn.apply(scope || cs[i], args || [cs[i]]) === false){
  698. break;
  699. }
  700. }
  701. },
  702. <span id='Ext-data-Node-method-findChild'> /**
  703. </span> * Finds the first child that has the attribute with the specified value.
  704. * @param {String} attribute The attribute name
  705. * @param {Mixed} value The value to search for
  706. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  707. * @return {Node} The found child or null if none was found
  708. */
  709. findChild : function(attribute, value, deep){
  710. return this.findChildBy(function(){
  711. return this.attributes[attribute] == value;
  712. }, null, deep);
  713. },
  714. <span id='Ext-data-Node-method-findChildBy'> /**
  715. </span> * Finds the first child by a custom function. The child matches if the function passed returns &lt;code&gt;true&lt;/code&gt;.
  716. * @param {Function} fn A function which must return &lt;code&gt;true&lt;/code&gt; if the passed Node is the required Node.
  717. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the Node being tested.
  718. * @param {Boolean} deep (Optional) True to search through nodes deeper than the immediate children
  719. * @return {Node} The found child or null if none was found
  720. */
  721. findChildBy : function(fn, scope, deep){
  722. var cs = this.childNodes,
  723. len = cs.length,
  724. i = 0,
  725. n,
  726. res;
  727. for(; i &lt; len; i++){
  728. n = cs[i];
  729. if(fn.call(scope || n, n) === true){
  730. return n;
  731. }else if (deep){
  732. res = n.findChildBy(fn, scope, deep);
  733. if(res != null){
  734. return res;
  735. }
  736. }
  737. }
  738. return null;
  739. },
  740. <span id='Ext-data-Node-method-sort'> /**
  741. </span> * Sorts this nodes children using the supplied sort function.
  742. * @param {Function} fn A function which, when passed two Nodes, returns -1, 0 or 1 depending upon required sort order.
  743. * @param {Object} scope (optional)The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the browser window.
  744. */
  745. sort : function(fn, scope){
  746. var cs = this.childNodes;
  747. var len = cs.length;
  748. if(len &gt; 0){
  749. var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
  750. cs.sort(sortFn);
  751. for(var i = 0; i &lt; len; i++){
  752. var n = cs[i];
  753. n.previousSibling = cs[i-1];
  754. n.nextSibling = cs[i+1];
  755. if(i === 0){
  756. this.setFirstChild(n);
  757. }
  758. if(i == len-1){
  759. this.setLastChild(n);
  760. }
  761. }
  762. }
  763. },
  764. <span id='Ext-data-Node-method-contains'> /**
  765. </span> * Returns true if this node is an ancestor (at any point) of the passed node.
  766. * @param {Node} node
  767. * @return {Boolean}
  768. */
  769. contains : function(node){
  770. return node.isAncestor(this);
  771. },
  772. <span id='Ext-data-Node-method-isAncestor'> /**
  773. </span> * Returns true if the passed node is an ancestor (at any point) of this node.
  774. * @param {Node} node
  775. * @return {Boolean}
  776. */
  777. isAncestor : function(node){
  778. var p = this.parentNode;
  779. while(p){
  780. if(p == node){
  781. return true;
  782. }
  783. p = p.parentNode;
  784. }
  785. return false;
  786. },
  787. <span id='Ext-data-Node-method-toString'> toString : function(){
  788. </span> return &quot;[Node&quot;+(this.id?&quot; &quot;+this.id:&quot;&quot;)+&quot;]&quot;;
  789. }
  790. });</pre>
  791. </body>
  792. </html>