jquery.tagbox.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * EasyUI for jQuery 1.5.5.4
  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=$.data(_2,"tagbox");
  13. var _4=_3.options;
  14. $(_2).addClass("tagbox-f").combobox($.extend({},_4,{cls:"tagbox",reversed:true,onChange:function(_5,_6){
  15. _7();
  16. $(this).combobox("hidePanel");
  17. _4.onChange.call(_2,_5,_6);
  18. },onResizing:function(_8,_9){
  19. var _a=$(this).combobox("textbox");
  20. var tb=$(this).data("textbox").textbox;
  21. var _b=tb.outerWidth();
  22. tb.css({height:"",paddingLeft:_a.css("marginLeft"),paddingRight:_a.css("marginRight")});
  23. _a.css("margin",0);
  24. tb._outerWidth(_b);
  25. _23(_2);
  26. _12(this);
  27. _4.onResizing.call(_2,_8,_9);
  28. },onLoadSuccess:function(_c){
  29. _7();
  30. _4.onLoadSuccess.call(_2,_c);
  31. }}));
  32. _7();
  33. _23(_2);
  34. function _7(){
  35. $(_2).next().find(".tagbox-label").remove();
  36. var _d=$(_2).tagbox("textbox");
  37. var ss=[];
  38. $.map($(_2).tagbox("getValues"),function(_e,_f){
  39. var row=_4.finder.getRow(_2,_e);
  40. var _10=_4.tagFormatter.call(_2,_e,row);
  41. var cs={};
  42. var css=_4.tagStyler.call(_2,_e,row)||"";
  43. if(typeof css=="string"){
  44. cs={s:css};
  45. }else{
  46. cs={c:css["class"]||"",s:css["style"]||""};
  47. }
  48. var _11=$("<span class=\"tagbox-label\"></span>").insertBefore(_d).html(_10);
  49. _11.attr("tagbox-index",_f);
  50. _11.attr("style",cs.s).addClass(cs.c);
  51. $("<a href=\"javascript:;\" class=\"tagbox-remove\"></a>").appendTo(_11);
  52. });
  53. _12(_2);
  54. $(_2).combobox("setText","");
  55. };
  56. };
  57. function _12(_13,_14){
  58. var _15=$(_13).next();
  59. var _16=_14?$(_14):_15.find(".tagbox-label");
  60. if(_16.length){
  61. var _17=$(_13).tagbox("textbox");
  62. var _18=$(_16[0]);
  63. var _19=_18.outerHeight(true)-_18.outerHeight();
  64. var _1a=_17.outerHeight()-_19*2;
  65. _16.css({height:_1a+"px",lineHeight:_1a+"px"});
  66. var _1b=_15.find(".textbox-addon").css("height","100%");
  67. _1b.find(".textbox-icon").css("height","100%");
  68. _15.find(".textbox-button").linkbutton("resize",{height:"100%"});
  69. }
  70. };
  71. function _1c(_1d){
  72. var _1e=$(_1d).next();
  73. _1e.unbind(".tagbox").bind("click.tagbox",function(e){
  74. var _1f=$(_1d).tagbox("options");
  75. if(_1f.disabled||_1f.readonly){
  76. return;
  77. }
  78. if($(e.target).hasClass("tagbox-remove")){
  79. var _20=parseInt($(e.target).parent().attr("tagbox-index"));
  80. var _21=$(_1d).tagbox("getValues");
  81. if(_1f.onBeforeRemoveTag.call(_1d,_21[_20])==false){
  82. return;
  83. }
  84. _1f.onRemoveTag.call(_1d,_21[_20]);
  85. _21.splice(_20,1);
  86. $(_1d).tagbox("setValues",_21);
  87. }else{
  88. var _22=$(e.target).closest(".tagbox-label");
  89. if(_22.length){
  90. var _20=parseInt(_22.attr("tagbox-index"));
  91. var _21=$(_1d).tagbox("getValues");
  92. _1f.onClickTag.call(_1d,_21[_20]);
  93. }
  94. }
  95. $(this).find(".textbox-text").focus();
  96. }).bind("keyup.tagbox",function(e){
  97. _23(_1d);
  98. }).bind("mouseover.tagbox",function(e){
  99. if($(e.target).closest(".textbox-button,.textbox-addon,.tagbox-label").length){
  100. $(this).triggerHandler("mouseleave");
  101. }else{
  102. $(this).find(".textbox-text").triggerHandler("mouseenter");
  103. }
  104. }).bind("mouseleave.tagbox",function(e){
  105. $(this).find(".textbox-text").triggerHandler("mouseleave");
  106. });
  107. };
  108. function _23(_24){
  109. var _25=$(_24).tagbox("options");
  110. var _26=$(_24).tagbox("textbox");
  111. var _27=$(_24).next();
  112. var tmp=$("<span></span>").appendTo("body");
  113. tmp.attr("style",_26.attr("style"));
  114. tmp.css({position:"absolute",top:-9999,left:-9999,width:"auto",fontFamily:_26.css("fontFamily"),fontSize:_26.css("fontSize"),fontWeight:_26.css("fontWeight"),whiteSpace:"nowrap"});
  115. var _28=_29(_26.val());
  116. var _2a=_29(_25.prompt||"");
  117. tmp.remove();
  118. var _2b=Math.min(Math.max(_28,_2a)+20,_27.width());
  119. _26._outerWidth(_2b);
  120. _27.find(".textbox-button").linkbutton("resize",{height:"100%"});
  121. function _29(val){
  122. var s=val.replace(/&/g,"&amp;").replace(/\s/g," ").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  123. tmp.html(s);
  124. return tmp.outerWidth();
  125. };
  126. };
  127. function _2c(_2d){
  128. var t=$(_2d);
  129. var _2e=t.tagbox("options");
  130. if(_2e.limitToList){
  131. var _2f=t.tagbox("panel");
  132. var _30=_2f.children("div.combobox-item-hover");
  133. if(_30.length){
  134. _30.removeClass("combobox-item-hover");
  135. var row=_2e.finder.getRow(_2d,_30);
  136. var _31=row[_2e.valueField];
  137. $(_2d).tagbox(_30.hasClass("combobox-item-selected")?"unselect":"select",_31);
  138. }
  139. $(_2d).tagbox("hidePanel");
  140. }else{
  141. var v=$.trim($(_2d).tagbox("getText"));
  142. if(v!==""){
  143. var _32=$(_2d).tagbox("getValues");
  144. _32.push(v);
  145. $(_2d).tagbox("setValues",_32);
  146. }
  147. }
  148. };
  149. function _33(_34,_35){
  150. $(_34).combobox("setText","");
  151. _23(_34);
  152. $(_34).combobox("setValues",_35);
  153. $(_34).combobox("setText","");
  154. $(_34).tagbox("validate");
  155. };
  156. $.fn.tagbox=function(_36,_37){
  157. if(typeof _36=="string"){
  158. var _38=$.fn.tagbox.methods[_36];
  159. if(_38){
  160. return _38(this,_37);
  161. }else{
  162. return this.combobox(_36,_37);
  163. }
  164. }
  165. _36=_36||{};
  166. return this.each(function(){
  167. var _39=$.data(this,"tagbox");
  168. if(_39){
  169. $.extend(_39.options,_36);
  170. }else{
  171. $.data(this,"tagbox",{options:$.extend({},$.fn.tagbox.defaults,$.fn.tagbox.parseOptions(this),_36)});
  172. }
  173. _1(this);
  174. _1c(this);
  175. });
  176. };
  177. $.fn.tagbox.methods={options:function(jq){
  178. var _3a=jq.combobox("options");
  179. return $.extend($.data(jq[0],"tagbox").options,{width:_3a.width,height:_3a.height,originalValue:_3a.originalValue,disabled:_3a.disabled,readonly:_3a.readonly});
  180. },setValues:function(jq,_3b){
  181. return jq.each(function(){
  182. _33(this,_3b);
  183. });
  184. },reset:function(jq){
  185. return jq.each(function(){
  186. $(this).combobox("reset").combobox("setText","");
  187. });
  188. }};
  189. $.fn.tagbox.parseOptions=function(_3c){
  190. return $.extend({},$.fn.combobox.parseOptions(_3c),$.parser.parseOptions(_3c,[]));
  191. };
  192. $.fn.tagbox.defaults=$.extend({},$.fn.combobox.defaults,{hasDownArrow:false,multiple:true,reversed:true,selectOnNavigation:false,tipOptions:$.extend({},$.fn.textbox.defaults.tipOptions,{showDelay:200}),val:function(_3d){
  193. var vv=$(_3d).parent().prev().tagbox("getValues");
  194. if($(_3d).is(":focus")){
  195. vv.push($(_3d).val());
  196. }
  197. return vv.join(",");
  198. },inputEvents:$.extend({},$.fn.combo.defaults.inputEvents,{blur:function(e){
  199. var _3e=e.data.target;
  200. var _3f=$(_3e).tagbox("options");
  201. if(_3f.limitToList){
  202. _2c(_3e);
  203. }
  204. }}),keyHandler:$.extend({},$.fn.combobox.defaults.keyHandler,{enter:function(e){
  205. _2c(this);
  206. },query:function(q,e){
  207. var _40=$(this).tagbox("options");
  208. if(_40.limitToList){
  209. $.fn.combobox.defaults.keyHandler.query.call(this,q,e);
  210. }else{
  211. $(this).combobox("hidePanel");
  212. }
  213. }}),tagFormatter:function(_41,row){
  214. var _42=$(this).tagbox("options");
  215. return row?row[_42.textField]:_41;
  216. },tagStyler:function(_43,row){
  217. return "";
  218. },onClickTag:function(_44){
  219. },onBeforeRemoveTag:function(_45){
  220. },onRemoveTag:function(_46){
  221. }});
  222. })(jQuery);