jquery.combotree.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * jQuery EasyUI 1.3.4
  3. *
  4. * Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL or commercial licenses
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. * http://www.gnu.org/licenses/gpl.txt
  9. * http://www.jeasyui.com/license_commercial.php
  10. *
  11. */
  12. (function($){
  13. function _1(_2){
  14. var _3=$.data(_2,"combotree").options;
  15. var _4=$.data(_2,"combotree").tree;
  16. $(_2).addClass("combotree-f");
  17. $(_2).combo(_3);
  18. var _5=$(_2).combo("panel");
  19. if(!_4){
  20. _4=$("<ul></ul>").appendTo(_5);
  21. $.data(_2,"combotree").tree=_4;
  22. }
  23. _4.tree($.extend({},_3,{checkbox:_3.multiple,onLoadSuccess:function(_6,_7){
  24. var _8=$(_2).combotree("getValues");
  25. if(_3.multiple){
  26. var _9=_4.tree("getChecked");
  27. for(var i=0;i<_9.length;i++){
  28. var id=_9[i].id;
  29. (function(){
  30. for(var i=0;i<_8.length;i++){
  31. if(id==_8[i]){
  32. return;
  33. }
  34. }
  35. _8.push(id);
  36. })();
  37. }
  38. }
  39. $(_2).combotree("setValues",_8);
  40. _3.onLoadSuccess.call(this,_6,_7);
  41. },onClick:function(_a){
  42. _d(_2);
  43. $(_2).combo("hidePanel");
  44. _3.onClick.call(this,_a);
  45. },onCheck:function(_b,_c){
  46. _d(_2);
  47. _3.onCheck.call(this,_b,_c);
  48. }}));
  49. };
  50. function _d(_e){
  51. var _f=$.data(_e,"combotree").options;
  52. var _10=$.data(_e,"combotree").tree;
  53. var vv=[],ss=[];
  54. if(_f.multiple){
  55. var _11=_10.tree("getChecked");
  56. for(var i=0;i<_11.length;i++){
  57. vv.push(_11[i].id);
  58. ss.push(_11[i].text);
  59. }
  60. }else{
  61. var _12=_10.tree("getSelected");
  62. if(_12){
  63. vv.push(_12.id);
  64. ss.push(_12.text);
  65. }
  66. }
  67. $(_e).combo("setValues",vv).combo("setText",ss.join(_f.separator));
  68. };
  69. function _13(_14,_15){
  70. var _16=$.data(_14,"combotree").options;
  71. var _17=$.data(_14,"combotree").tree;
  72. _17.find("span.tree-checkbox").addClass("tree-checkbox0").removeClass("tree-checkbox1 tree-checkbox2");
  73. var vv=[],ss=[];
  74. for(var i=0;i<_15.length;i++){
  75. var v=_15[i];
  76. var s=v;
  77. var _18=_17.tree("find",v);
  78. if(_18){
  79. s=_18.text;
  80. _17.tree("check",_18.target);
  81. _17.tree("select",_18.target);
  82. }
  83. vv.push(v);
  84. ss.push(s);
  85. }
  86. $(_14).combo("setValues",vv).combo("setText",ss.join(_16.separator));
  87. };
  88. $.fn.combotree=function(_19,_1a){
  89. if(typeof _19=="string"){
  90. var _1b=$.fn.combotree.methods[_19];
  91. if(_1b){
  92. return _1b(this,_1a);
  93. }else{
  94. return this.combo(_19,_1a);
  95. }
  96. }
  97. _19=_19||{};
  98. return this.each(function(){
  99. var _1c=$.data(this,"combotree");
  100. if(_1c){
  101. $.extend(_1c.options,_19);
  102. }else{
  103. $.data(this,"combotree",{options:$.extend({},$.fn.combotree.defaults,$.fn.combotree.parseOptions(this),_19)});
  104. }
  105. _1(this);
  106. });
  107. };
  108. $.fn.combotree.methods={options:function(jq){
  109. var _1d=jq.combo("options");
  110. return $.extend($.data(jq[0],"combotree").options,{originalValue:_1d.originalValue,disabled:_1d.disabled,readonly:_1d.readonly});
  111. },tree:function(jq){
  112. return $.data(jq[0],"combotree").tree;
  113. },loadData:function(jq,_1e){
  114. return jq.each(function(){
  115. var _1f=$.data(this,"combotree").options;
  116. _1f.data=_1e;
  117. var _20=$.data(this,"combotree").tree;
  118. _20.tree("loadData",_1e);
  119. });
  120. },reload:function(jq,url){
  121. return jq.each(function(){
  122. var _21=$.data(this,"combotree").options;
  123. var _22=$.data(this,"combotree").tree;
  124. if(url){
  125. _21.url=url;
  126. }
  127. _22.tree({url:_21.url});
  128. });
  129. },setValues:function(jq,_23){
  130. return jq.each(function(){
  131. _13(this,_23);
  132. });
  133. },setValue:function(jq,_24){
  134. return jq.each(function(){
  135. _13(this,[_24]);
  136. });
  137. },clear:function(jq){
  138. return jq.each(function(){
  139. var _25=$.data(this,"combotree").tree;
  140. _25.find("div.tree-node-selected").removeClass("tree-node-selected");
  141. var cc=_25.tree("getChecked");
  142. for(var i=0;i<cc.length;i++){
  143. _25.tree("uncheck",cc[i].target);
  144. }
  145. $(this).combo("clear");
  146. });
  147. },reset:function(jq){
  148. return jq.each(function(){
  149. var _26=$(this).combotree("options");
  150. if(_26.multiple){
  151. $(this).combotree("setValues",_26.originalValue);
  152. }else{
  153. $(this).combotree("setValue",_26.originalValue);
  154. }
  155. });
  156. }};
  157. $.fn.combotree.parseOptions=function(_27){
  158. return $.extend({},$.fn.combo.parseOptions(_27),$.fn.tree.parseOptions(_27));
  159. };
  160. $.fn.combotree.defaults=$.extend({},$.fn.combo.defaults,$.fn.tree.defaults,{editable:false});
  161. })(jQuery);