tree.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /**
  2. * @description {Class} wdTree
  3. * This is the main class of wdTree.法法师法
  4. */
  5. (function ($) {
  6. $.fn.swapClass = function (c1, c2) {
  7. return this.removeClass(c1).addClass(c2);
  8. };
  9. $.fn.switchClass = function (c1, c2) {
  10. if (this.hasClass(c1)) {
  11. return this.swapClass(c1, c2);
  12. }
  13. else {
  14. return this.swapClass(c2, c1);
  15. }
  16. };
  17. $.fn.treeview = function (settings) {
  18. var dfop =
  19. {
  20. method: "GET",
  21. datatype: "json",
  22. /**
  23. * @description {Config} url
  24. * {String} Url for child nodes retrieving.
  25. */
  26. url: false,
  27. param: null,
  28. /**
  29. * @description {Config} cbiconpath
  30. * {String} Checkbox image path.
  31. */
  32. cbiconpath: "/content/plugins/wdtree/images/icons/",
  33. icons: ["checkbox_0.png", "checkbox_1.png", "checkbox_2.png"],
  34. /**
  35. * @description {Config} showcheck
  36. * {Boolean} Whether to show check box or not.
  37. */
  38. showcheck: false,
  39. /**
  40. * @description {Event} oncheckboxclick:function(tree, item, status)
  41. * Fired when check box is clicked on.
  42. * @param {Object} tree This tree object.
  43. * @param {Object} item Node item clicked on.
  44. * @param {Number} status 1 for checked, 0 for unchecked.
  45. */
  46. oncheckboxclick: false,
  47. /**
  48. * @description {Event} onnodeclick:function(tree, item)
  49. * Fired when a node is clicked on.
  50. * @param {Object} tree This tree object.
  51. * @param {Object} item Ndde item clicked on.
  52. */
  53. onnodeclick: false,
  54. /**
  55. * @description {Config} cascadecheck
  56. * {Boolean} Whether node being seleted leads to parent/sub node being selected.
  57. */
  58. cascadecheck: true,
  59. /**
  60. * @description {Config} data
  61. * {Object} Tree theme. Three themes provided. 'bbit-tree-lines' ,'bbit-tree-no-lines' and 'bbit-tree-arrows'.
  62. * @sample
  63. * data:[{
  64. * id:"node1", //node id
  65. * text:"node 1", //node text for display.
  66. * value:"1", //node value
  67. * showcheck:false, //whether to show checkbox
  68. * checkstate:0, //Checkbox checking state. 0 for unchecked, 1 for partial checked, 2 for checked.
  69. * hasChildren:true, //If hasChildren and complete set to true, and ChildNodes is empty, tree will request server to get sub node.
  70. * isexpand:false, //Expand or collapse.
  71. * complete:false, //See hasChildren.
  72. * ChildNodes:[] // child nodes
  73. * }]
  74. * */
  75. data: null,
  76. /**
  77. * @description {Config} clicktoggle
  78. * {String} Whether to toggle node when node clicked.
  79. */
  80. clicktoggle: true,
  81. /**
  82. * @description {Config} theme
  83. * {String} Tree theme. Three themes provided. 'bbit-tree-lines' ,'bbit-tree-no-lines' and 'bbit-tree-arrows'.
  84. */
  85. theme: "bbit-tree-arrows", //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
  86. /*
  87. *显示工具栏
  88. */
  89. isTool: false,
  90. nodeTools: []
  91. };
  92. $.extend(dfop, settings);
  93. var treenodes = dfop.data;
  94. var me = $(this);
  95. var id = me.attr("id");
  96. if (id == null || id == "") {
  97. id = "bbtree" + new Date().getTime();
  98. me.attr("id", id);
  99. }
  100. me.height(dfop.height);
  101. if (dfop.slimscroll == true) {
  102. //me.slimScroll({ height: dfop.height });
  103. me.css({ "overflow": "auto", "overflow-y": "hidden" });
  104. } else {
  105. me.css({ "overflow": "auto" });
  106. }
  107. var html = [];
  108. buildtree(dfop.data, html);
  109. me.html('');
  110. me.addClass("bbit-tree").append(html.join(""));
  111. InitEvent(me);
  112. html = null;
  113. //pre load the icons
  114. if (dfop.showcheck) {
  115. for (var i = 0; i < 3; i++) {
  116. var im = new Image();
  117. im.src = dfop.cbiconpath + dfop.icons[i];
  118. }
  119. }
  120. //region
  121. function buildtree(data, ht) {
  122. ht.push("<div class='bbit-tree-bwrap'>"); // Wrap ;
  123. ht.push("<div class='bbit-tree-body " + id + "'>"); // body ;
  124. ht.push("<ul class='bbit-tree-root ", dfop.theme, "'>"); //root
  125. if (data && data.length > 0) {
  126. var l = data.length;
  127. for (var i = 0; i < l; i++) {
  128. buildnode(data[i], ht, 0, i, i == l - 1);
  129. }
  130. }
  131. else {
  132. asnyloadc(null, false, function (data) {
  133. if (data && data.length > 0) {
  134. treenodes = data;
  135. dfop.data = data;
  136. if (dfop.description) {
  137. data.unshift({
  138. "id": "",
  139. "text": dfop.description,
  140. "value": "",
  141. "img": "-1",
  142. "parentnodes": "0",
  143. "showcheck": false,
  144. "isexpand": true,
  145. "complete": true,
  146. "hasChildren": false,
  147. "ChildNodes": []
  148. });
  149. }
  150. var l = data.length;
  151. for (var i = 0; i < l; i++) {
  152. buildnode(data[i], ht, 0, i, i == l - 1);
  153. }
  154. }
  155. });
  156. }
  157. ht.push("</ul>"); // root and;
  158. ht.push("</div>"); // body end;
  159. ht.push("</div>"); // Wrap end;
  160. }
  161. //endregion
  162. function buildnode(nd, ht, deep, path, isend) {
  163. var nid = nd.id.replace(/[^\w]/gi, "_");
  164. ht.push("<li class='bbit-tree-node'>");
  165. var title = nd.title;
  166. if (title) {
  167. title = nd.title;
  168. } else {
  169. title = nd.text;
  170. }
  171. ht.push("<div id='", id, "_", nid, "' tpath='", path, "' unselectable='on' title='", title, "'");
  172. var cs = [];
  173. cs.push("bbit-tree-node-el");
  174. if (nd.hasChildren) {
  175. cs.push(nd.isexpand ? "bbit-tree-node-expanded" : "bbit-tree-node-collapsed");
  176. }
  177. else {
  178. cs.push("bbit-tree-node-leaf");
  179. }
  180. if (nd.classes) { cs.push(nd.classes); }
  181. ht.push(" class='", cs.join(" "), "'>");
  182. //span indent
  183. ht.push("<span class='bbit-tree-node-indent'>");
  184. if (deep == 1) {
  185. ht.push("<img class='bbit-tree-icon' src='" + dfop.cbiconpath + "s.gif'/>");
  186. }
  187. else if (deep > 1) {
  188. ht.push("<img class='bbit-tree-icon' src='" + dfop.cbiconpath + "s.gif'/>");
  189. for (var j = 1; j < deep; j++) {
  190. ht.push("<img class='bbit-tree-elbow-line' src='" + dfop.cbiconpath + "s.gif'/>");
  191. }
  192. }
  193. ht.push("</span>");
  194. //img
  195. cs.length = 0;
  196. if (nd.hasChildren) {
  197. if (nd.isexpand) {
  198. cs.push(isend ? "bbit-tree-elbow-end-minus" : "bbit-tree-elbow-minus");
  199. }
  200. else {
  201. cs.push(isend ? "bbit-tree-elbow-end-plus" : "bbit-tree-elbow-plus");
  202. }
  203. }
  204. else {
  205. cs.push(isend ? "bbit-tree-elbow-end" : "bbit-tree-elbow");
  206. }
  207. ht.push("<img class='bbit-tree-ec-icon ", cs.join(" "), "' src='" + dfop.cbiconpath + "s.gif'/>");
  208. //checkbox
  209. if (dfop.showcheck && nd.showcheck) {
  210. if (nd.checkstate == null || nd.checkstate == undefined) {
  211. nd.checkstate = 0;
  212. }
  213. ht.push("<img id='", id, "_", nid, "_cb' class='bbit-tree-node-cb' src='", dfop.cbiconpath, dfop.icons[nd.checkstate], "'/>");
  214. }
  215. if (nd.hasChildren) {
  216. if (nd.img == -1) {
  217. ht.push("");
  218. } else
  219. if (!!nd.img) {
  220. ht.push("<i class=\"" + nd.img + "\"></i>&nbsp;");
  221. } else {
  222. ht.push("<i class=\"fa fa-folder-open\" style='width:15px'>&nbsp;</i>");
  223. }
  224. } else {
  225. if (nd.img == -1) {
  226. ht.push("");
  227. } else
  228. if (!!nd.img) {
  229. ht.push("<i class=\"" + nd.img + "\"></i>&nbsp;");
  230. } else {
  231. ht.push("<i class=\"fa fa-file-o\"></i>&nbsp;");
  232. }
  233. }
  234. //a
  235. ht.push("<a hideFocus class='bbit-tree-node-anchor' tabIndex=1 href='javascript:void(0);'>");
  236. ht.push("<span data-value='" + nd.id + "' class='bbit-tree-node-text' unselectable='on'>", nd.text, "</span>");
  237. ht.push("</a>");
  238. //tool 显示工具栏
  239. if (dfop.isTool) {
  240. ht.push("<div class='bbit-tree-node-tool'>");
  241. for (var ii in dfop.nodeTools) {
  242. var toolItem = dfop.nodeTools[ii];
  243. ht.push("<span class='" + toolItem.img + "' title='" + toolItem.text + "'></span>");
  244. }
  245. ht.push("</div>");
  246. }
  247. ht.push("</div>");
  248. //Child
  249. if (nd.hasChildren) {
  250. if (nd.isexpand) {
  251. ht.push("<ul class='bbit-tree-node-ct' style='z-index: 0; position: static; visibility: visible; top: auto; left: auto;'>");
  252. if (nd.ChildNodes) {
  253. var l = nd.ChildNodes.length;
  254. for (var k = 0; k < l; k++) {
  255. nd.ChildNodes[k].parent = nd;
  256. buildnode(nd.ChildNodes[k], ht, deep + 1, path + "." + k, k == l - 1);
  257. }
  258. }
  259. ht.push("</ul>");
  260. }
  261. else {
  262. ht.push("<ul style='display:none;'>");
  263. if (nd.ChildNodes) {
  264. var l = nd.ChildNodes.length;
  265. for (var k = 0; k < l; k++) {
  266. nd.ChildNodes[k].parent = nd;
  267. buildnode(nd.ChildNodes[k], ht, deep + 1, path + "." + k, k == l - 1);
  268. }
  269. }
  270. ht.push("</ul>");
  271. }
  272. }
  273. ht.push("</li>");
  274. nd.render = true;
  275. }
  276. function getItem(path) {
  277. var ap = path.split(".");
  278. var t = treenodes;
  279. for (var i = 0; i < ap.length; i++) {
  280. if (i == 0) {
  281. t = t[ap[i]];
  282. }
  283. else {
  284. t = t.ChildNodes[ap[i]];
  285. }
  286. }
  287. return t;
  288. }
  289. function check(item, state, type) {
  290. var pstate = item.checkstate;
  291. if (type == 1) {
  292. item.checkstate = state;
  293. }
  294. else {// go to childnodes
  295. var cs = item.ChildNodes;
  296. var l = cs.length;
  297. var ch = true;
  298. for (var i = 0; i < l; i++) {
  299. if ((state == 1 && cs[i].checkstate != 1) || state == 0 && cs[i].checkstate != 0) {
  300. ch = false;
  301. break;
  302. }
  303. }
  304. if (ch) {
  305. item.checkstate = state;
  306. }
  307. else {
  308. item.checkstate = 2;
  309. }
  310. }
  311. //change show
  312. if (item.render && pstate != item.checkstate) {
  313. var nid = item.id.replace(/[^\w]/gi, "_");
  314. var et = $("#" + id + "_" + nid + "_cb");
  315. if (et.length == 1) {
  316. et.attr("src", dfop.cbiconpath + dfop.icons[item.checkstate]);
  317. }
  318. }
  319. }
  320. //iterate all children nodes
  321. function cascade(fn, item, args) {
  322. if (fn(item, args, 1) != false) {
  323. if (item.ChildNodes != null && item.ChildNodes.length > 0) {
  324. var cs = item.ChildNodes;
  325. for (var i = 0, len = cs.length; i < len; i++) {
  326. cascade(fn, cs[i], args);
  327. }
  328. }
  329. }
  330. }
  331. //bubble to parent
  332. function bubble(fn, item, args) {
  333. var p = item.parent;
  334. while (p) {
  335. if (fn(p, args, 0) === false) {
  336. break;
  337. }
  338. p = p.parent;
  339. }
  340. }
  341. function nodeclick(e) {
  342. var path = $(this).attr("tpath");
  343. var et = e.target || e.srcElement;
  344. var item = getItem(path);
  345. if (et.tagName == "IMG") {
  346. //+ if collapsed, expend it
  347. if ($(et).hasClass("bbit-tree-elbow-plus") || $(et).hasClass("bbit-tree-elbow-end-plus")) {
  348. if ($(this).find('i').hasClass('fa-folder')) {
  349. $(this).find('i').swapClass('fa-folder', 'fa-folder-open');
  350. }
  351. var ul = $(this).next(); //"bbit-tree-node-ct"
  352. if (ul.hasClass("bbit-tree-node-ct")) {
  353. ul.slideDown(200);
  354. }
  355. else {
  356. var deep = path.split(".").length;
  357. if (item.complete) {
  358. item.ChildNodes != null && asnybuild(item.ChildNodes, deep, path, ul, item);
  359. }
  360. else {
  361. $(this).addClass("bbit-tree-node-loading");
  362. asnyloadc(item, true, function (data) {
  363. item.complete = true;
  364. item.ChildNodes = data;
  365. asnybuild(data, deep, path, ul, item);
  366. });
  367. }
  368. }
  369. if ($(et).hasClass("bbit-tree-elbow-plus")) {
  370. $(et).swapClass("bbit-tree-elbow-plus", "bbit-tree-elbow-minus");
  371. }
  372. else {
  373. $(et).swapClass("bbit-tree-elbow-end-plus", "bbit-tree-elbow-end-minus");
  374. }
  375. $(this).swapClass("bbit-tree-node-collapsed", "bbit-tree-node-expanded");
  376. }
  377. //if expended, collapse it
  378. else if ($(et).hasClass("bbit-tree-elbow-minus") || $(et).hasClass("bbit-tree-elbow-end-minus")) {
  379. if ($(this).find('i').hasClass('fa-folder-open')) {
  380. $(this).find('i').swapClass('fa-folder-open', 'fa-folder');
  381. }
  382. $(this).next().slideUp(200);
  383. if ($(et).hasClass("bbit-tree-elbow-minus")) {
  384. $(et).swapClass("bbit-tree-elbow-minus", "bbit-tree-elbow-plus");
  385. }
  386. else {
  387. $(et).swapClass("bbit-tree-elbow-end-minus", "bbit-tree-elbow-end-plus");
  388. }
  389. $(this).swapClass("bbit-tree-node-expanded", "bbit-tree-node-collapsed");
  390. }
  391. else if ($(et).hasClass("bbit-tree-node-cb")) // click on checkbox
  392. {
  393. var s = item.checkstate != 1 ? 1 : 0;
  394. var r = true;
  395. if (dfop.oncheckboxclick) {
  396. r = dfop.oncheckboxclick.call(et, item, s);
  397. }
  398. if (r != false) {
  399. if (dfop.cascadecheck) {
  400. cascade(check, item, s);
  401. bubble(check, item, s);
  402. }
  403. else {
  404. check(item, s, 1);
  405. }
  406. }
  407. }
  408. }
  409. else {
  410. if (dfop.citem) {
  411. var nid = dfop.citem.id.replace(/[^\w]/gi, "_");
  412. $("." + id).removeClass("bbit-tree-selected");
  413. }
  414. dfop.citem = item;
  415. $("." + id).find('div').removeClass("bbit-tree-selected");
  416. $(this).addClass("bbit-tree-selected");
  417. if (dfop.onnodeclick) {
  418. if (!item.expand) {
  419. item.expand = function () { expandnode.call(item); };
  420. }
  421. dfop.onnodeclick.call(this, item);
  422. }
  423. }
  424. }
  425. function expandnode() {
  426. var item = this;
  427. var nid = item.id.replace(/[^\w]/gi, "_");
  428. var img = $("#" + id + "_" + nid + " img.bbit-tree-ec-icon");
  429. if (img.length > 0) {
  430. img.click();
  431. }
  432. }
  433. function asnybuild(nodes, deep, path, ul, pnode) {
  434. var l = nodes.length;
  435. if (l > 0) {
  436. var ht = [];
  437. for (var i = 0; i < l; i++) {
  438. nodes[i].parent = pnode;
  439. buildnode(nodes[i], ht, deep, path + "." + i, i == l - 1);
  440. }
  441. ul.html(ht.join(""));
  442. ht = null;
  443. InitEvent(ul);
  444. }
  445. ul.addClass("bbit-tree-node-ct").css({ "z-index": 0, position: "static", visibility: "visible", top: "auto", left: "auto", display: "" });
  446. ul.prev().removeClass("bbit-tree-node-loading");
  447. }
  448. function asnyloadc(pnode, isAsync, callback) {
  449. if (dfop.url) {
  450. if (pnode && pnode != null)
  451. var param = builparam(pnode);
  452. if (dfop.param != null) {
  453. var param = dfop.param
  454. }
  455. $.ajax({
  456. type: dfop.method,
  457. url: dfop.url,
  458. data: param,
  459. async: isAsync,
  460. dataType: dfop.datatype,
  461. success: callback,
  462. error: function (e) { dialogMsg("服务端未响应。", -1); }
  463. });
  464. }
  465. }
  466. function builparam(node) {
  467. var p = [{ name: "id", value: encodeURIComponent(node.id) }
  468. , { name: "text", value: encodeURIComponent(node.text) }
  469. , { name: "value", value: encodeURIComponent(node.value) }
  470. , { name: "checkstate", value: node.checkstate }];
  471. return p;
  472. }
  473. function bindevent() {
  474. $(this).hover(function () {
  475. $(this).addClass("bbit-tree-node-over");
  476. }, function () {
  477. $(this).removeClass("bbit-tree-node-over");
  478. }).click(nodeclick)
  479. .find("img.bbit-tree-ec-icon").each(function (e) {
  480. if (!$(this).hasClass("bbit-tree-elbow")) {
  481. $(this).hover(function () {
  482. $(this).parent().addClass("bbit-tree-ec-over");
  483. }, function () {
  484. $(this).parent().removeClass("bbit-tree-ec-over");
  485. });
  486. }
  487. });
  488. }
  489. function InitEvent(parent) {
  490. var nodes = $("li.bbit-tree-node>div", parent);
  491. nodes.each(bindevent);
  492. }
  493. function reflash(itemId) {
  494. var nid = itemId.replace(/[^\w-]/gi, "_");
  495. var node = $("#" + id + "_" + nid);
  496. if (node.length > 0) {
  497. node.addClass("bbit-tree-node-loading");
  498. var isend = node.hasClass("bbit-tree-elbow-end") || node.hasClass("bbit-tree-elbow-end-plus") || node.hasClass("bbit-tree-elbow-end-minus");
  499. var path = node.attr("tpath");
  500. var deep = path.split(".").length;
  501. var item = getItem(path);
  502. if (item) {
  503. asnyloadc(item, true, function (data) {
  504. item.complete = true;
  505. item.ChildNodes = data;
  506. item.isexpand = true;
  507. if (data && data.length > 0) {
  508. item.hasChildren = true;
  509. }
  510. else {
  511. item.hasChildren = false;
  512. }
  513. var ht = [];
  514. buildnode(item, ht, deep - 1, path, isend);
  515. ht.shift();
  516. ht.pop();
  517. var li = node.parent();
  518. li.html(ht.join(""));
  519. ht = null;
  520. InitEvent(li);
  521. bindevent.call(li.find(">div"));
  522. });
  523. }
  524. }
  525. else {
  526. //node not created yet
  527. }
  528. }
  529. function getck(items, c, fn) {
  530. for (var i = 0, l = items.length; i < l; i++) {
  531. (items[i].showcheck == true && items[i].checkstate == 1) && c.push(fn(items[i]));
  532. if (items[i].ChildNodes != null && items[i].ChildNodes.length > 0) {
  533. getck(items[i].ChildNodes, c, fn);
  534. }
  535. }
  536. }
  537. function getCkAndHalfCk(items, c, fn) {
  538. for (var i = 0, l = items.length; i < l; i++) {
  539. (items[i].showcheck == true && (items[i].checkstate == 1 || items[i].checkstate == 2)) && c.push(fn(items[i]));
  540. if (items[i].ChildNodes != null && items[i].ChildNodes.length > 0) {
  541. getCkAndHalfCk(items[i].ChildNodes, c, fn);
  542. }
  543. }
  544. }
  545. me[0].t = {
  546. getSelectedNodes: function (gethalfchecknode) {
  547. var s = [];
  548. if (gethalfchecknode) {
  549. getCkAndHalfCk(treenodes, s, function (item) { return item; });
  550. }
  551. else {
  552. getck(treenodes, s, function (item) { return item; });
  553. }
  554. return s;
  555. },
  556. getSelectedValues: function () {
  557. var s = [];
  558. getck(treenodes, s, function (item) { return item.value; });
  559. return s;
  560. },
  561. getCurrentItem: function () {
  562. return dfop.citem;
  563. },
  564. reflash: function (itemOrItemId) {
  565. var id;
  566. if (typeof (itemOrItemId) == "string") {
  567. id = itemOrItemId;
  568. }
  569. else {
  570. id = itemOrItemId.id;
  571. }
  572. reflash(id);
  573. }
  574. };
  575. return me;
  576. };
  577. $.fn.getCheckedNodes = function () {
  578. if (this[0].t) {
  579. return this[0].t.getSelectedValues();
  580. }
  581. return null;
  582. };
  583. $.fn.getCheckedAllNodes = function () {
  584. var $id = $(this);
  585. var _length = $id.attr('id').trim().length + 1;
  586. var value = []
  587. $id.find('.bbit-tree-node-cb').each(function () {
  588. var _src = $(this).attr('src');
  589. _src = _src.substr(_src.lastIndexOf("/") + 1);
  590. if (_src == 'checkbox_1.png' || _src == 'checkbox_2.png') {
  591. var _value = $(this).attr('id').substring(parseInt(_length)).replace(/_/g, "-");
  592. _value = _value.substring(0, _value.length - 3);
  593. value.push(_value)
  594. }
  595. });
  596. return value;
  597. };
  598. $.fn.setCheckedNodes = function (data) {
  599. var $id = $(this);
  600. var id = $id.attr('id').trim();
  601. $.each(data, function (i, item) {
  602. var object = $id.find(('#' + id + '_' + item.replace(/-/g, "_") + '_cb'));
  603. if (object.length != 0) {
  604. //var _src = object.attr('src');
  605. //object.attr('src', _src.replace('checkbox_0.png', 'checkbox_1.png'));
  606. object.trigger("click");
  607. }
  608. });
  609. }
  610. $.fn.setCheckedNodeOne = function (data) {
  611. var $id = $(this);
  612. var id = $id.attr('id').trim();
  613. var object = $id.find(('#' + id + '_' + data.replace(/-/g, "_") + '_cb'));
  614. if (object.length != 0) {
  615. //var _src = object.attr('src');
  616. //object.attr('src', _src.replace('checkbox_0.png', 'checkbox_1.png'));
  617. object.trigger("click");
  618. }
  619. }
  620. $.fn.setNoCheckedNodes = function (item) {
  621. var $id = $(this);
  622. var id = $id.attr('id').trim();
  623. var object = $id.find(('#' + id + '_' + item.replace(/-/g, "_") + '_cb'));
  624. var _src = object.attr('src');
  625. object.attr('src', _src.replace('checkbox_1.png', 'checkbox_0.png'));
  626. }
  627. $.fn.getTSNs = function (gethalfchecknode) {
  628. if (this[0].t) {
  629. return this[0].t.getSelectedNodes(gethalfchecknode);
  630. }
  631. return null;
  632. };
  633. $.fn.getCurrentNode = function () {
  634. if (this[0].t) {
  635. return this[0].t.getCurrentItem();
  636. }
  637. return null;
  638. };
  639. $.fn.reflash = function (ItemOrItemId) {
  640. if (this[0].t) {
  641. return this[0].t.reflash(ItemOrItemId);
  642. }
  643. };
  644. $.fn.setTreeHeight = function (height) {
  645. var me = $(this);
  646. me.height(height);
  647. //me.parents('.slimScrollDiv').height(height);
  648. }
  649. $.fn.setNodeChecked = function (value) {
  650. var $id = $(this);
  651. var id = $id.attr('id').trim();
  652. $id.find('.bbit-tree-selected').removeClass('bbit-tree-selected');
  653. var object = $id.find(('#' + id + '_' + value.replace(/-/g, "_")));
  654. object.addClass('bbit-tree-selected');
  655. }
  656. $.fn.refreshNode = function (value, text) {
  657. var $id = $(this);
  658. var id = $id.attr('id').trim();
  659. var object = $id.find(('#' + id + '_' + value.replace(/-/g, "_"))).find('span[data-value = "' + value + '" ]');
  660. object.html(text);
  661. }
  662. })(jQuery);