jquery.tree.js 26 KB

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