jquery.tree.js 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /**
  2. * EasyUI for jQuery 1.5.5.6
  3. *
  4. * Copyright (c) 2009-2018 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(_2){
  12. var _3=$(_2);
  13. _3.addClass("tree");
  14. return _3;
  15. };
  16. function _4(_5){
  17. var _6=$.data(_5,"tree").options;
  18. $(_5).unbind().bind("mouseover",function(e){
  19. var tt=$(e.target);
  20. var _7=tt.closest("div.tree-node");
  21. if(!_7.length){
  22. return;
  23. }
  24. _7.addClass("tree-node-hover");
  25. if(tt.hasClass("tree-hit")){
  26. if(tt.hasClass("tree-expanded")){
  27. tt.addClass("tree-expanded-hover");
  28. }else{
  29. tt.addClass("tree-collapsed-hover");
  30. }
  31. }
  32. e.stopPropagation();
  33. }).bind("mouseout",function(e){
  34. var tt=$(e.target);
  35. var _8=tt.closest("div.tree-node");
  36. if(!_8.length){
  37. return;
  38. }
  39. _8.removeClass("tree-node-hover");
  40. if(tt.hasClass("tree-hit")){
  41. if(tt.hasClass("tree-expanded")){
  42. tt.removeClass("tree-expanded-hover");
  43. }else{
  44. tt.removeClass("tree-collapsed-hover");
  45. }
  46. }
  47. e.stopPropagation();
  48. }).bind("click",function(e){
  49. var tt=$(e.target);
  50. var _9=tt.closest("div.tree-node");
  51. if(!_9.length){
  52. return;
  53. }
  54. if(tt.hasClass("tree-hit")){
  55. _85(_5,_9[0]);
  56. return false;
  57. }else{
  58. if(tt.hasClass("tree-checkbox")){
  59. _34(_5,_9[0]);
  60. return false;
  61. }else{
  62. _d9(_5,_9[0]);
  63. _6.onClick.call(_5,_c(_5,_9[0]));
  64. }
  65. }
  66. e.stopPropagation();
  67. }).bind("dblclick",function(e){
  68. var _a=$(e.target).closest("div.tree-node");
  69. if(!_a.length){
  70. return;
  71. }
  72. _d9(_5,_a[0]);
  73. _6.onDblClick.call(_5,_c(_5,_a[0]));
  74. e.stopPropagation();
  75. }).bind("contextmenu",function(e){
  76. var _b=$(e.target).closest("div.tree-node");
  77. if(!_b.length){
  78. return;
  79. }
  80. _6.onContextMenu.call(_5,e,_c(_5,_b[0]));
  81. e.stopPropagation();
  82. });
  83. };
  84. function _d(_e){
  85. var _f=$.data(_e,"tree").options;
  86. _f.dnd=false;
  87. var _10=$(_e).find("div.tree-node");
  88. _10.draggable("disable");
  89. _10.css("cursor","pointer");
  90. };
  91. function _11(_12){
  92. var _13=$.data(_12,"tree");
  93. var _14=_13.options;
  94. var _15=_13.tree;
  95. _13.disabledNodes=[];
  96. _14.dnd=true;
  97. _15.find("div.tree-node").draggable({disabled:false,revert:true,cursor:"pointer",proxy:function(_16){
  98. var p=$("<div class=\"tree-node-proxy\"></div>").appendTo("body");
  99. p.html("<span class=\"tree-dnd-icon tree-dnd-no\">&nbsp;</span>"+$(_16).find(".tree-title").html());
  100. p.hide();
  101. return p;
  102. },deltaX:15,deltaY:15,onBeforeDrag:function(e){
  103. if(_14.onBeforeDrag.call(_12,_c(_12,this))==false){
  104. return false;
  105. }
  106. if($(e.target).hasClass("tree-hit")||$(e.target).hasClass("tree-checkbox")){
  107. return false;
  108. }
  109. if(e.which!=1){
  110. return false;
  111. }
  112. var _17=$(this).find("span.tree-indent");
  113. if(_17.length){
  114. e.data.offsetWidth-=_17.length*_17.width();
  115. }
  116. },onStartDrag:function(e){
  117. $(this).next("ul").find("div.tree-node").each(function(){
  118. $(this).droppable("disable");
  119. _13.disabledNodes.push(this);
  120. });
  121. $(this).draggable("proxy").css({left:-10000,top:-10000});
  122. _14.onStartDrag.call(_12,_c(_12,this));
  123. var _18=_c(_12,this);
  124. if(_18.id==undefined){
  125. _18.id="easyui_tree_node_id_temp";
  126. _60(_12,_18);
  127. }
  128. _13.draggingNodeId=_18.id;
  129. },onDrag:function(e){
  130. var x1=e.pageX,y1=e.pageY,x2=e.data.startX,y2=e.data.startY;
  131. var d=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  132. if(d>3){
  133. $(this).draggable("proxy").show();
  134. }
  135. this.pageY=e.pageY;
  136. },onStopDrag:function(){
  137. for(var i=0;i<_13.disabledNodes.length;i++){
  138. $(_13.disabledNodes[i]).droppable("enable");
  139. }
  140. _13.disabledNodes=[];
  141. var _19=_d0(_12,_13.draggingNodeId);
  142. if(_19&&_19.id=="easyui_tree_node_id_temp"){
  143. _19.id="";
  144. _60(_12,_19);
  145. }
  146. _14.onStopDrag.call(_12,_19);
  147. }}).droppable({accept:"div.tree-node",onDragEnter:function(e,_1a){
  148. if(_14.onDragEnter.call(_12,this,_1b(_1a))==false){
  149. _1c(_1a,false);
  150. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  151. $(this).droppable("disable");
  152. _13.disabledNodes.push(this);
  153. }
  154. },onDragOver:function(e,_1d){
  155. if($(this).droppable("options").disabled){
  156. return;
  157. }
  158. var _1e=_1d.pageY;
  159. var top=$(this).offset().top;
  160. var _1f=top+$(this).outerHeight();
  161. _1c(_1d,true);
  162. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  163. if(_1e>top+(_1f-top)/2){
  164. if(_1f-_1e<5){
  165. $(this).addClass("tree-node-bottom");
  166. }else{
  167. $(this).addClass("tree-node-append");
  168. }
  169. }else{
  170. if(_1e-top<5){
  171. $(this).addClass("tree-node-top");
  172. }else{
  173. $(this).addClass("tree-node-append");
  174. }
  175. }
  176. if(_14.onDragOver.call(_12,this,_1b(_1d))==false){
  177. _1c(_1d,false);
  178. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  179. $(this).droppable("disable");
  180. _13.disabledNodes.push(this);
  181. }
  182. },onDragLeave:function(e,_20){
  183. _1c(_20,false);
  184. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  185. _14.onDragLeave.call(_12,this,_1b(_20));
  186. },onDrop:function(e,_21){
  187. var _22=this;
  188. var _23,_24;
  189. if($(this).hasClass("tree-node-append")){
  190. _23=_25;
  191. _24="append";
  192. }else{
  193. _23=_26;
  194. _24=$(this).hasClass("tree-node-top")?"top":"bottom";
  195. }
  196. if(_14.onBeforeDrop.call(_12,_22,_1b(_21),_24)==false){
  197. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  198. return;
  199. }
  200. _23(_21,_22,_24);
  201. $(this).removeClass("tree-node-append tree-node-top tree-node-bottom");
  202. }});
  203. function _1b(_27,pop){
  204. return $(_27).closest("ul.tree").tree(pop?"pop":"getData",_27);
  205. };
  206. function _1c(_28,_29){
  207. var _2a=$(_28).draggable("proxy").find("span.tree-dnd-icon");
  208. _2a.removeClass("tree-dnd-yes tree-dnd-no").addClass(_29?"tree-dnd-yes":"tree-dnd-no");
  209. };
  210. function _25(_2b,_2c){
  211. if(_c(_12,_2c).state=="closed"){
  212. _79(_12,_2c,function(){
  213. _2d();
  214. });
  215. }else{
  216. _2d();
  217. }
  218. function _2d(){
  219. var _2e=_1b(_2b,true);
  220. $(_12).tree("append",{parent:_2c,data:[_2e]});
  221. _14.onDrop.call(_12,_2c,_2e,"append");
  222. };
  223. };
  224. function _26(_2f,_30,_31){
  225. var _32={};
  226. if(_31=="top"){
  227. _32.before=_30;
  228. }else{
  229. _32.after=_30;
  230. }
  231. var _33=_1b(_2f,true);
  232. _32.data=_33;
  233. $(_12).tree("insert",_32);
  234. _14.onDrop.call(_12,_30,_33,_31);
  235. };
  236. };
  237. function _34(_35,_36,_37,_38){
  238. var _39=$.data(_35,"tree");
  239. var _3a=_39.options;
  240. if(!_3a.checkbox){
  241. return;
  242. }
  243. var _3b=_c(_35,_36);
  244. if(!_3b.checkState){
  245. return;
  246. }
  247. var ck=$(_36).find(".tree-checkbox");
  248. if(_37==undefined){
  249. if(ck.hasClass("tree-checkbox1")){
  250. _37=false;
  251. }else{
  252. if(ck.hasClass("tree-checkbox0")){
  253. _37=true;
  254. }else{
  255. if(_3b._checked==undefined){
  256. _3b._checked=$(_36).find(".tree-checkbox").hasClass("tree-checkbox1");
  257. }
  258. _37=!_3b._checked;
  259. }
  260. }
  261. }
  262. _3b._checked=_37;
  263. if(_37){
  264. if(ck.hasClass("tree-checkbox1")){
  265. return;
  266. }
  267. }else{
  268. if(ck.hasClass("tree-checkbox0")){
  269. return;
  270. }
  271. }
  272. if(!_38){
  273. if(_3a.onBeforeCheck.call(_35,_3b,_37)==false){
  274. return;
  275. }
  276. }
  277. if(_3a.cascadeCheck){
  278. _3c(_35,_3b,_37);
  279. _3d(_35,_3b);
  280. }else{
  281. _3e(_35,_3b,_37?"1":"0");
  282. }
  283. if(!_38){
  284. _3a.onCheck.call(_35,_3b,_37);
  285. }
  286. };
  287. function _3c(_3f,_40,_41){
  288. var _42=$.data(_3f,"tree").options;
  289. var _43=_41?1:0;
  290. _3e(_3f,_40,_43);
  291. if(_42.deepCheck){
  292. $.easyui.forEach(_40.children||[],true,function(n){
  293. _3e(_3f,n,_43);
  294. });
  295. }else{
  296. var _44=[];
  297. if(_40.children&&_40.children.length){
  298. _44.push(_40);
  299. }
  300. $.easyui.forEach(_40.children||[],true,function(n){
  301. if(!n.hidden){
  302. _3e(_3f,n,_43);
  303. if(n.children&&n.children.length){
  304. _44.push(n);
  305. }
  306. }
  307. });
  308. for(var i=_44.length-1;i>=0;i--){
  309. var _45=_44[i];
  310. _3e(_3f,_45,_46(_45));
  311. }
  312. }
  313. };
  314. function _3e(_47,_48,_49){
  315. var _4a=$.data(_47,"tree").options;
  316. if(!_48.checkState||_49==undefined){
  317. return;
  318. }
  319. if(_48.hidden&&!_4a.deepCheck){
  320. return;
  321. }
  322. var ck=$("#"+_48.domId).find(".tree-checkbox");
  323. _48.checkState=["unchecked","checked","indeterminate"][_49];
  324. _48.checked=(_48.checkState=="checked");
  325. ck.removeClass("tree-checkbox0 tree-checkbox1 tree-checkbox2");
  326. ck.addClass("tree-checkbox"+_49);
  327. };
  328. function _3d(_4b,_4c){
  329. var pd=_4d(_4b,$("#"+_4c.domId)[0]);
  330. if(pd){
  331. _3e(_4b,pd,_46(pd));
  332. _3d(_4b,pd);
  333. }
  334. };
  335. function _46(row){
  336. var c0=0;
  337. var c1=0;
  338. var len=0;
  339. $.easyui.forEach(row.children||[],false,function(r){
  340. if(r.checkState){
  341. len++;
  342. if(r.checkState=="checked"){
  343. c1++;
  344. }else{
  345. if(r.checkState=="unchecked"){
  346. c0++;
  347. }
  348. }
  349. }
  350. });
  351. if(len==0){
  352. return undefined;
  353. }
  354. var _4e=0;
  355. if(c0==len){
  356. _4e=0;
  357. }else{
  358. if(c1==len){
  359. _4e=1;
  360. }else{
  361. _4e=2;
  362. }
  363. }
  364. return _4e;
  365. };
  366. function _4f(_50,_51){
  367. var _52=$.data(_50,"tree").options;
  368. if(!_52.checkbox){
  369. return;
  370. }
  371. var _53=$(_51);
  372. var ck=_53.find(".tree-checkbox");
  373. var _54=_c(_50,_51);
  374. if(_52.view.hasCheckbox(_50,_54)){
  375. if(!ck.length){
  376. _54.checkState=_54.checkState||"unchecked";
  377. $("<span class=\"tree-checkbox\"></span>").insertBefore(_53.find(".tree-title"));
  378. }
  379. if(_54.checkState=="checked"){
  380. _34(_50,_51,true,true);
  381. }else{
  382. if(_54.checkState=="unchecked"){
  383. _34(_50,_51,false,true);
  384. }else{
  385. var _55=_46(_54);
  386. if(_55===0){
  387. _34(_50,_51,false,true);
  388. }else{
  389. if(_55===1){
  390. _34(_50,_51,true,true);
  391. }
  392. }
  393. }
  394. }
  395. }else{
  396. ck.remove();
  397. _54.checkState=undefined;
  398. _54.checked=undefined;
  399. _3d(_50,_54);
  400. }
  401. };
  402. function _56(_57,ul,_58,_59,_5a){
  403. var _5b=$.data(_57,"tree");
  404. var _5c=_5b.options;
  405. var _5d=$(ul).prevAll("div.tree-node:first");
  406. _58=_5c.loadFilter.call(_57,_58,_5d[0]);
  407. var _5e=_5f(_57,"domId",_5d.attr("id"));
  408. if(!_59){
  409. _5e?_5e.children=_58:_5b.data=_58;
  410. $(ul).empty();
  411. }else{
  412. if(_5e){
  413. _5e.children?_5e.children=_5e.children.concat(_58):_5e.children=_58;
  414. }else{
  415. _5b.data=_5b.data.concat(_58);
  416. }
  417. }
  418. _5c.view.render.call(_5c.view,_57,ul,_58);
  419. if(_5c.dnd){
  420. _11(_57);
  421. }
  422. if(_5e){
  423. _60(_57,_5e);
  424. }
  425. for(var i=0;i<_5b.tmpIds.length;i++){
  426. _34(_57,$("#"+_5b.tmpIds[i])[0],true,true);
  427. }
  428. _5b.tmpIds=[];
  429. setTimeout(function(){
  430. _61(_57,_57);
  431. },0);
  432. if(!_5a){
  433. _5c.onLoadSuccess.call(_57,_5e,_58);
  434. }
  435. };
  436. function _61(_62,ul,_63){
  437. var _64=$.data(_62,"tree").options;
  438. if(_64.lines){
  439. $(_62).addClass("tree-lines");
  440. }else{
  441. $(_62).removeClass("tree-lines");
  442. return;
  443. }
  444. if(!_63){
  445. _63=true;
  446. $(_62).find("span.tree-indent").removeClass("tree-line tree-join tree-joinbottom");
  447. $(_62).find("div.tree-node").removeClass("tree-node-last tree-root-first tree-root-one");
  448. var _65=$(_62).tree("getRoots");
  449. if(_65.length>1){
  450. $(_65[0].target).addClass("tree-root-first");
  451. }else{
  452. if(_65.length==1){
  453. $(_65[0].target).addClass("tree-root-one");
  454. }
  455. }
  456. }
  457. $(ul).children("li").each(function(){
  458. var _66=$(this).children("div.tree-node");
  459. var ul=_66.next("ul");
  460. if(ul.length){
  461. if($(this).next().length){
  462. _67(_66);
  463. }
  464. _61(_62,ul,_63);
  465. }else{
  466. _68(_66);
  467. }
  468. });
  469. var _69=$(ul).children("li:last").children("div.tree-node").addClass("tree-node-last");
  470. _69.children("span.tree-join").removeClass("tree-join").addClass("tree-joinbottom");
  471. function _68(_6a,_6b){
  472. var _6c=_6a.find("span.tree-icon");
  473. _6c.prev("span.tree-indent").addClass("tree-join");
  474. };
  475. function _67(_6d){
  476. var _6e=_6d.find("span.tree-indent, span.tree-hit").length;
  477. _6d.next().find("div.tree-node").each(function(){
  478. $(this).children("span:eq("+(_6e-1)+")").addClass("tree-line");
  479. });
  480. };
  481. };
  482. function _6f(_70,ul,_71,_72){
  483. var _73=$.data(_70,"tree").options;
  484. _71=$.extend({},_73.queryParams,_71||{});
  485. var _74=null;
  486. if(_70!=ul){
  487. var _75=$(ul).prev();
  488. _74=_c(_70,_75[0]);
  489. }
  490. if(_73.onBeforeLoad.call(_70,_74,_71)==false){
  491. return;
  492. }
  493. var _76=$(ul).prev().children("span.tree-folder");
  494. _76.addClass("tree-loading");
  495. var _77=_73.loader.call(_70,_71,function(_78){
  496. _76.removeClass("tree-loading");
  497. _56(_70,ul,_78);
  498. if(_72){
  499. _72();
  500. }
  501. },function(){
  502. _76.removeClass("tree-loading");
  503. _73.onLoadError.apply(_70,arguments);
  504. if(_72){
  505. _72();
  506. }
  507. });
  508. if(_77==false){
  509. _76.removeClass("tree-loading");
  510. }
  511. };
  512. function _79(_7a,_7b,_7c){
  513. var _7d=$.data(_7a,"tree").options;
  514. var hit=$(_7b).children("span.tree-hit");
  515. if(hit.length==0){
  516. return;
  517. }
  518. if(hit.hasClass("tree-expanded")){
  519. return;
  520. }
  521. var _7e=_c(_7a,_7b);
  522. if(_7d.onBeforeExpand.call(_7a,_7e)==false){
  523. return;
  524. }
  525. hit.removeClass("tree-collapsed tree-collapsed-hover").addClass("tree-expanded");
  526. hit.next().addClass("tree-folder-open");
  527. var ul=$(_7b).next();
  528. if(ul.length){
  529. if(_7d.animate){
  530. ul.slideDown("normal",function(){
  531. _7e.state="open";
  532. _7d.onExpand.call(_7a,_7e);
  533. if(_7c){
  534. _7c();
  535. }
  536. });
  537. }else{
  538. ul.css("display","block");
  539. _7e.state="open";
  540. _7d.onExpand.call(_7a,_7e);
  541. if(_7c){
  542. _7c();
  543. }
  544. }
  545. }else{
  546. var _7f=$("<ul style=\"display:none\"></ul>").insertAfter(_7b);
  547. _6f(_7a,_7f[0],{id:_7e.id},function(){
  548. if(_7f.is(":empty")){
  549. _7f.remove();
  550. }
  551. if(_7d.animate){
  552. _7f.slideDown("normal",function(){
  553. _7e.state="open";
  554. _7d.onExpand.call(_7a,_7e);
  555. if(_7c){
  556. _7c();
  557. }
  558. });
  559. }else{
  560. _7f.css("display","block");
  561. _7e.state="open";
  562. _7d.onExpand.call(_7a,_7e);
  563. if(_7c){
  564. _7c();
  565. }
  566. }
  567. });
  568. }
  569. };
  570. function _80(_81,_82){
  571. var _83=$.data(_81,"tree").options;
  572. var hit=$(_82).children("span.tree-hit");
  573. if(hit.length==0){
  574. return;
  575. }
  576. if(hit.hasClass("tree-collapsed")){
  577. return;
  578. }
  579. var _84=_c(_81,_82);
  580. if(_83.onBeforeCollapse.call(_81,_84)==false){
  581. return;
  582. }
  583. hit.removeClass("tree-expanded tree-expanded-hover").addClass("tree-collapsed");
  584. hit.next().removeClass("tree-folder-open");
  585. var ul=$(_82).next();
  586. if(_83.animate){
  587. ul.slideUp("normal",function(){
  588. _84.state="closed";
  589. _83.onCollapse.call(_81,_84);
  590. });
  591. }else{
  592. ul.css("display","none");
  593. _84.state="closed";
  594. _83.onCollapse.call(_81,_84);
  595. }
  596. };
  597. function _85(_86,_87){
  598. var hit=$(_87).children("span.tree-hit");
  599. if(hit.length==0){
  600. return;
  601. }
  602. if(hit.hasClass("tree-expanded")){
  603. _80(_86,_87);
  604. }else{
  605. _79(_86,_87);
  606. }
  607. };
  608. function _88(_89,_8a){
  609. var _8b=_8c(_89,_8a);
  610. if(_8a){
  611. _8b.unshift(_c(_89,_8a));
  612. }
  613. for(var i=0;i<_8b.length;i++){
  614. _79(_89,_8b[i].target);
  615. }
  616. };
  617. function _8d(_8e,_8f){
  618. var _90=[];
  619. var p=_4d(_8e,_8f);
  620. while(p){
  621. _90.unshift(p);
  622. p=_4d(_8e,p.target);
  623. }
  624. for(var i=0;i<_90.length;i++){
  625. _79(_8e,_90[i].target);
  626. }
  627. };
  628. function _91(_92,_93){
  629. var c=$(_92).parent();
  630. while(c[0].tagName!="BODY"&&c.css("overflow-y")!="auto"){
  631. c=c.parent();
  632. }
  633. var n=$(_93);
  634. var _94=n.offset().top;
  635. if(c[0].tagName!="BODY"){
  636. var _95=c.offset().top;
  637. if(_94<_95){
  638. c.scrollTop(c.scrollTop()+_94-_95);
  639. }else{
  640. if(_94+n.outerHeight()>_95+c.outerHeight()-18){
  641. c.scrollTop(c.scrollTop()+_94+n.outerHeight()-_95-c.outerHeight()+18);
  642. }
  643. }
  644. }else{
  645. c.scrollTop(_94);
  646. }
  647. };
  648. function _96(_97,_98){
  649. var _99=_8c(_97,_98);
  650. if(_98){
  651. _99.unshift(_c(_97,_98));
  652. }
  653. for(var i=0;i<_99.length;i++){
  654. _80(_97,_99[i].target);
  655. }
  656. };
  657. function _9a(_9b,_9c){
  658. var _9d=$(_9c.parent);
  659. var _9e=_9c.data;
  660. if(!_9e){
  661. return;
  662. }
  663. _9e=$.isArray(_9e)?_9e:[_9e];
  664. if(!_9e.length){
  665. return;
  666. }
  667. var ul;
  668. if(_9d.length==0){
  669. ul=$(_9b);
  670. }else{
  671. if(_9f(_9b,_9d[0])){
  672. var _a0=_9d.find("span.tree-icon");
  673. _a0.removeClass("tree-file").addClass("tree-folder tree-folder-open");
  674. var hit=$("<span class=\"tree-hit tree-expanded\"></span>").insertBefore(_a0);
  675. if(hit.prev().length){
  676. hit.prev().remove();
  677. }
  678. }
  679. ul=_9d.next();
  680. if(!ul.length){
  681. ul=$("<ul></ul>").insertAfter(_9d);
  682. }
  683. }
  684. _56(_9b,ul[0],_9e,true,true);
  685. };
  686. function _a1(_a2,_a3){
  687. var ref=_a3.before||_a3.after;
  688. var _a4=_4d(_a2,ref);
  689. var _a5=_a3.data;
  690. if(!_a5){
  691. return;
  692. }
  693. _a5=$.isArray(_a5)?_a5:[_a5];
  694. if(!_a5.length){
  695. return;
  696. }
  697. _9a(_a2,{parent:(_a4?_a4.target:null),data:_a5});
  698. var _a6=_a4?_a4.children:$(_a2).tree("getRoots");
  699. for(var i=0;i<_a6.length;i++){
  700. if(_a6[i].domId==$(ref).attr("id")){
  701. for(var j=_a5.length-1;j>=0;j--){
  702. _a6.splice((_a3.before?i:(i+1)),0,_a5[j]);
  703. }
  704. _a6.splice(_a6.length-_a5.length,_a5.length);
  705. break;
  706. }
  707. }
  708. var li=$();
  709. for(var i=0;i<_a5.length;i++){
  710. li=li.add($("#"+_a5[i].domId).parent());
  711. }
  712. if(_a3.before){
  713. li.insertBefore($(ref).parent());
  714. }else{
  715. li.insertAfter($(ref).parent());
  716. }
  717. };
  718. function _a7(_a8,_a9){
  719. var _aa=del(_a9);
  720. $(_a9).parent().remove();
  721. if(_aa){
  722. if(!_aa.children||!_aa.children.length){
  723. var _ab=$(_aa.target);
  724. _ab.find(".tree-icon").removeClass("tree-folder").addClass("tree-file");
  725. _ab.find(".tree-hit").remove();
  726. $("<span class=\"tree-indent\"></span>").prependTo(_ab);
  727. _ab.next().remove();
  728. }
  729. _60(_a8,_aa);
  730. }
  731. _61(_a8,_a8);
  732. function del(_ac){
  733. var id=$(_ac).attr("id");
  734. var _ad=_4d(_a8,_ac);
  735. var cc=_ad?_ad.children:$.data(_a8,"tree").data;
  736. for(var i=0;i<cc.length;i++){
  737. if(cc[i].domId==id){
  738. cc.splice(i,1);
  739. break;
  740. }
  741. }
  742. return _ad;
  743. };
  744. };
  745. function _60(_ae,_af){
  746. var _b0=$.data(_ae,"tree").options;
  747. var _b1=$(_af.target);
  748. var _b2=_c(_ae,_af.target);
  749. if(_b2.iconCls){
  750. _b1.find(".tree-icon").removeClass(_b2.iconCls);
  751. }
  752. $.extend(_b2,_af);
  753. _b1.find(".tree-title").html(_b0.formatter.call(_ae,_b2));
  754. if(_b2.iconCls){
  755. _b1.find(".tree-icon").addClass(_b2.iconCls);
  756. }
  757. _4f(_ae,_af.target);
  758. };
  759. function _b3(_b4,_b5){
  760. if(_b5){
  761. var p=_4d(_b4,_b5);
  762. while(p){
  763. _b5=p.target;
  764. p=_4d(_b4,_b5);
  765. }
  766. return _c(_b4,_b5);
  767. }else{
  768. var _b6=_b7(_b4);
  769. return _b6.length?_b6[0]:null;
  770. }
  771. };
  772. function _b7(_b8){
  773. var _b9=$.data(_b8,"tree").data;
  774. for(var i=0;i<_b9.length;i++){
  775. _ba(_b9[i]);
  776. }
  777. return _b9;
  778. };
  779. function _8c(_bb,_bc){
  780. var _bd=[];
  781. var n=_c(_bb,_bc);
  782. var _be=n?(n.children||[]):$.data(_bb,"tree").data;
  783. $.easyui.forEach(_be,true,function(_bf){
  784. _bd.push(_ba(_bf));
  785. });
  786. return _bd;
  787. };
  788. function _4d(_c0,_c1){
  789. var p=$(_c1).closest("ul").prevAll("div.tree-node:first");
  790. return _c(_c0,p[0]);
  791. };
  792. function _c2(_c3,_c4){
  793. _c4=_c4||"checked";
  794. if(!$.isArray(_c4)){
  795. _c4=[_c4];
  796. }
  797. var _c5=[];
  798. $.easyui.forEach($.data(_c3,"tree").data,true,function(n){
  799. if(n.checkState&&$.easyui.indexOfArray(_c4,n.checkState)!=-1){
  800. _c5.push(_ba(n));
  801. }
  802. });
  803. return _c5;
  804. };
  805. function _c6(_c7){
  806. var _c8=$(_c7).find("div.tree-node-selected");
  807. return _c8.length?_c(_c7,_c8[0]):null;
  808. };
  809. function _c9(_ca,_cb){
  810. var _cc=_c(_ca,_cb);
  811. if(_cc&&_cc.children){
  812. $.easyui.forEach(_cc.children,true,function(_cd){
  813. _ba(_cd);
  814. });
  815. }
  816. return _cc;
  817. };
  818. function _c(_ce,_cf){
  819. return _5f(_ce,"domId",$(_cf).attr("id"));
  820. };
  821. function _d0(_d1,id){
  822. return _5f(_d1,"id",id);
  823. };
  824. function _5f(_d2,_d3,_d4){
  825. var _d5=$.data(_d2,"tree").data;
  826. var _d6=null;
  827. $.easyui.forEach(_d5,true,function(_d7){
  828. if(_d7[_d3]==_d4){
  829. _d6=_ba(_d7);
  830. return false;
  831. }
  832. });
  833. return _d6;
  834. };
  835. function _ba(_d8){
  836. _d8.target=$("#"+_d8.domId)[0];
  837. return _d8;
  838. };
  839. function _d9(_da,_db){
  840. var _dc=$.data(_da,"tree").options;
  841. var _dd=_c(_da,_db);
  842. if(_dc.onBeforeSelect.call(_da,_dd)==false){
  843. return;
  844. }
  845. $(_da).find("div.tree-node-selected").removeClass("tree-node-selected");
  846. $(_db).addClass("tree-node-selected");
  847. _dc.onSelect.call(_da,_dd);
  848. };
  849. function _9f(_de,_df){
  850. return $(_df).children("span.tree-hit").length==0;
  851. };
  852. function _e0(_e1,_e2){
  853. var _e3=$.data(_e1,"tree").options;
  854. var _e4=_c(_e1,_e2);
  855. if(_e3.onBeforeEdit.call(_e1,_e4)==false){
  856. return;
  857. }
  858. $(_e2).css("position","relative");
  859. var nt=$(_e2).find(".tree-title");
  860. var _e5=nt.outerWidth();
  861. nt.empty();
  862. var _e6=$("<input class=\"tree-editor\">").appendTo(nt);
  863. _e6.val(_e4.text).focus();
  864. _e6.width(_e5+20);
  865. _e6._outerHeight(_e3.editorHeight);
  866. _e6.bind("click",function(e){
  867. return false;
  868. }).bind("mousedown",function(e){
  869. e.stopPropagation();
  870. }).bind("mousemove",function(e){
  871. e.stopPropagation();
  872. }).bind("keydown",function(e){
  873. if(e.keyCode==13){
  874. _e7(_e1,_e2);
  875. return false;
  876. }else{
  877. if(e.keyCode==27){
  878. _ed(_e1,_e2);
  879. return false;
  880. }
  881. }
  882. }).bind("blur",function(e){
  883. e.stopPropagation();
  884. _e7(_e1,_e2);
  885. });
  886. };
  887. function _e7(_e8,_e9){
  888. var _ea=$.data(_e8,"tree").options;
  889. $(_e9).css("position","");
  890. var _eb=$(_e9).find("input.tree-editor");
  891. var val=_eb.val();
  892. _eb.remove();
  893. var _ec=_c(_e8,_e9);
  894. _ec.text=val;
  895. _60(_e8,_ec);
  896. _ea.onAfterEdit.call(_e8,_ec);
  897. };
  898. function _ed(_ee,_ef){
  899. var _f0=$.data(_ee,"tree").options;
  900. $(_ef).css("position","");
  901. $(_ef).find("input.tree-editor").remove();
  902. var _f1=_c(_ee,_ef);
  903. _60(_ee,_f1);
  904. _f0.onCancelEdit.call(_ee,_f1);
  905. };
  906. function _f2(_f3,q){
  907. var _f4=$.data(_f3,"tree");
  908. var _f5=_f4.options;
  909. var ids={};
  910. $.easyui.forEach(_f4.data,true,function(_f6){
  911. if(_f5.filter.call(_f3,q,_f6)){
  912. $("#"+_f6.domId).removeClass("tree-node-hidden");
  913. ids[_f6.domId]=1;
  914. _f6.hidden=false;
  915. }else{
  916. $("#"+_f6.domId).addClass("tree-node-hidden");
  917. _f6.hidden=true;
  918. }
  919. });
  920. for(var id in ids){
  921. _f7(id);
  922. }
  923. function _f7(_f8){
  924. var p=$(_f3).tree("getParent",$("#"+_f8)[0]);
  925. while(p){
  926. $(p.target).removeClass("tree-node-hidden");
  927. p.hidden=false;
  928. p=$(_f3).tree("getParent",p.target);
  929. }
  930. };
  931. };
  932. $.fn.tree=function(_f9,_fa){
  933. if(typeof _f9=="string"){
  934. return $.fn.tree.methods[_f9](this,_fa);
  935. }
  936. var _f9=_f9||{};
  937. return this.each(function(){
  938. var _fb=$.data(this,"tree");
  939. var _fc;
  940. if(_fb){
  941. _fc=$.extend(_fb.options,_f9);
  942. _fb.options=_fc;
  943. }else{
  944. _fc=$.extend({},$.fn.tree.defaults,$.fn.tree.parseOptions(this),_f9);
  945. $.data(this,"tree",{options:_fc,tree:_1(this),data:[],tmpIds:[]});
  946. var _fd=$.fn.tree.parseData(this);
  947. if(_fd.length){
  948. _56(this,this,_fd);
  949. }
  950. }
  951. _4(this);
  952. if(_fc.data){
  953. _56(this,this,$.extend(true,[],_fc.data));
  954. }
  955. _6f(this,this);
  956. });
  957. };
  958. $.fn.tree.methods={options:function(jq){
  959. return $.data(jq[0],"tree").options;
  960. },loadData:function(jq,_fe){
  961. return jq.each(function(){
  962. _56(this,this,_fe);
  963. });
  964. },getNode:function(jq,_ff){
  965. return _c(jq[0],_ff);
  966. },getData:function(jq,_100){
  967. return _c9(jq[0],_100);
  968. },reload:function(jq,_101){
  969. return jq.each(function(){
  970. if(_101){
  971. var node=$(_101);
  972. var hit=node.children("span.tree-hit");
  973. hit.removeClass("tree-expanded tree-expanded-hover").addClass("tree-collapsed");
  974. node.next().remove();
  975. _79(this,_101);
  976. }else{
  977. $(this).empty();
  978. _6f(this,this);
  979. }
  980. });
  981. },getRoot:function(jq,_102){
  982. return _b3(jq[0],_102);
  983. },getRoots:function(jq){
  984. return _b7(jq[0]);
  985. },getParent:function(jq,_103){
  986. return _4d(jq[0],_103);
  987. },getChildren:function(jq,_104){
  988. return _8c(jq[0],_104);
  989. },getChecked:function(jq,_105){
  990. return _c2(jq[0],_105);
  991. },getSelected:function(jq){
  992. return _c6(jq[0]);
  993. },isLeaf:function(jq,_106){
  994. return _9f(jq[0],_106);
  995. },find:function(jq,id){
  996. return _d0(jq[0],id);
  997. },select:function(jq,_107){
  998. return jq.each(function(){
  999. _d9(this,_107);
  1000. });
  1001. },check:function(jq,_108){
  1002. return jq.each(function(){
  1003. _34(this,_108,true);
  1004. });
  1005. },uncheck:function(jq,_109){
  1006. return jq.each(function(){
  1007. _34(this,_109,false);
  1008. });
  1009. },collapse:function(jq,_10a){
  1010. return jq.each(function(){
  1011. _80(this,_10a);
  1012. });
  1013. },expand:function(jq,_10b){
  1014. return jq.each(function(){
  1015. _79(this,_10b);
  1016. });
  1017. },collapseAll:function(jq,_10c){
  1018. return jq.each(function(){
  1019. _96(this,_10c);
  1020. });
  1021. },expandAll:function(jq,_10d){
  1022. return jq.each(function(){
  1023. _88(this,_10d);
  1024. });
  1025. },expandTo:function(jq,_10e){
  1026. return jq.each(function(){
  1027. _8d(this,_10e);
  1028. });
  1029. },scrollTo:function(jq,_10f){
  1030. return jq.each(function(){
  1031. _91(this,_10f);
  1032. });
  1033. },toggle:function(jq,_110){
  1034. return jq.each(function(){
  1035. _85(this,_110);
  1036. });
  1037. },append:function(jq,_111){
  1038. return jq.each(function(){
  1039. _9a(this,_111);
  1040. });
  1041. },insert:function(jq,_112){
  1042. return jq.each(function(){
  1043. _a1(this,_112);
  1044. });
  1045. },remove:function(jq,_113){
  1046. return jq.each(function(){
  1047. _a7(this,_113);
  1048. });
  1049. },pop:function(jq,_114){
  1050. var node=jq.tree("getData",_114);
  1051. jq.tree("remove",_114);
  1052. return node;
  1053. },update:function(jq,_115){
  1054. return jq.each(function(){
  1055. _60(this,$.extend({},_115,{checkState:_115.checked?"checked":(_115.checked===false?"unchecked":undefined)}));
  1056. });
  1057. },enableDnd:function(jq){
  1058. return jq.each(function(){
  1059. _11(this);
  1060. });
  1061. },disableDnd:function(jq){
  1062. return jq.each(function(){
  1063. _d(this);
  1064. });
  1065. },beginEdit:function(jq,_116){
  1066. return jq.each(function(){
  1067. _e0(this,_116);
  1068. });
  1069. },endEdit:function(jq,_117){
  1070. return jq.each(function(){
  1071. _e7(this,_117);
  1072. });
  1073. },cancelEdit:function(jq,_118){
  1074. return jq.each(function(){
  1075. _ed(this,_118);
  1076. });
  1077. },doFilter:function(jq,q){
  1078. return jq.each(function(){
  1079. _f2(this,q);
  1080. });
  1081. }};
  1082. $.fn.tree.parseOptions=function(_119){
  1083. var t=$(_119);
  1084. return $.extend({},$.parser.parseOptions(_119,["url","method",{checkbox:"boolean",cascadeCheck:"boolean",onlyLeafCheck:"boolean"},{animate:"boolean",lines:"boolean",dnd:"boolean"}]));
  1085. };
  1086. $.fn.tree.parseData=function(_11a){
  1087. var data=[];
  1088. _11b(data,$(_11a));
  1089. return data;
  1090. function _11b(aa,tree){
  1091. tree.children("li").each(function(){
  1092. var node=$(this);
  1093. var item=$.extend({},$.parser.parseOptions(this,["id","iconCls","state"]),{checked:(node.attr("checked")?true:undefined)});
  1094. item.text=node.children("span").html();
  1095. if(!item.text){
  1096. item.text=node.html();
  1097. }
  1098. var _11c=node.children("ul");
  1099. if(_11c.length){
  1100. item.children=[];
  1101. _11b(item.children,_11c);
  1102. }
  1103. aa.push(item);
  1104. });
  1105. };
  1106. };
  1107. var _11d=1;
  1108. var _11e={render:function(_11f,ul,data){
  1109. var _120=$.data(_11f,"tree");
  1110. var opts=_120.options;
  1111. var _121=$(ul).prev(".tree-node");
  1112. var _122=_121.length?$(_11f).tree("getNode",_121[0]):null;
  1113. var _123=_121.find("span.tree-indent, span.tree-hit").length;
  1114. var cc=_124.call(this,_123,data);
  1115. $(ul).append(cc.join(""));
  1116. function _124(_125,_126){
  1117. var cc=[];
  1118. for(var i=0;i<_126.length;i++){
  1119. var item=_126[i];
  1120. if(item.state!="open"&&item.state!="closed"){
  1121. item.state="open";
  1122. }
  1123. item.domId="_easyui_tree_"+_11d++;
  1124. cc.push("<li>");
  1125. cc.push("<div id=\""+item.domId+"\" class=\"tree-node"+(item.nodeCls?" "+item.nodeCls:"")+"\">");
  1126. for(var j=0;j<_125;j++){
  1127. cc.push("<span class=\"tree-indent\"></span>");
  1128. }
  1129. if(item.state=="closed"){
  1130. cc.push("<span class=\"tree-hit tree-collapsed\"></span>");
  1131. cc.push("<span class=\"tree-icon tree-folder "+(item.iconCls?item.iconCls:"")+"\"></span>");
  1132. }else{
  1133. if(item.children&&item.children.length){
  1134. cc.push("<span class=\"tree-hit tree-expanded\"></span>");
  1135. cc.push("<span class=\"tree-icon tree-folder tree-folder-open "+(item.iconCls?item.iconCls:"")+"\"></span>");
  1136. }else{
  1137. cc.push("<span class=\"tree-indent\"></span>");
  1138. cc.push("<span class=\"tree-icon tree-file "+(item.iconCls?item.iconCls:"")+"\"></span>");
  1139. }
  1140. }
  1141. if(this.hasCheckbox(_11f,item)){
  1142. var flag=0;
  1143. if(_122&&_122.checkState=="checked"&&opts.cascadeCheck){
  1144. flag=1;
  1145. item.checked=true;
  1146. }else{
  1147. if(item.checked){
  1148. $.easyui.addArrayItem(_120.tmpIds,item.domId);
  1149. }
  1150. }
  1151. item.checkState=flag?"checked":"unchecked";
  1152. cc.push("<span class=\"tree-checkbox tree-checkbox"+flag+"\"></span>");
  1153. }else{
  1154. item.checkState=undefined;
  1155. item.checked=undefined;
  1156. }
  1157. cc.push("<span class=\"tree-title\">"+opts.formatter.call(_11f,item)+"</span>");
  1158. cc.push("</div>");
  1159. if(item.children&&item.children.length){
  1160. var tmp=_124.call(this,_125+1,item.children);
  1161. cc.push("<ul style=\"display:"+(item.state=="closed"?"none":"block")+"\">");
  1162. cc=cc.concat(tmp);
  1163. cc.push("</ul>");
  1164. }
  1165. cc.push("</li>");
  1166. }
  1167. return cc;
  1168. };
  1169. },hasCheckbox:function(_127,item){
  1170. var _128=$.data(_127,"tree");
  1171. var opts=_128.options;
  1172. if(opts.checkbox){
  1173. if($.isFunction(opts.checkbox)){
  1174. if(opts.checkbox.call(_127,item)){
  1175. return true;
  1176. }else{
  1177. return false;
  1178. }
  1179. }else{
  1180. if(opts.onlyLeafCheck){
  1181. if(item.state=="open"&&!(item.children&&item.children.length)){
  1182. return true;
  1183. }
  1184. }else{
  1185. return true;
  1186. }
  1187. }
  1188. }
  1189. return false;
  1190. }};
  1191. $.fn.tree.defaults={url:null,method:"post",animate:false,checkbox:false,cascadeCheck:true,onlyLeafCheck:false,lines:false,dnd:false,editorHeight:26,data:null,queryParams:{},formatter:function(node){
  1192. return node.text;
  1193. },filter:function(q,node){
  1194. var qq=[];
  1195. $.map($.isArray(q)?q:[q],function(q){
  1196. q=$.trim(q);
  1197. if(q){
  1198. qq.push(q);
  1199. }
  1200. });
  1201. for(var i=0;i<qq.length;i++){
  1202. var _129=node.text.toLowerCase().indexOf(qq[i].toLowerCase());
  1203. if(_129>=0){
  1204. return true;
  1205. }
  1206. }
  1207. return !qq.length;
  1208. },loader:function(_12a,_12b,_12c){
  1209. var opts=$(this).tree("options");
  1210. if(!opts.url){
  1211. return false;
  1212. }
  1213. $.ajax({type:opts.method,url:opts.url,data:_12a,dataType:"json",success:function(data){
  1214. _12b(data);
  1215. },error:function(){
  1216. _12c.apply(this,arguments);
  1217. }});
  1218. },loadFilter:function(data,_12d){
  1219. return data;
  1220. },view:_11e,onBeforeLoad:function(node,_12e){
  1221. },onLoadSuccess:function(node,data){
  1222. },onLoadError:function(){
  1223. },onClick:function(node){
  1224. },onDblClick:function(node){
  1225. },onBeforeExpand:function(node){
  1226. },onExpand:function(node){
  1227. },onBeforeCollapse:function(node){
  1228. },onCollapse:function(node){
  1229. },onBeforeCheck:function(node,_12f){
  1230. },onCheck:function(node,_130){
  1231. },onBeforeSelect:function(node){
  1232. },onSelect:function(node){
  1233. },onContextMenu:function(e,node){
  1234. },onBeforeDrag:function(node){
  1235. },onStartDrag:function(node){
  1236. },onStopDrag:function(node){
  1237. },onDragEnter:function(_131,_132){
  1238. },onDragOver:function(_133,_134){
  1239. },onDragLeave:function(_135,_136){
  1240. },onBeforeDrop:function(_137,_138,_139){
  1241. },onDrop:function(_13a,_13b,_13c){
  1242. },onBeforeEdit:function(node){
  1243. },onAfterEdit:function(node){
  1244. },onCancelEdit:function(node){
  1245. }};
  1246. })(jQuery);