idTree.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /**
  2. * Created by Mai on 2017/3/17.
  3. */
  4. var idTree = {
  5. createNew: function (setting) {
  6. var _setting = {
  7. id: 'id',
  8. pid: 'pid',
  9. nid: 'nid',
  10. rootId: -1,
  11. autoUpdate: false
  12. };
  13. var _eventType = {
  14. editedData: 'editedData'
  15. };
  16. var tools = {
  17. findNode: function (nodes, check) {
  18. for (var i = 0; i < nodes.length; i++) {
  19. if (check(nodes[i])) {
  20. return nodes[i];
  21. }
  22. }
  23. return null;
  24. },
  25. reSortNodes: function (nodes, recursive) {
  26. var temp = [], first;
  27. var findFirstNode = function (nodes) {
  28. return tools.findNode(nodes, function (node) {
  29. return node.preSibling === null;
  30. });
  31. };
  32. var moveNode = function (node, orgArray, newArray, newIndex) {
  33. var next;
  34. orgArray.splice(orgArray.indexOf(node), 1);
  35. newArray.splice(newIndex, 0, node);
  36. if (node.getNextSiblingID() !== -1) {
  37. next = node.nextSibling;
  38. if (next && (orgArray.indexOf(next) >= 0)) {
  39. moveNode(next, orgArray, newArray, newIndex + 1);
  40. }
  41. }
  42. };
  43. if (nodes.length === 0) {
  44. return nodes;
  45. }
  46. if (recursive) {
  47. nodes.forEach(function (node) {
  48. node.children = tools.reSortNodes(node.children, recursive);
  49. });
  50. }
  51. while (nodes.length > 0) {
  52. first = findFirstNode(nodes);
  53. first = first ? first : nodes[0];
  54. moveNode(first, nodes, temp, temp.length);
  55. }
  56. nodes = null;
  57. tools.reSiblingNodes(temp);
  58. return temp;
  59. },
  60. reSiblingNodes: function (nodes) {
  61. var i;
  62. for (i = 0; i < nodes.length; i++) {
  63. nodes[i].preSibling = (i === 0) ? null : nodes[i - 1];
  64. nodes[i].nextSibling = (i === nodes.length - 1) ? null : nodes[i + 1];
  65. }
  66. },
  67. <<<<<<< HEAD
  68. // ��nodes�У���iIndex����������ʼȫ���Ƴ�
  69. =======
  70. // 在nodes中,从iIndex(包括)开始全部移除
  71. >>>>>>> bc0f5d2858a5b09273a8d6ed5620a4deb05293b2
  72. removeNodes: function (tree, parent, iIndex, count) {
  73. var children = parent ? parent.children : tree.roots;
  74. var pre = (iIndex < 0 || iIndex >= children.length) ? null : children[iIndex].preSibling;
  75. var next = (pre && iIndex + count - 1 < children.length) ? children[iIndex + count] : null;
  76. if (pre) {
  77. pre.setNextSibling(next);
  78. //pre.nextSibling = next;
  79. }
  80. if (next) {
  81. next.preSibling = pre;
  82. }
  83. if (arguments.length === 4) {
  84. children.splice(iIndex, count);
  85. } else {
  86. children.splice(iIndex, children.length - iIndex);
  87. }
  88. },
  89. <<<<<<< HEAD
  90. // ��nodes������addNodes, λ�ô�index��ʼ
  91. =======
  92. // 在parent.children/tree.roots中增加nodes, 位置从index开始
  93. >>>>>>> bc0f5d2858a5b09273a8d6ed5620a4deb05293b2
  94. addNodes: function (tree, parent, nodes, iIndex) {
  95. var children = parent ? parent.children : tree.roots;
  96. var pre, next, i;
  97. if (nodes.length === 0) { return; }
  98. if (arguments.length === 4) {
  99. pre = (iIndex <= 0 || iIndex > children.length) ? null : children[iIndex - 1];
  100. next = pre ? pre.nextSibling : null;
  101. } else if (arguments.length === 3) {
  102. pre = children.length === 0 ? null : children[children.length - 1];
  103. next = null;
  104. }
  105. if (pre) {
  106. pre.setNextSibling(nodes[0]);
  107. }
  108. nodes[0].preSibling = pre;
  109. if (next) {
  110. next.preSibling = nodes[nodes.length - 1];
  111. }
  112. nodes[nodes.length - 1].setNextSibling(next);
  113. for (i = 0; i < nodes.length; i++) {
  114. if (arguments.length === 4) {
  115. children.splice(iIndex + i, 0, nodes[i]);
  116. } else if (arguments.length === 3) {
  117. children.push(nodes[i]);
  118. }
  119. nodes[i].setParent(parent ? parent : null);
  120. }
  121. },
  122. sortTreeItems: function (tree) {
  123. var addItems = function (items) {
  124. var i;
  125. for (i = 0; i < items.length; i++) {
  126. tree.items.push(items[i]);
  127. addItems(items[i].children);
  128. }
  129. };
  130. tree.items.splice(0, tree.items.length);
  131. addItems(tree.roots);
  132. },
  133. addUpdateDataForParent: function (datas, nodes, pid) {
  134. nodes.forEach(function (node) {
  135. datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), pid, node.getNextSiblingID())});
  136. });
  137. },
  138. addUpdateDataForNextSibling: function (datas, node, nid) {
  139. if (node) {
  140. datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), node.getParentID(), nid)});
  141. }
  142. }
  143. };
  144. var Node = function (tree, data) {
  145. <<<<<<< HEAD
  146. // ���µ����ԣ�����Ԫ�������ֱ���޸�
  147. =======
  148. // 以下的属性,本单元外均不可直接修改
  149. >>>>>>> bc0f5d2858a5b09273a8d6ed5620a4deb05293b2
  150. this.tree = tree;
  151. this.data = data;
  152. this.children = [];
  153. this.parent = null;
  154. this.nextSibling = null;
  155. this.preSibling = null;
  156. this.expanded = true;
  157. this.visible = true;
  158. this.visible = true;
  159. };
  160. Node.prototype.getID = function () {
  161. return this.data[this.tree.setting.id];
  162. };
  163. Node.prototype.getParentID = function () {
  164. return this.parent ? this.parent.getID() : -1;
  165. };
  166. Node.prototype.getNextSiblingID = function () {
  167. return this.nextSibling ? this.nextSibling.getID() : -1;
  168. };
  169. Node.prototype.setParent = function (parent) {
  170. this.parent = parent;
  171. if (this.tree.setting.autoUpdate) {
  172. this.data[this.tree.setting.pid] = this.getParentID();
  173. }
  174. };
  175. Node.prototype.setNextSibling = function (nextSibling) {
  176. this.nextSibling = nextSibling;
  177. if (this.tree.setting.autoUpdate) {
  178. this.data[this.tree.setting.nid] = this.getNextSiblingID();
  179. }
  180. }
  181. Node.prototype.firstChild = function () {
  182. return this.children.length === 0 ? null : this.children[0];
  183. };
  184. Node.prototype.lastChild = function () {
  185. return this.children.length === 0 ? null : this.children[this.children.length - 1];
  186. };
  187. Node.prototype.depth = function () {
  188. return this.parent ? this.parent.depth() + 1 : 0;
  189. };
  190. Node.prototype.isFirst = function () {
  191. if (this.parent) {
  192. return this.parent.children.indexOf(this) === 0 ? true : false;
  193. } else {
  194. return this.tree.roots.indexOf(this) === 0 ? true : false;
  195. }
  196. };
  197. Node.prototype.isLast = function () {
  198. if (this.parent) {
  199. return this.parent.children.indexOf(this) === this.parent.children.length - 1 ? true : false;
  200. } else {
  201. return this.tree.roots.indexOf(this) === this.tree.roots.length - 1 ? true : false;
  202. }
  203. };
  204. Node.prototype.siblingIndex = function () {
  205. return this.parent ? this.parent.children.indexOf(this) : this.tree.roots.indexOf(this);
  206. };
  207. Node.prototype.posterityCount = function () {
  208. var iCount = 0;
  209. if (this.children.length !== 0) {
  210. iCount += this.children.length;
  211. this.children.forEach(function (child) {
  212. iCount += child.posterityCount();
  213. });
  214. }
  215. return iCount;
  216. /*return (node.children.length === 0) ? 0 : node.children.reduce(function (x, y) {
  217. return x.posterityCount() + y.posterityCount();
  218. }) + node.children.count;*/
  219. };
  220. Node.prototype.setExpanded = function (expanded) {
  221. var setNodesVisible = function (nodes, visible) {
  222. nodes.forEach(function (node) {
  223. node.visible = visible;
  224. setNodesVisible(node.children, visible && node.expanded);
  225. })
  226. };
  227. this.expanded = expanded;
  228. setNodesVisible(this.children, expanded);
  229. };
  230. /*Node.prototype.vis = function () {
  231. return this.parent ? this.parent.vis() && this.parent.expanded() : true;
  232. };*/
  233. Node.prototype.serialNo = function () {
  234. return this.tree.items.indexOf(this);
  235. };
  236. Node.prototype.addChild = function (node) {
  237. var preSibling = this.children.length === 0 ? null : this.children[this.children.length - 1];
  238. node.parent = this;
  239. if (preSibling) {
  240. preSibling.nextSibling = node;
  241. }
  242. node.preSibling = preSibling;
  243. this.children.push(node);
  244. };
  245. Node.prototype.removeChild = function (node) {
  246. var preSibling = node.preSibling, nextSibling = node.nextSibling;
  247. if (preSibling) {
  248. preSibling.nextSibling = nextSibling;
  249. }
  250. if (nextSibling) {
  251. nextSibling.preSibling = preSibling;
  252. }
  253. this.children.splice(this.children.re)
  254. };
  255. Node.prototype.canUpLevel = function () {
  256. return this.parent ? true : false;
  257. };
  258. Node.prototype.getUpLevelData = function () {
  259. var data = [];
  260. if (this.canUpLevel()) {
  261. if (!this.isLast()) {
  262. tools.addUpdateDataForParent(data, this.parent.children.slice(this.siblingIndex() + 1), this.getID());
  263. }
  264. if (this.preSibling) {
  265. tools.addUpdateDataForNextSibling(data, this.preSibling, this.tree.setting.rootId);
  266. }
  267. tools.addUpdateDataForNextSibling(data, this.parent, this.getID());
  268. data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.parent.getParentID(), this.parent.getNextSiblingID())});
  269. }
  270. return data;
  271. };
  272. Node.prototype.upLevel = function () {
  273. var result = {success: false, updateDatas: []};
  274. var iIndex = this.parent.children.indexOf(this), orgParent = this.parent, newNextSibling = this.parent.nextSibling;
  275. if (this.canUpLevel) {
  276. // NextSiblings become child
  277. tools.addNodes(this.tree, this, this.parent.children.slice(iIndex + 1));
  278. // Orginal Parent remove node and nextSiblings
  279. tools.removeNodes(this.tree, this.parent, iIndex);
  280. // New Parent add node
  281. tools.addNodes(this.tree, this.parent.parent, [this], this.parent.siblingIndex() + 1);
  282. if (!this.expanded) {
  283. this.setExpanded(true);
  284. }
  285. result.success = true;
  286. }
  287. return result;
  288. };
  289. Node.prototype.canDownLevel = function () {
  290. return !this.isFirst();
  291. };
  292. Node.prototype.getDownLevelData = function () {
  293. var data = [];
  294. if (this.canDownLevel()) {
  295. if (this.preSibling.children.length !== 0) {
  296. tools.addUpdateDataForNextSibling(data, this.preSibling.lastChild(), this.getID());
  297. }
  298. tools.addUpdateDataForNextSibling(data, this.preSibling, this.getNextSiblingID());
  299. data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.preSibling.getID(), this.tree.setting.rootId)});
  300. }
  301. return data;
  302. };
  303. Node.prototype.downLevel = function () {
  304. var success = false, iIndex = this.parent ? this.parent.children.indexOf(this) : this.tree.roots.indexOf(this);
  305. var newParent = this.preSibling;
  306. if (this.canDownLevel()) {
  307. tools.removeNodes(this.tree, this.parent, this.siblingIndex(), 1);
  308. tools.addNodes(this.tree, this.preSibling, [this]);
  309. if (!newParent.expanded) {
  310. newParent.setExpanded(true);
  311. }
  312. success = true;
  313. }
  314. return success;
  315. };
  316. Node.prototype.canUpMove = function () {
  317. return !this.isFirst();
  318. };
  319. Node.prototype.getUpMoveData = function () {
  320. var data = [];
  321. if (this.canUpMove()) {
  322. if (this.preSibling.preSibling) {
  323. tools.addUpdateDataForNextSibling(data, this.preSibling.preSibling, this.getID());
  324. }
  325. tools.addUpdateDataForNextSibling(data, this.preSibling, this.getNextSiblingID());
  326. tools.addUpdateDataForNextSibling(data, this, this.preSibling.getID());
  327. }
  328. return data;
  329. };
  330. Node.prototype.upMove = function () {
  331. var success = false;
  332. var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgPre = this.preSibling;
  333. if (this.canUpMove()) {
  334. if (orgPre.preSibling) {
  335. orgPre.preSibling.setNextSibling(this);
  336. }
  337. orgPre.seNextSibling(this.nextSibling);
  338. this.preSibling = orgPre.preSibling;
  339. orgPre.preSibling = this;
  340. this.setNextSibling(orgPre);
  341. belongArray.splice(iIndex, 1);
  342. belongArray.splice(iIndex - 1, 0, this);
  343. tools.sortTreeItems(this.tree);
  344. success = true;
  345. }
  346. return success;
  347. };
  348. Node.prototype.canDownMove = function () {
  349. return !this.isLast();
  350. };
  351. Node.prototype.getDownMoveData = function () {
  352. var data = [];
  353. if (this.canDownMove()) {
  354. if (this.preSibling) {
  355. tools.addUpdateDataForNextSibling(data, this.preSibling, this.nextSibling.getID());
  356. }
  357. tools.addUpdateDataForNextSibling(data, this, this.nextSibling.getNextSiblingID());
  358. tools.addUpdateDataForNextSibling(data, this.nextSibling, this.getID());
  359. }
  360. return data;
  361. };
  362. Node.prototype.downMove = function () {
  363. var success = false;
  364. var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgNext = this.nextSibling;
  365. if (this.canDownMove()) {
  366. if (this.preSibling) {
  367. this.preSibling.setNextSibling(orgNext);
  368. }
  369. orgNext.preSibling = this.preSibling;
  370. this.setNextSibling(orgNext.nextSibling);
  371. orgNext.setNextSibling(this);
  372. this.preSibling = orgNext;
  373. belongArray.splice(iIndex, 1);
  374. belongArray.splice(iIndex + 1, 0, this);
  375. tools.sortTreeItems(this.tree);
  376. success = true;
  377. }
  378. return success;
  379. };
  380. var Tree = function (setting) {
  381. this.nodes = {};
  382. this.roots = [];
  383. this.items = [];
  384. this.setting = setting;
  385. this.prefix = 'id_';
  386. this.selected = null;
  387. this.event = {};
  388. this.eventType = _eventType;
  389. };
  390. Tree.prototype.getDataTemplate = function (id, pid, nid) {
  391. var data = {};
  392. data[this.setting.id] = id;
  393. data[this.setting.pid] = pid;
  394. data[this.setting.nid] = nid;
  395. return data;
  396. };
  397. Tree.prototype.maxNodeID = (function () {
  398. var maxID = 0;
  399. return function (ID) {
  400. if (arguments.length === 0) {
  401. return maxID;
  402. } else {
  403. maxID = Math.max(maxID, ID);
  404. }
  405. };
  406. })();
  407. Tree.prototype.rangeNodeID = (function () {
  408. var rangeID = -1;
  409. return function (ID) {
  410. if (arguments.length === 0) {
  411. return rangeID;
  412. } else {
  413. rangeID = Math.max(rangeID, ID);
  414. }
  415. }
  416. })();
  417. Tree.prototype.newNodeID = function () {
  418. if (this.rangeNodeID() === -1) {
  419. return this.maxNodeID() + 1;
  420. } else {
  421. if (this.maxNodeID() < this.rangeNodeID()) {
  422. return this.maxNodeID() + 1;
  423. } else {
  424. return -1;
  425. }
  426. }
  427. /*if (this.maxID >= this.rangeNodeID() || this.rangeNodeID === -1) {
  428. return -1;
  429. } else {
  430. return this.maxNodeID() + 1;
  431. }*/
  432. };
  433. Tree.prototype.loadDatas = function (datas) {
  434. var prefix = this.prefix, i, node, parent, next, that = this;
  435. // prepare index
  436. datas.forEach(function (data) {
  437. var node = new Node(that, data);
  438. that.nodes[prefix + data[that.setting.id]] = node;
  439. that.maxNodeID(data[that.setting.id]);
  440. });
  441. // set parent by pid, set nextSibling by nid
  442. datas.forEach(function (data) {
  443. node = that.nodes[prefix + data[that.setting.id]];
  444. if (data[that.setting.pid] === that.setting.rootId) {
  445. that.roots.push(node);
  446. } else {
  447. parent = that.nodes[prefix + data[that.setting.pid]];
  448. if (parent) {
  449. node.parent = parent;
  450. parent.children.push(node);
  451. }
  452. }
  453. if (data[that.setting.nid] !== that.setting.rootId) {
  454. next = that.nodes[prefix + data[that.setting.nid]];
  455. if (next) {
  456. node.nextSibling = next;
  457. next.preSibling = node;
  458. }
  459. }
  460. })
  461. // sort by nid
  462. this.roots = tools.reSortNodes(this.roots, true);
  463. tools.sortTreeItems(this);
  464. };
  465. Tree.prototype.firstNode = function () {
  466. return this.roots.length === 0 ? null : this.roots[0];
  467. };
  468. Tree.prototype.findNode = function (id) {
  469. return this.nodes[this.prefix + id];
  470. };
  471. Tree.prototype.count = function () {
  472. var iCount = 0;
  473. if (this.roots.length !== 0) {
  474. iCount += this.roots.length;
  475. this.roots.forEach(function (node) {
  476. iCount += node.posterityCount();
  477. });
  478. }
  479. return iCount;
  480. };
  481. Tree.prototype.insert = function (parentID, nextSiblingID) {
  482. var newID = this.newNodeID(), node = null, data = {};
  483. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  484. var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
  485. if (newID !== -1) {
  486. data = {};
  487. data[this.setting.id] = newID;
  488. data[this.setting.pid] = parent ? parent.getID() : this.setting.rootId;
  489. data[this.setting.nid] = nextSibling ? nextSibling.getID() : this.setting.rootId;
  490. node = new Node(this, data);
  491. if (nextSibling) {
  492. tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
  493. } else {
  494. tools.addNodes(this, parent, [node]);
  495. }
  496. this.nodes[this.prefix + newID] = node;
  497. tools.sortTreeItems(this);
  498. this.maxNodeID(newID);
  499. }
  500. return node;
  501. };
  502. Tree.prototype.getInsertData = function (parentID, nextSiblingID) {
  503. var data = [];
  504. var newID = this.newNodeID();
  505. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  506. var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
  507. if (newID !== -1) {
  508. data.push({type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId)});
  509. if (nextSibling && nextSibling.preSibling) {
  510. tools.addUpdateDataForNextSibling(data, nextSibling.preSibling, newID);
  511. } else if (parent && parent.children.length !== 0) {
  512. tools.addUpdateDataForNextSibling(data, parent.lastChild(), newID);
  513. } else if (!parent && this.roots.length !== 0) {
  514. tools.addUpdateDataForNextSibling(data, this.roots[this.roots.length - 1], newID);
  515. }
  516. }
  517. return data;
  518. };
  519. Tree.prototype.insertByData = function (data, parentID, nextSiblingID) {
  520. var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
  521. var nextSibling = nextSiblingID === -1 ? null : this.nodes[this.prefix + nextSiblingID];
  522. var node = this.nodes[this.prefix + data[this.setting.id]];
  523. if (node) {
  524. return node;
  525. } else {
  526. node = new Node(this, data);
  527. if (nextSibling) {
  528. tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
  529. } else {
  530. tools.addNodes(this, parent, [node]);
  531. }
  532. this.nodes[this.prefix + data[this.setting.id]] = node;
  533. tools.sortTreeItems(this);
  534. this.maxNodeID( data[this.setting.id]);
  535. return node;
  536. }
  537. };
  538. Tree.prototype.delete = function (node) {
  539. var success = false, that = this;
  540. var deleteIdIndex = function (nodes) {
  541. nodes.forEach(function (node) {
  542. delete that.nodes[that.prefix + node.getID()];
  543. deleteIdIndex(node.children);
  544. })
  545. }
  546. if (node) {
  547. deleteIdIndex([node]);
  548. //delete this.nodes[this.prefix + node.getID()];
  549. if (node.preSibling) {
  550. node.preSibling.setNextSibling(node.nextSibling);
  551. }
  552. if (node.nextSibling) {
  553. node.nextSibling.preSibling = node.preSibling;
  554. }
  555. if (node.parent) {
  556. node.parent.children.splice(node.siblingIndex(), 1);
  557. } else {
  558. this.roots.splice(node.siblingIndex(), 1);
  559. }
  560. tools.sortTreeItems(this);
  561. success = true;
  562. }
  563. return success;
  564. };
  565. Tree.prototype.getDeleteData = function (node) {
  566. var data = [];
  567. var addUpdateDataForDelete = function (datas, nodes) {
  568. nodes.forEach(function (node) {
  569. var delData = {};
  570. delData[node.tree.setting.id] = node.getID();
  571. datas.push({type: 'delete', data: delData});
  572. addUpdateDataForDelete(datas, node.children);
  573. })
  574. };
  575. if (node) {
  576. addUpdateDataForDelete(data, [node]);
  577. if (node.preSibling) {
  578. tools.addUpdateDataForNextSibling(data, node.preSibling, node.getNextSiblingID());
  579. }
  580. }
  581. return data;
  582. }
  583. /*Tree.prototype.editedData = function (field, id, newText) {
  584. var node = this.findNode(id), result = {allow: false, nodes: []};
  585. if (this.event[this.eventType.editedData]) {
  586. return this.event[this.eventType.editedData](field, node.data);
  587. } else {
  588. node.data[field] = newText;
  589. result.allow = true;
  590. return result;
  591. }
  592. };*/
  593. Tree.prototype.bind = function (eventName, eventFun) {
  594. this.event[eventName] = eventFun;
  595. };
  596. return new Tree(setting);
  597. }
  598. };