tree.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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/scripts/plugins/tree/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: true,
  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. {
  241. ht.push("<div class='bbit-tree-node-tool'>");
  242. for (var ii in dfop.nodeTools) {
  243. var toolItem = dfop.nodeTools[ii];
  244. if (toolItem.node == undefined || toolItem.node == nd.type)
  245. {
  246. ht.push("<span class='" + toolItem.img + "' data-value='" + nd.id + "' title='" + toolItem.text + "'></span>");
  247. }
  248. }
  249. ht.push("</div>");
  250. }
  251. ht.push("</div>");
  252. //Child
  253. if (nd.hasChildren) {
  254. if (nd.isexpand) {
  255. ht.push("<ul class='bbit-tree-node-ct' style='z-index: 0; position: static; visibility: visible; top: auto; left: auto;'>");
  256. if (nd.ChildNodes) {
  257. var l = nd.ChildNodes.length;
  258. for (var k = 0; k < l; k++) {
  259. nd.ChildNodes[k].parent = nd;
  260. buildnode(nd.ChildNodes[k], ht, deep + 1, path + "." + k, k == l - 1);
  261. }
  262. }
  263. ht.push("</ul>");
  264. }
  265. else {
  266. ht.push("<ul style='display:none;'>");
  267. if (nd.ChildNodes) {
  268. var l = nd.ChildNodes.length;
  269. for (var k = 0; k < l; k++) {
  270. nd.ChildNodes[k].parent = nd;
  271. buildnode(nd.ChildNodes[k], ht, deep + 1, path + "." + k, k == l - 1);
  272. }
  273. }
  274. ht.push("</ul>");
  275. }
  276. }
  277. ht.push("</li>");
  278. nd.render = true;
  279. }
  280. function getItem(path) {
  281. var ap = path.split(".");
  282. var t = treenodes;
  283. for (var i = 0; i < ap.length; i++) {
  284. if (i == 0) {
  285. t = t[ap[i]];
  286. }
  287. else {
  288. t = t.ChildNodes[ap[i]];
  289. }
  290. }
  291. return t;
  292. }
  293. function check(item, state, type) {
  294. var pstate = item.checkstate;
  295. if (type == 1) {
  296. item.checkstate = state;
  297. }
  298. else {// go to childnodes
  299. var cs = item.ChildNodes;
  300. var l = cs.length;
  301. var ch = true;
  302. for (var i = 0; i < l; i++) {
  303. if ((state == 1 && cs[i].checkstate != 1) || state == 0 && cs[i].checkstate != 0) {
  304. ch = false;
  305. break;
  306. }
  307. }
  308. if (ch) {
  309. item.checkstate = state;
  310. }
  311. else {
  312. item.checkstate = 2;
  313. }
  314. }
  315. //change show
  316. if (item.render && pstate != item.checkstate) {
  317. var nid = item.id.replace(/[^\w]/gi, "_");
  318. var et = $("#" + id + "_" + nid + "_cb");
  319. if (et.length == 1) {
  320. et.attr("src", dfop.cbiconpath + dfop.icons[item.checkstate]);
  321. }
  322. }
  323. }
  324. //iterate all children nodes
  325. function cascade(fn, item, args) {
  326. if (fn(item, args, 1) != false) {
  327. if (item.ChildNodes != null && item.ChildNodes.length > 0) {
  328. var cs = item.ChildNodes;
  329. for (var i = 0, len = cs.length; i < len; i++) {
  330. cascade(fn, cs[i], args);
  331. }
  332. }
  333. }
  334. }
  335. //bubble to parent
  336. function bubble(fn, item, args) {
  337. var p = item.parent;
  338. while (p) {
  339. if (fn(p, args, 0) === false) {
  340. break;
  341. }
  342. p = p.parent;
  343. }
  344. }
  345. function nodeclick(e) {
  346. var path = $(this).attr("tpath");
  347. var et = e.target || e.srcElement;
  348. var item = getItem(path);
  349. if (et.tagName == "IMG") {
  350. //+ if collapsed, expend it
  351. if ($(et).hasClass("bbit-tree-elbow-plus") || $(et).hasClass("bbit-tree-elbow-end-plus")) {
  352. if ($(this).find('i').hasClass('fa-folder')) {
  353. $(this).find('i').swapClass('fa-folder', 'fa-folder-open');
  354. }
  355. var ul = $(this).next(); //"bbit-tree-node-ct"
  356. if (ul.hasClass("bbit-tree-node-ct")) {
  357. ul.slideDown(200);
  358. }
  359. else {
  360. var deep = path.split(".").length;
  361. if (item.complete) {
  362. item.ChildNodes != null && asnybuild(item.ChildNodes, deep, path, ul, item);
  363. }
  364. else {
  365. $(this).addClass("bbit-tree-node-loading");
  366. asnyloadc(item, true, function (data) {
  367. item.complete = true;
  368. item.ChildNodes = data;
  369. asnybuild(data, deep, path, ul, item);
  370. });
  371. }
  372. }
  373. if ($(et).hasClass("bbit-tree-elbow-plus")) {
  374. $(et).swapClass("bbit-tree-elbow-plus", "bbit-tree-elbow-minus");
  375. }
  376. else {
  377. $(et).swapClass("bbit-tree-elbow-end-plus", "bbit-tree-elbow-end-minus");
  378. }
  379. $(this).swapClass("bbit-tree-node-collapsed", "bbit-tree-node-expanded");
  380. }
  381. //if expended, collapse it
  382. else if ($(et).hasClass("bbit-tree-elbow-minus") || $(et).hasClass("bbit-tree-elbow-end-minus")) {
  383. if ($(this).find('i').hasClass('fa-folder-open')) {
  384. $(this).find('i').swapClass('fa-folder-open', 'fa-folder');
  385. }
  386. $(this).next().slideUp(200);
  387. if ($(et).hasClass("bbit-tree-elbow-minus")) {
  388. $(et).swapClass("bbit-tree-elbow-minus", "bbit-tree-elbow-plus");
  389. }
  390. else {
  391. $(et).swapClass("bbit-tree-elbow-end-minus", "bbit-tree-elbow-end-plus");
  392. }
  393. $(this).swapClass("bbit-tree-node-expanded", "bbit-tree-node-collapsed");
  394. }
  395. else if ($(et).hasClass("bbit-tree-node-cb")) // click on checkbox
  396. {
  397. var s = item.checkstate != 1 ? 1 : 0;
  398. var r = true;
  399. if (dfop.oncheckboxclick) {
  400. r = dfop.oncheckboxclick.call(et, item, s);
  401. }
  402. if (r != false) {
  403. if (dfop.cascadecheck) {
  404. cascade(check, item, s);
  405. bubble(check, item, s);
  406. }
  407. else {
  408. check(item, s, 1);
  409. }
  410. }
  411. }
  412. }
  413. else {
  414. if (dfop.citem) {
  415. var nid = dfop.citem.id.replace(/[^\w]/gi, "_");
  416. $("." + id).removeClass("bbit-tree-selected");
  417. }
  418. dfop.citem = item;
  419. $("." + id).find('div').removeClass("bbit-tree-selected");
  420. $(this).addClass("bbit-tree-selected");
  421. if (dfop.onnodeclick) {
  422. if (!item.expand) {
  423. item.expand = function () { expandnode.call(item); };
  424. }
  425. dfop.onnodeclick.call(this, item);
  426. }
  427. }
  428. }
  429. function expandnode() {
  430. var item = this;
  431. var nid = item.id.replace(/[^\w]/gi, "_");
  432. var img = $("#" + id + "_" + nid + " img.bbit-tree-ec-icon");
  433. if (img.length > 0) {
  434. img.click();
  435. }
  436. }
  437. function asnybuild(nodes, deep, path, ul, pnode) {
  438. var l = nodes.length;
  439. if (l > 0) {
  440. var ht = [];
  441. for (var i = 0; i < l; i++) {
  442. nodes[i].parent = pnode;
  443. buildnode(nodes[i], ht, deep, path + "." + i, i == l - 1);
  444. }
  445. ul.html(ht.join(""));
  446. ht = null;
  447. InitEvent(ul);
  448. }
  449. ul.addClass("bbit-tree-node-ct").css({ "z-index": 0, position: "static", visibility: "visible", top: "auto", left: "auto", display: "" });
  450. ul.prev().removeClass("bbit-tree-node-loading");
  451. }
  452. function asnyloadc(pnode, isAsync, callback) {
  453. if (dfop.url) {
  454. if (pnode && pnode != null)
  455. var param = builparam(pnode);
  456. if (dfop.param != null) {
  457. var param = dfop.param
  458. }
  459. $.ajax({
  460. type: dfop.method,
  461. url: dfop.url,
  462. data: param,
  463. async: isAsync,
  464. dataType: dfop.datatype,
  465. success: callback,
  466. error: function (e) { dialogMsg("륩蛟똥灌捲壇。", -1); }
  467. });
  468. }
  469. }
  470. function builparam(node) {
  471. var p = [{ name: "id", value: encodeURIComponent(node.id) }
  472. , { name: "text", value: encodeURIComponent(node.text) }
  473. , { name: "value", value: encodeURIComponent(node.value) }
  474. , { name: "checkstate", value: node.checkstate }];
  475. return p;
  476. }
  477. function bindevent() {
  478. $(this).hover(function () {
  479. $(this).addClass("bbit-tree-node-over");
  480. }, function () {
  481. $(this).removeClass("bbit-tree-node-over");
  482. }).click(nodeclick)
  483. .find("img.bbit-tree-ec-icon").each(function (e) {
  484. if (!$(this).hasClass("bbit-tree-elbow")) {
  485. $(this).hover(function () {
  486. $(this).parent().addClass("bbit-tree-ec-over");
  487. }, function () {
  488. $(this).parent().removeClass("bbit-tree-ec-over");
  489. });
  490. }
  491. });
  492. //tool 鞫刻묏야으
  493. if (dfop.isTool) {
  494. for (var ii in dfop.nodeTools) {
  495. var toolItem = dfop.nodeTools[ii];
  496. if (toolItem.callback != undefined) {
  497. $($(".bbit-tree-node-tool span", $(this))[ii]).click( function(){
  498. var id = $(this).attr("data-value");
  499. toolItem.callback(id);
  500. });
  501. }
  502. }
  503. }
  504. }
  505. function InitEvent(parent) {
  506. var nodes = $("li.bbit-tree-node>div", parent);
  507. nodes.each(bindevent);
  508. }
  509. function reflash(itemId) {
  510. var nid = itemId.replace(/[^\w-]/gi, "_");
  511. var node = $("#" + id + "_" + nid);
  512. if (node.length > 0) {
  513. node.addClass("bbit-tree-node-loading");
  514. var isend = node.hasClass("bbit-tree-elbow-end") || node.hasClass("bbit-tree-elbow-end-plus") || node.hasClass("bbit-tree-elbow-end-minus");
  515. var path = node.attr("tpath");
  516. var deep = path.split(".").length;
  517. var item = getItem(path);
  518. if (item) {
  519. asnyloadc(item, true, function (data) {
  520. item.complete = true;
  521. item.ChildNodes = data;
  522. item.isexpand = true;
  523. if (data && data.length > 0) {
  524. item.hasChildren = true;
  525. }
  526. else {
  527. item.hasChildren = false;
  528. }
  529. var ht = [];
  530. buildnode(item, ht, deep - 1, path, isend);
  531. ht.shift();
  532. ht.pop();
  533. var li = node.parent();
  534. li.html(ht.join(""));
  535. ht = null;
  536. InitEvent(li);
  537. bindevent.call(li.find(">div"));
  538. });
  539. }
  540. }
  541. else {
  542. //node not created yet
  543. }
  544. }
  545. function getck(items, c, fn) {
  546. for (var i = 0, l = items.length; i < l; i++) {
  547. (items[i].showcheck == true && items[i].checkstate == 1) && c.push(fn(items[i]));
  548. if (items[i].ChildNodes != null && items[i].ChildNodes.length > 0) {
  549. getck(items[i].ChildNodes, c, fn);
  550. }
  551. }
  552. }
  553. function getCkAndHalfCk(items, c, fn) {
  554. for (var i = 0, l = items.length; i < l; i++) {
  555. (items[i].showcheck == true && (items[i].checkstate == 1 || items[i].checkstate == 2)) && c.push(fn(items[i]));
  556. if (items[i].ChildNodes != null && items[i].ChildNodes.length > 0) {
  557. getCkAndHalfCk(items[i].ChildNodes, c, fn);
  558. }
  559. }
  560. }
  561. me[0].t = {
  562. getSelectedNodes: function (gethalfchecknode) {
  563. var s = [];
  564. if (gethalfchecknode) {
  565. getCkAndHalfCk(treenodes, s, function (item) { return item; });
  566. }
  567. else {
  568. getck(treenodes, s, function (item) { return item; });
  569. }
  570. return s;
  571. },
  572. getSelectedValues: function () {
  573. var s = [];
  574. getck(treenodes, s, function (item) { return item.value; });
  575. return s;
  576. },
  577. getCurrentItem: function () {
  578. return dfop.citem;
  579. },
  580. reflash: function (itemOrItemId) {
  581. var id;
  582. if (typeof (itemOrItemId) == "string") {
  583. id = itemOrItemId;
  584. }
  585. else {
  586. id = itemOrItemId.id;
  587. }
  588. reflash(id);
  589. }
  590. };
  591. return me;
  592. };
  593. $.fn.getCheckedNodes = function () {
  594. if (this[0].t) {
  595. return this[0].t.getSelectedValues();
  596. }
  597. return null;
  598. };
  599. $.fn.getCheckedAllNodes = function () {
  600. var $id = $(this);
  601. var _length = $id.attr('id').trim().length + 1;
  602. var value = []
  603. $id.find('.bbit-tree-node-cb').each(function () {
  604. var _src = $(this).attr('src');
  605. _src = _src.substr(_src.lastIndexOf("/") + 1);
  606. if (_src == 'checkbox_1.png' || _src == 'checkbox_2.png') {
  607. var _value = $(this).attr('id').substring(parseInt(_length)).replace(/_/g, "-");
  608. _value = _value.substring(0, _value.length - 3);
  609. value.push(_value)
  610. }
  611. });
  612. return value;
  613. };
  614. $.fn.setCheckedNodes = function (data) {
  615. var $id = $(this);
  616. var id = $id.attr('id').trim();
  617. $.each(data, function (i, item) {
  618. var object = $id.find(('#' + id + '_' + item.replace(/-/g, "_") + '_cb'));
  619. if (object.length != 0) {
  620. //var _src = object.attr('src');
  621. //object.attr('src', _src.replace('checkbox_0.png', 'checkbox_1.png'));
  622. object.trigger("click");
  623. }
  624. });
  625. }
  626. $.fn.setCheckedNodeOne = function (data) {
  627. var $id = $(this);
  628. var id = $id.attr('id').trim();
  629. var object = $id.find(('#' + id + '_' + data.replace(/-/g, "_") + '_cb'));
  630. if (object.length != 0) {
  631. //var _src = object.attr('src');
  632. //object.attr('src', _src.replace('checkbox_0.png', 'checkbox_1.png'));
  633. object.trigger("click");
  634. }
  635. }
  636. $.fn.setNoCheckedNodes = function (item) {
  637. var $id = $(this);
  638. var id = $id.attr('id').trim();
  639. var object = $id.find(('#' + id + '_' + item.replace(/-/g, "_") + '_cb'));
  640. var _src = object.attr('src');
  641. object.attr('src', _src.replace('checkbox_1.png', 'checkbox_0.png'));
  642. }
  643. $.fn.getTSNs = function (gethalfchecknode) {
  644. if (this[0].t) {
  645. return this[0].t.getSelectedNodes(gethalfchecknode);
  646. }
  647. return null;
  648. };
  649. $.fn.getCurrentNode = function () {
  650. if (this[0].t) {
  651. return this[0].t.getCurrentItem();
  652. }
  653. return null;
  654. };
  655. $.fn.reflash = function (ItemOrItemId) {
  656. if (this[0].t) {
  657. return this[0].t.reflash(ItemOrItemId);
  658. }
  659. };
  660. $.fn.setTreeHeight = function (height) {
  661. var me = $(this);
  662. me.height(height);
  663. //me.parents('.slimScrollDiv').height(height);
  664. }
  665. $.fn.setNodeChecked = function (value) {
  666. var $id = $(this);
  667. var id = $id.attr('id').trim();
  668. $id.find('.bbit-tree-selected').removeClass('bbit-tree-selected');
  669. var object = $id.find(('#' + id + '_' + value.replace(/-/g, "_")));
  670. object.addClass('bbit-tree-selected');
  671. }
  672. $.fn.refreshNode = function (value, text)
  673. {
  674. var $id = $(this);
  675. var id = $id.attr('id').trim();
  676. var object = $id.find(('#' + id + '_' + value.replace(/-/g, "_"))).find('span[data-value = "' + value + '" ]');
  677. object.html(text);
  678. }
  679. $.fn.refreshNodeIcon = function (value, icon,flag) {
  680. var $id = $(this);
  681. var id = $id.attr('id').trim();
  682. var object = $id.find(('#' + id + '_' + value.replace(/-/g, "_"))).find('i');
  683. if (flag != undefined)
  684. {
  685. var _classs = object.attr("class");
  686. var _aa = $id.find(flag);
  687. _aa.removeAttr("class");
  688. _aa.addClass(_classs);
  689. }
  690. object.removeAttr("class");
  691. object.addClass(icon);
  692. }
  693. })(jQuery);