bf3c2134ada7c32fab150db9e1e207d3d2e625f0.svn-base 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * jQuery EasyUI 1.3.6
  3. *
  4. * Copyright (c) 2009-2014 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. $(_2).addClass("validatebox-text");
  13. };
  14. function _3(_4){
  15. var _5=$.data(_4,"validatebox");
  16. _5.validating=false;
  17. if(_5.timer){
  18. clearTimeout(_5.timer);
  19. }
  20. $(_4).tooltip("destroy");
  21. $(_4).unbind();
  22. $(_4).remove();
  23. };
  24. function _6(_7){
  25. var _8=$(_7);
  26. var _9=$.data(_7,"validatebox");
  27. _8.unbind(".validatebox");
  28. if(_9.options.novalidate){
  29. return;
  30. }
  31. _8.bind("focus.validatebox",function(){
  32. _9.validating=true;
  33. _9.value=undefined;
  34. (function(){
  35. if(_9.validating){
  36. if(_9.value!=_8.val()){
  37. _9.value=_8.val();
  38. if(_9.timer){
  39. clearTimeout(_9.timer);
  40. }
  41. _9.timer=setTimeout(function(){
  42. $(_7).validatebox("validate");
  43. },_9.options.delay);
  44. }else{
  45. _f(_7);
  46. }
  47. setTimeout(arguments.callee,200);
  48. }
  49. })();
  50. }).bind("blur.validatebox",function(){
  51. if(_9.timer){
  52. clearTimeout(_9.timer);
  53. _9.timer=undefined;
  54. }
  55. _9.validating=false;
  56. _a(_7);
  57. }).bind("mouseenter.validatebox",function(){
  58. if(_8.hasClass("validatebox-invalid")){
  59. _b(_7);
  60. }
  61. }).bind("mouseleave.validatebox",function(){
  62. if(!_9.validating){
  63. _a(_7);
  64. }
  65. });
  66. };
  67. function _b(_c){
  68. var _d=$.data(_c,"validatebox");
  69. var _e=_d.options;
  70. $(_c).tooltip($.extend({},_e.tipOptions,{content:_d.message,position:_e.tipPosition,deltaX:_e.deltaX})).tooltip("show");
  71. _d.tip=true;
  72. };
  73. function _f(_10){
  74. var _11=$.data(_10,"validatebox");
  75. if(_11&&_11.tip){
  76. $(_10).tooltip("reposition");
  77. }
  78. };
  79. function _a(_12){
  80. var _13=$.data(_12,"validatebox");
  81. _13.tip=false;
  82. $(_12).tooltip("hide");
  83. };
  84. function _14(_15){
  85. var _16=$.data(_15,"validatebox");
  86. var _17=_16.options;
  87. var box=$(_15);
  88. var _18=box.val();
  89. function _19(msg){
  90. _16.message=msg;
  91. };
  92. function _1a(_1b,_1c){
  93. var _1d=/([a-zA-Z_]+)(.*)/.exec(_1b);
  94. var _1e=_17.rules[_1d[1]];
  95. if(_1e&&_18){
  96. var _1f=_1c||_17.validParams||eval(_1d[2]);
  97. if(!_1e["validator"].call(_15,_18,_1f)){
  98. box.addClass("validatebox-invalid");
  99. var _20=_1e["message"];
  100. if(_1f){
  101. for(var i=0;i<_1f.length;i++){
  102. _20=_20.replace(new RegExp("\\{"+i+"\\}","g"),_1f[i]);
  103. }
  104. }
  105. _19(_17.invalidMessage||_20);
  106. if(_16.validating){
  107. _b(_15);
  108. }
  109. return false;
  110. }
  111. }
  112. return true;
  113. };
  114. box.removeClass("validatebox-invalid");
  115. _a(_15);
  116. if(_17.novalidate||box.is(":disabled")){
  117. return true;
  118. }
  119. if(_17.required){
  120. if(_18==""){
  121. box.addClass("validatebox-invalid");
  122. _19(_17.missingMessage);
  123. if(_16.validating){
  124. _b(_15);
  125. }
  126. return false;
  127. }
  128. }
  129. if(_17.validType){
  130. if($.isArray(_17.validType)){
  131. for(var i=0;i<_17.validType.length;i++){
  132. if(!_1a(_17.validType[i])){
  133. return false;
  134. }
  135. }
  136. }else{
  137. if(typeof _17.validType=="string"){
  138. if(!_1a(_17.validType)){
  139. return false;
  140. }
  141. }else{
  142. for(var _21 in _17.validType){
  143. var _22=_17.validType[_21];
  144. if(!_1a(_21,_22)){
  145. return false;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. return true;
  152. };
  153. function _23(_24,_25){
  154. var _26=$.data(_24,"validatebox").options;
  155. if(_25!=undefined){
  156. _26.novalidate=_25;
  157. }
  158. if(_26.novalidate){
  159. $(_24).removeClass("validatebox-invalid");
  160. _a(_24);
  161. }
  162. _6(_24);
  163. };
  164. $.fn.validatebox=function(_27,_28){
  165. if(typeof _27=="string"){
  166. return $.fn.validatebox.methods[_27](this,_28);
  167. }
  168. _27=_27||{};
  169. return this.each(function(){
  170. var _29=$.data(this,"validatebox");
  171. if(_29){
  172. $.extend(_29.options,_27);
  173. }else{
  174. _1(this);
  175. $.data(this,"validatebox",{options:$.extend({},$.fn.validatebox.defaults,$.fn.validatebox.parseOptions(this),_27)});
  176. }
  177. _23(this);
  178. _14(this);
  179. });
  180. };
  181. $.fn.validatebox.methods={options:function(jq){
  182. return $.data(jq[0],"validatebox").options;
  183. },destroy:function(jq){
  184. return jq.each(function(){
  185. _3(this);
  186. });
  187. },validate:function(jq){
  188. return jq.each(function(){
  189. _14(this);
  190. });
  191. },isValid:function(jq){
  192. return _14(jq[0]);
  193. },enableValidation:function(jq){
  194. return jq.each(function(){
  195. _23(this,false);
  196. });
  197. },disableValidation:function(jq){
  198. return jq.each(function(){
  199. _23(this,true);
  200. });
  201. }};
  202. $.fn.validatebox.parseOptions=function(_2a){
  203. var t=$(_2a);
  204. return $.extend({},$.parser.parseOptions(_2a,["validType","missingMessage","invalidMessage","tipPosition",{delay:"number",deltaX:"number"}]),{required:(t.attr("required")?true:undefined),novalidate:(t.attr("novalidate")!=undefined?true:undefined)});
  205. };
  206. $.fn.validatebox.defaults={required:false,validType:null,validParams:null,delay:200,missingMessage:"This field is required.",invalidMessage:null,tipPosition:"right",deltaX:0,novalidate:false,tipOptions:{showEvent:"none",hideEvent:"none",showDelay:0,hideDelay:0,zIndex:"",onShow:function(){
  207. $(this).tooltip("tip").css({color:"#000",borderColor:"#CC9933",backgroundColor:"#FFFFCC"});
  208. },onHide:function(){
  209. $(this).tooltip("destroy");
  210. }},rules:{email:{validator:function(_2b){
  211. return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(_2b);
  212. },message:"Please enter a valid email address."},url:{validator:function(_2c){
  213. return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(_2c);
  214. },message:"Please enter a valid URL."},length:{validator:function(_2d,_2e){
  215. var len=$.trim(_2d).length;
  216. return len>=_2e[0]&&len<=_2e[1];
  217. },message:"Please enter a value between {0} and {1}."},remote:{validator:function(_2f,_30){
  218. var _31={};
  219. _31[_30[1]]=_2f;
  220. var _32=$.ajax({url:_30[0],dataType:"json",data:_31,async:false,cache:false,type:"post"}).responseText;
  221. return _32=="true";
  222. },message:"Please fix this field."}}};
  223. })(jQuery);