Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated the minified version

  • Loading branch information...
commit ac70f1b21daf83f44122aecaa55ac5ca4a543609 1 parent 19c18e7
@thedersen authored
Showing with 3 additions and 3 deletions.
  1. +3 −3 backbone.validation.min.js
View
6 backbone.validation.min.js
@@ -1,8 +1,8 @@
-// Backbone.Validation v0.5.2
+// Backbone.Validation v0.6.0
//
// Copyright (C)2011-2012 Thomas Pedersen
// Distributed under MIT License
//
// Documentation and full license available at:
-// http://thedersen.github.com/backbone.validation
-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,e){var f=d[e]||{};return b.isFunction(f)?f:b.isString(f)?c[f]:(b.isArray(f)||(f=[f]),b.reduce(f,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){return b.isObject(a)&&b.isObject(a[c])&&b.isObject(a[c].validation)},h=function(c,d,e,g,h){var i=f(c,d,e);return b.isFunction(i)?i.call(c,g,e,h):b.reduce(i,function(b,d){var f=d.fn.call(a.Validation.validators,g,e,d.val,c,h);return f===!1||b===!1?!1:f&&!b?d.msg||f:b},"")},i=function(a,c,d,e,f,j){if(!d)return!1;var k=!0,l;for(var m in c){l=h(a,c,m,a.get(m),e);if(b.isUndefined(d[m])&&l){k=!1;break}!l&&f&&j.valid(f,m,j.selector),l!==!1&&g(c,m)&&(k=i(a,c[m].validation,d[m],e))}return k},j=function(a,c,d,e,f,k){k=k||"";var l,m,n,o=[],p=[],q=!0,r=b.extend(c.toJSON(),e);for(n in e)m=h(c,d,n,e[n],r),m?(o.push(m),p.push(k+n),q=!1,a&&f.invalid(a,n,m,f.selector)):a&&f.valid(a,n,f.selector),m!==!1&&g(d,n)&&(l=j(a,c,d[n].validation,e[n],f,k+n+"."),Array.prototype.push.apply(o,l.errorMessages),Array.prototype.push.apply(p,l.invalidAttrs),q=q&&l.isValid);return q&&(q=i(c,d,e,r,a,f)),{errorMessages:o,invalidAttrs:p,isValid:q}},k=function(a,c){return{isValid:function(a){if(b.isString(a))return!h(this,this.validation,a,this.get(a),this.toJSON());if(b.isArray(a)){for(var c=0;c<a.length;c++)if(h(this,this.validation,a[c],this.get(a[c]),this.toJSON()))return!1;return!0}return a===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(d,f){var g=this,h=b.extend({},c,f);if(!d)return g.validate.call(g,b.extend(e(g),g.toJSON()));var i=j(a,g,g.validation,d,h);g._isValid=i.isValid,b.defer(function(){g.trigger("validated",g._isValid,g,i.invalidAttrs),g.trigger("validated:"+(g._isValid?"valid":"invalid"),g,i.invalidAttrs)});if(!h.forceUpdate&&i.errorMessages.length>0)return i.errorMessages}}},l=function(a,c,d){b.extend(c,k(a,d))},m=function(a){delete a.validate,delete a.isValid},n=function(a){l(this.view,a,this.options)},o=function(a){m(a)};return{version:"0.5.2",configure:function(a){b.extend(d,a)},bind:function(c,e){var f=c.model,g=c.collection,h=b.extend({},d,a.Validation.callbacks,e);f&&l(c,f,h),g&&(g.each(function(a){l(c,a,h)}),g.bind("add",n,{view:c,options:h}),g.bind("remove",o))},unbind:function(a){var b=a.model,c=a.collection;b&&m(a.model),c&&(c.each(function(a){m(a)}),c.unbind("add",n),c.unbind("remove",o))},mixin:k(null,d)}}(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}",object:"{0} must be an object"},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,f){return c.isString(d)&&(d=e[d]),d.call(e,a,b,f)},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,g){if(a!==g[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)},validation:function(a,d,f){if(!c.isObject(a))return e(b.object,d)}}}(Backbone.Validation.patterns,Backbone.Validation.messages,_);
+// http://thedersen.com/projects/backbone-validation
+(function(e,t){var n={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",valid:Function.prototype,invalid:Function.prototype};e.Validation=function(){var e=function(e){return t.reduce(t.keys(e.validation||{}),function(e,t){return e[t]=void 0,e},{})},i=function(e,n){var r=e.validation?e.validation[n]||{}:{};return t.isFunction(r)?r:t.isString(r)?e[r]:(t.isArray(r)||(r=[r]),t.reduce(r,function(e,n){return t.each(t.without(t.keys(n),"msg"),function(t){e.push({fn:u[t],val:n[t],msg:n.msg})}),e},[]))},s=function(e,n,r,s){var o=i(e,n);return t.isFunction(o)?o.call(e,r,n,s):t.reduce(o,function(t,i){var o=i.fn.call(u,r,n,i.val,e,s);return o===!1||t===!1?!1:o&&!t?i.msg||o:t},"")},o=function(e,n){var r,i,o,u={},a=!0,f=t.clone(n);for(o in n)i=s(e,o,n[o],f),i&&(u[o]=i,a=!1);return{invalidAttrs:u,isValid:a}},a=function(n,r){return{preValidate:function(e,n){return s(this,e,n,t.extend({},this.attributes))},isValid:function(e){if(t.isString(e))return!s(this,e,this.get(e),t.extend({},this.attributes));if(t.isArray(e)){for(var n=0;n<e.length;n++)if(s(this,e[n],this.get(e[n]),t.extend({},this.attributes)))return!1;return!0}return e===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(i,s){var u=this,a=!i,f=t.extend({},r,s),l=t.extend(e(u),u.attributes,i),c=i||l,h=o(u,l);u._isValid=h.isValid;for(var p in l){var d=h.invalidAttrs.hasOwnProperty(p),v=c.hasOwnProperty(p);d&&(v||a)&&f.invalid(n,p,h.invalidAttrs[p],f.selector),d||f.valid(n,p,f.selector)}t.defer(function(){u.trigger("validated",u._isValid,u,h.invalidAttrs),u.trigger("validated:"+(u._isValid?"valid":"invalid"),u,h.invalidAttrs)});if(!f.forceUpdate&&t.intersection(t.keys(h.invalidAttrs),t.keys(c)).length>0)return h.invalidAttrs}}},f=function(e,n,r){t.extend(n,a(e,r))},l=function(e){delete e.validate,delete e.preValidate,delete e.isValid},c=function(e){f(this.view,e,this.options)},h=function(e){l(e)};return{version:"0.6.0",configure:function(e){t.extend(n,e)},bind:function(e,i){var s=e.model,o=e.collection;i=t.extend({},n,r,i),s&&f(e,s,i),o&&(o.each(function(t){f(e,t,i)}),o.bind("add",c,{view:e,options:i}),o.bind("remove",h))},unbind:function(e){var t=e.model,n=e.collection;t&&l(e.model),n&&(n.each(function(e){l(e)}),n.unbind("add",c),n.unbind("remove",h))},mixin:a(null,n)}}();var r=e.Validation.callbacks={valid:function(e,t,n){e.$("["+n+"~="+t+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(e,t,n,r){e.$("["+r+"~="+t+"]").addClass("invalid").attr("data-error",n)}},i=e.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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\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},s=e.Validation.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater 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}"},o=e.Validation.labelFormatters={none:function(e){return e},sentenceCase:function(e){return e.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return t===0?e.toUpperCase():" "+e.toLowerCase()}).replace("_"," ")},label:function(e,t){return t.labels[e]||o.sentenceCase(e,t)}},u=e.Validation.validators=function(){var e=String.prototype.trim?function(e){return e===null?"":String.prototype.trim.call(e)}:function(e){var t=/^\s+/,n=/\s+$/;return e===null?"":e.toString().replace(t,"").replace(n,"")},r=function(e,t){return o[n.labelFormatter](e,t)},u=function(){var e=Array.prototype.slice.call(arguments),t=e.shift();return t.replace(/\{(\d+)\}/g,function(t,n){return typeof e[n]!="undefined"?e[n]:t})},a=function(e){return t.isNumber(e)||t.isString(e)&&e.match(i.number)},f=function(n){return!(t.isNull(n)||t.isUndefined(n)||t.isString(n)&&e(n)==="")};return{fn:function(e,n,r,i,s){return t.isString(r)&&(r=i[r]),r.call(i,e,n,s)},required:function(e,n,i,o,a){var l=t.isFunction(i)?i.call(o,e,n,a):i;if(!l&&!f(e))return!1;if(l&&!f(e))return u(s.required,r(n,o))},acceptance:function(e,n,i,o){if(e!=="true"&&(!t.isBoolean(e)||e===!1))return u(s.acceptance,r(n,o))},min:function(e,t,n,i){if(!a(e)||e<n)return u(s.min,r(t,i),n)},max:function(e,t,n,i){if(!a(e)||e>n)return u(s.max,r(t,i),n)},range:function(e,t,n,i){if(!a(e)||e<n[0]||e>n[1])return u(s.range,r(t,i),n[0],n[1])},length:function(t,n,i,o){if(!f(t)||e(t).length!==i)return u(s.length,r(n,o),i)},minLength:function(t,n,i,o){if(!f(t)||e(t).length<i)return u(s.minLength,r(n,o),i)},maxLength:function(t,n,i,o){if(!f(t)||e(t).length>i)return u(s.maxLength,r(n,o),i)},rangeLength:function(t,n,i,o){if(!f(t)||e(t).length<i[0]||e(t).length>i[1])return u(s.rangeLength,r(n,o),i[0],i[1])},oneOf:function(e,n,i,o){if(!t.include(i,e))return u(s.oneOf,r(n,o),i.join(", "))},equalTo:function(e,t,n,i,o){if(e!==o[n])return u(s.equalTo,r(t,i),r(n,i))},pattern:function(e,t,n,o){if(!f(e)||!e.toString().match(i[n]||n))return u(s.pattern,r(t,o),n)}}}()})(Backbone,_);
Please sign in to comment.
Something went wrong with that request. Please try again.