jquery.tagbox.js 6.2 KB

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