Permalink
Browse files

Updated minified version

  • Loading branch information...
1 parent 3b6dc78 commit 4e8488428f1830d3cdd15dc95783938fb266161d @thedersen thedersen committed Jan 7, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 backbone.validation.min.js
View
4 backbone.validation.min.js
@@ -1,8 +1,8 @@
-// Backbone.Validation v0.2.0
+// Backbone.Validation v0.3.0
//
// Copyright (C)2011 Thomas Pedersen
// Distributed under MIT License
//
// Documentation and full license availabe at:
// http://github.com/thedersen/backbone.validation
-Backbone.Validation=(function(H,D,G){var B="id";var C=function(J){var K={};for(var I in J.validation){if(J.validation.hasOwnProperty(I)){K[I]=G;}}return K;};var F=function(L,I){var K=L.validation[I],J=[];if(D.isFunction(K)){return K;}else{if(D.isString(K)){return L[K];}else{for(var M in K){if(M!=="msg"&&K.hasOwnProperty(M)){J.push({fn:H.Validation.validators[M],val:K[M],msg:K.msg});}}return J;}}};var A=function(M,J,P){var K=F(M,J),L="",O,I;if(D.isFunction(K)){return K.call(M,P);}else{for(var N=0;N<K.length;N++){O=K[N];I=O.fn(P,J,O.val,M);if(I===false){return ;}else{if(I){L+=O.msg||I;}}}return L;}};var E=function(I){return I==="class"?".":"#";};return{version:"0.2.0",setDefaultSelector:function(I){B=I;},bind:function(K,N){N=N||{};var M=K.model,J=E(N.selector||B),L=N.valid||H.Validation.callbacks.valid,I=N.invalid||H.Validation.callbacks.invalid;M.validate=function(P){if(!P){return M.validate.call(M,D.extend(C(M),M.toJSON()));}var S=true,O;for(var R in P){if(R==="isValid"){return false;}O=A(M,R,P[R]);if(O){I(K,R,O,J+R);}else{L(K,R,J+R);}}if(O){M.set({isValid:false});}else{for(var Q in M.validation){if(D.isUndefined(P[Q])&&A(M,Q,M.get(Q))){S=false;break;}}M.set({isValid:S});}return O;};},unbind:function(I){I.model.validate=G;}};}(Backbone,_));Backbone.Validation.callbacks={valid:function(C,B,A){C.$(A).removeClass("invalid");C.$(A).removeAttr("data-error");},invalid:function(C,B,D,A){C.$(A).addClass("invalid");C.$(A).attr("data-error",D);}};Backbone.Validation.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([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])))$/,url:/^(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};Backbone.Validation.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be grater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"};Backbone.Validation.validators=(function(E,F,C){var A=String.prototype.trim?function(H){return H==null?"":String.prototype.trim.call(H);}:function(J){var I=/^\s+/,H=/\s+$/;return J==null?"":J.toString().replace(I,"").replace(H,"");};var G=function(){var H=Array.prototype.slice.call(arguments);var I=H.shift();return I.replace(/{(\d+)}/g,function(J,K){return typeof H[K]!="undefined"?H[K]:J;});};var B=function(H){return C.isNumber(H)||(C.isString(H)&&H.match(E.number));};var D=function(H){return !(C.isNull(H)||C.isUndefined(H)||(C.isString(H)&&A(H)===""));};return{required:function(K,H,L,I){var J=C.isFunction(L)?L.call(I):L;if(!J&&(!D(K))){return false;}if(J&&!D(K)){return G(F.required,H);}},acceptance:function(I,H){if(!C.isBoolean(I)||I===false){return G(F.acceptance,H);}},min:function(J,H,I){if(!B(J)||J<I){return G(F.min,H,I);}},max:function(I,H,J){if(!B(I)||I>J){return G(F.max,H,J);}},range:function(J,H,I){if(!B(J)||J<I[0]||J>I[1]){return G(F.range,H,I[0],I[1]);}},length:function(J,H,I){if(!D(J)||A(J).length!==I){return G(F.length,H,I);}},minLength:function(J,H,I){if(!D(J)||A(J).length<I){return G(F.minLength,H,I);}},maxLength:function(J,H,I){if(!D(J)||A(J).length>I){return G(F.maxLength,H,I);}},rangeLength:function(K,H,I){var J=A(K).length;if(!D(K)||J<I[0]||J>I[1]){return G(F.rangeLength,H,I[0],I[1]);}},oneOf:function(J,H,I){if(!C.include(I,J)){return G(F.oneOf,H,I.join(", "));}},equalTo:function(K,H,I,J){if(K!==J.get(I)){return G(F.equalTo,H,I);}},pattern:function(J,H,I){if(!D(J)||!J.toString().match(E[I]||I)){return G(F.pattern,H,I);}}};}(Backbone.Validation.patterns,Backbone.Validation.messages,_));
+Backbone.Validation=(function(G,D,F){var B="name";var C=function(I){var J={};for(var H in I.validation){if(I.validation.hasOwnProperty(H)){J[H]=F;}}return J;};var E=function(K,H){var J=K.validation[H],I=[];if(D.isFunction(J)){return J;}else{if(D.isString(J)){return K[J];}else{for(var L in J){if(L!=="msg"&&J.hasOwnProperty(L)){I.push({fn:G.Validation.validators[L],val:J[L],msg:J.msg});}}return I;}}};var A=function(L,I,O){var J=E(L,I),K="",N,H;if(D.isFunction(J)){return J.call(L,O,I);}else{for(var M=0;M<J.length;M++){N=J[M];H=N.fn(O,I,N.val,L);if(H===false){return ;}else{if(H){K+=N.msg||H;}}}return K;}};return{version:"0.3.0",setDefaultSelector:function(H){B=H;},bind:function(J,M){M=M||{};var L=J.model,I=M.selector||B,K=M.valid||G.Validation.callbacks.valid,H=M.invalid||G.Validation.callbacks.invalid,N=D.isUndefined(L.validation);L.validate=function(Q){if(!Q){return L.validate.call(L,D.extend(C(L),L.toJSON()));}var O=[];N=true;for(var S in Q){var P=A(L,S,Q[S]);if(P){O.push(P);N=false;H(J,S,P,I);}else{K(J,S,I);}}if(N){for(var R in L.validation){if(D.isUndefined(Q[R])&&A(L,R,L.get(R))){N=false;break;}}}L.trigger("validated",N);L.trigger("validated:"+(N?"valid":"invalid"));if(O.length===1){return O[0];}if(O.length>1){return O;}};L.isValid=function(){return N;};},unbind:function(H){H.model.validate=F;}};}(Backbone,_));Backbone.Validation.callbacks={valid:function(C,B,A){C.$("["+A+"~="+B+"]").removeClass("invalid").removeAttr("data-error");},invalid:function(C,B,D,A){C.$("["+A+"~="+B+"]").addClass("invalid").attr("data-error",D);}};Backbone.Validation.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([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])))$/,url:/^(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};Backbone.Validation.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be grater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"};Backbone.Validation.validators=(function(E,F,C){var A=String.prototype.trim?function(H){return H==null?"":String.prototype.trim.call(H);}:function(J){var I=/^\s+/,H=/\s+$/;return J==null?"":J.toString().replace(I,"").replace(H,"");};var G=function(){var H=Array.prototype.slice.call(arguments);var I=H.shift();return I.replace(/{(\d+)}/g,function(J,K){return typeof H[K]!="undefined"?H[K]:J;});};var B=function(H){return C.isNumber(H)||(C.isString(H)&&H.match(E.number));};var D=function(H){return !(C.isNull(H)||C.isUndefined(H)||(C.isString(H)&&A(H)===""));};return{required:function(K,H,L,I){var J=C.isFunction(L)?L.call(I):L;if(!J&&(!D(K))){return false;}if(J&&!D(K)){return G(F.required,H);}},acceptance:function(I,H){if(!C.isBoolean(I)||I===false){return G(F.acceptance,H);}},min:function(J,H,I){if(!B(J)||J<I){return G(F.min,H,I);}},max:function(I,H,J){if(!B(I)||I>J){return G(F.max,H,J);}},range:function(J,H,I){if(!B(J)||J<I[0]||J>I[1]){return G(F.range,H,I[0],I[1]);}},length:function(J,H,I){if(!D(J)||A(J).length!==I){return G(F.length,H,I);}},minLength:function(J,H,I){if(!D(J)||A(J).length<I){return G(F.minLength,H,I);}},maxLength:function(J,H,I){if(!D(J)||A(J).length>I){return G(F.maxLength,H,I);}},rangeLength:function(K,H,I){var J=A(K).length;if(!D(K)||J<I[0]||J>I[1]){return G(F.rangeLength,H,I[0],I[1]);}},oneOf:function(J,H,I){if(!C.include(I,J)){return G(F.oneOf,H,I.join(", "));}},equalTo:function(K,H,I,J){if(K!==J.get(I)){return G(F.equalTo,H,I);}},pattern:function(J,H,I){if(!D(J)||!J.toString().match(E[I]||I)){return G(F.pattern,H,I);}}};}(Backbone.Validation.patterns,Backbone.Validation.messages,_));

0 comments on commit 4e84884

Please sign in to comment.