Skip to content
Browse files

Updated minified version

  • Loading branch information...
1 parent 4f15f4c commit 2401783d11d402dd9a3fb10db41d0f4adf466c2a @thedersen thedersen committed Jan 21, 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.3.1
+// Backbone.Validation v0.4.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(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.1",setDefaultSelector:function(H){B=H;},bind:function(J,M){M=M||{};var L=J.model,O,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(R){if(!R){return L.validate.call(L,D.extend(C(L),L.toJSON()));}var P=[],T=[];N=true;for(var U in R){var Q=A(L,U,R[U]);if(Q){P.push(Q);T.push(U);N=false;H(J,U,Q,I);}else{K(J,U,I);}}if(N){for(var S in L.validation){if(D.isUndefined(R[S])&&A(L,S,L.get(S))){N=false;break;}}}D.defer(function(){L.trigger("validated",N,L,T);L.trigger("validated:"+(N?"valid":"invalid"),L,T);});if(P.length===1){return P[0];}if(P.length>1){return P;}};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|-|\.|_|~|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$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/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(a,b,c){var d={forceUpdate:!1,selector:"name"},e=function(a){return b.reduce(b.keys(a.validation),function(a,b){return a[b]=c,a},{})},f=function(c,d){var e=c.validation[d]||{};return b.isFunction(e)?e:b.isString(e)?c[e]:(b.isArray(e)||(e=[e]),b.reduce(e,function(c,d){return b.each(b.without(b.keys(d),"msg"),function(b){c.push({fn:a.Validation.validators[b],val:d[b],msg:d.msg})}),c},[]))},g=function(a,c,d){var e=f(a,c);return b.isFunction(e)?e.call(a,d,c):b.reduce(e,function(b,e){var f=e.fn(d,c,e.val,a);return f===!1||b===!1?!1:f&&!b?e.msg||f:b},"")};return{version:"0.4.0",configure:function(a){b.extend(d,a)},bind:function(f,h){h=h||{};var i=f.model,j=h.forceUpdate||d.forceUpdate,k=h.selector||d.selector,l=h.valid||a.Validation.callbacks.valid,m=h.invalid||a.Validation.callbacks.invalid,n=b.isUndefined(i.validation)?!0:c;i.validate=function(a){if(!a)return i.validate.call(i,b.extend(e(i),i.toJSON()));var c=[],d=[];n=!0;for(var h in a){var o=g(i,h,a[h]);o?(c.push(o),d.push(h),n=!1,m(f,h,o,k)):l(f,h,k)}if(n)for(var p in i.validation)if(b.isUndefined(a[p])&&g(i,p,i.get(p))){n=!1;break}b.defer(function(){i.trigger("validated",n,i,d),i.trigger("validated:"+(n?"valid":"invalid"),i,d)});if(j)return;if(c.length===1)return c[0];if(c.length>1)return c},i.isValid=function(a){return a&&this.validate(),n}},unbind:function(a){delete a.model.validate,delete a.model.isValid}}}(Backbone,_),Backbone.Validation.callbacks={valid:function(a,b,c){a.$("["+c+"~="+b+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(a,b,c,d){a.$("["+d+"~="+b+"]").addClass("invalid").attr("data-error",c)}},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])))$/i,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(a,b,c){var d=String.prototype.trim?function(a){return a===null?"":String.prototype.trim.call(a)}:function(a){var b=/^\s+/,c=/\s+$/;return a===null?"":a.toString().replace(b,"").replace(c,"")},e=function(){var a=Array.prototype.slice.call(arguments),b=a.shift();return b.replace(/\{(\d+)\}/g,function(b,c){return typeof a[c]!="undefined"?a[c]:b})},f=function(b){return c.isNumber(b)||c.isString(b)&&b.match(a.number)},g=function(a){return!(c.isNull(a)||c.isUndefined(a)||c.isString(a)&&d(a)==="")};return{fn:function(a,b,d,e){return c.isString(d)&&(d=e[d]),d.call(e,a,b)},required:function(a,d,f,h){var i=c.isFunction(f)?f.call(h):f;if(!i&&!g(a))return!1;if(i&&!g(a))return e(b.required,d)},acceptance:function(a,d){if(a!=="true"&&(!c.isBoolean(a)||a===!1))return e(b.acceptance,d)},min:function(a,c,d){if(!f(a)||a<d)return e(b.min,c,d)},max:function(a,c,d){if(!f(a)||a>d)return e(b.max,c,d)},range:function(a,c,d){if(!f(a)||a<d[0]||a>d[1])return e(b.range,c,d[0],d[1])},length:function(a,c,f){if(!g(a)||d(a).length!==f)return e(b.length,c,f)},minLength:function(a,c,f){if(!g(a)||d(a).length<f)return e(b.minLength,c,f)},maxLength:function(a,c,f){if(!g(a)||d(a).length>f)return e(b.maxLength,c,f)},rangeLength:function(a,c,f){if(!g(a)||d(a).length<f[0]||d(a).length>f[1])return e(b.rangeLength,c,f[0],f[1])},oneOf:function(a,d,f){if(!c.include(f,a))return e(b.oneOf,d,f.join(", "))},equalTo:function(a,c,d,f){if(a!==f.get(d))return e(b.equalTo,c,d)},pattern:function(c,d,f){if(!g(c)||!c.toString().match(a[f]||f))return e(b.pattern,d,f)}}}(Backbone.Validation.patterns,Backbone.Validation.messages,_);

0 comments on commit 2401783

Please sign in to comment.
Something went wrong with that request. Please try again.