Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Compress livevalidation_standalone.js

  • Loading branch information...
commit 27b790e29e6425ea34fb094402d13f972ade1079 1 parent 65c55ab
Pavel Kornilov authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  src/livevalidation_standalone.compressed.js
2  src/livevalidation_standalone.compressed.js
View
@@ -1,4 +1,4 @@
// LiveValidation 1.4 (standalone version)
// Copyright (c) 2007-2008 Alec Hill (www.livevalidation.com)
// LiveValidation is licensed under the terms of the MIT License
-var LiveValidation=function(b,a){this.initialize(b,a)};LiveValidation.VERSION="1.4 standalone";LiveValidation.TEXTAREA=1;LiveValidation.TEXT=2;LiveValidation.PASSWORD=3;LiveValidation.CHECKBOX=4;LiveValidation.SELECT=5;LiveValidation.FILE=6;LiveValidation.massValidate=function(c){for(var a=true,b=0,e=c.length;b<e;++b){var d=c[b].validate();if(a)a=d}return a};LiveValidation.prototype={validClass:"LV_valid",invalidClass:"LV_invalid",messageClass:"LV_validation_message",validFieldClass:"LV_valid_field",invalidFieldClass:"LV_invalid_field",initialize:function(d,f){var a=this,c=a;if(!d)throw new Error("LiveValidation::initialize - No element reference or element id has been provided!");a.element=d.nodeName?d:document.getElementById(d);if(!a.element)throw new Error("LiveValidation::initialize - No element with reference or id of '"+d+"' exists!");a.validations=[];a.elementType=a.getElementType();a.form=a.element.form;var b=f||{};a.validMessage=b.validMessage||"Thankyou!";var e=b.insertAfterWhatNode||a.element;a.insertAfterWhatNode=e.nodeType?e:document.getElementById(e);a.onlyOnBlur=b.onlyOnBlur||false;a.wait=b.wait||0;a.onlyOnSubmit=b.onlyOnSubmit||false;a.beforeValidation=b.beforeValidation||function(){};a.beforeValid=b.beforeValid||function(){};a.onValid=b.onValid||function(){this.insertMessage(this.createMessageSpan());this.addFieldClass()};a.afterValid=b.afterValid||function(){};a.beforeInvalid=b.beforeInvalid||function(){};a.onInvalid=b.onInvalid||function(){this.insertMessage(this.createMessageSpan());this.addFieldClass()};a.afterInvalid=b.afterInvalid||function(){};a.afterValidation=b.afterValidation||function(){};if(a.form){a.formObj=LiveValidationForm.getInstance(a.form);a.formObj.addField(a)}a.oldOnFocus=a.element.onfocus||function(){};a.oldOnBlur=a.element.onblur||function(){};a.oldOnClick=a.element.onclick||function(){};a.oldOnChange=a.element.onchange||function(){};a.oldOnKeyup=a.element.onkeyup||function(){};a.element.onfocus=function(a){c.doOnFocus(a);return c.oldOnFocus.call(this,a)};switch(a.elementType){case LiveValidation.CHECKBOX:a.element.onclick=function(a){c.validate(a);return c.oldOnClick.call(this,a)};case LiveValidation.SELECT:case LiveValidation.FILE:a.element.onchange=function(a){c.validate(a);return c.oldOnChange.call(this,a)};break;default:a.element.onkeyup=function(a){c.deferValidation(a);return c.oldOnKeyup.call(this,a)};a.element.onblur=function(a){c.doOnBlur(a);return c.oldOnBlur.call(this,a)}}},destroy:function(){var a=this;if(a.formObj){a.formObj.removeField(a);a.formObj.destroy()}a.element.onfocus=a.oldOnFocus;switch(a.elementType){case LiveValidation.CHECKBOX:a.element.onclick=a.oldOnClick;case LiveValidation.SELECT:case LiveValidation.FILE:a.element.onchange=a.oldOnChange;break;default:a.element.onkeyup=a.oldOnKeyup;a.element.onblur=a.oldOnBlur}a.validations=[];a.removeMessageAndFieldClass()},add:function(c,a){var b=this;b.validations.push({type:c,onlyOnBlur:a&&a.onlyOnBlur!==undefined?a.onlyOnBlur:b.onlyOnBlur,onlyOnSubmit:a&&a.onlyOnSubmit!==undefined?a.onlyOnSubmit:b.onlyOnSubmit,params:a||{}});return b},remove:function(f,e){var a=this;for(var d=[],b=0,g=a.validations.length;b<g;b++){var c=a.validations[b];c.type!=f&&c.params!=e&&d.push(c)}a.validations=d;return a},deferValidation:function(c){var a=this;a.wait>=300&&a.removeMessageAndFieldClass();var b=a;a.timeout&&clearTimeout(b.timeout);a.timeout=setTimeout(function(){b.validate(c)},b.wait)},doOnBlur:function(a){this.focused=false;this.validate(a)},doOnFocus:function(){this.focused=true;this.removeMessageAndFieldClass()},getElementType:function(){var b="INPUT",a=this.element.nodeName.toUpperCase(),c=this.element.type.toUpperCase();switch(true){case a=="TEXTAREA":return LiveValidation.TEXTAREA;case a==b&&c=="TEXT":return LiveValidation.TEXT;case a==b&&c=="PASSWORD":return LiveValidation.PASSWORD;case a==b&&c=="CHECKBOX":return LiveValidation.CHECKBOX;case a==b&&c=="FILE":return LiveValidation.FILE;case a=="SELECT":return LiveValidation.SELECT;case a==b:throw new Error("LiveValidation::getElementType - Cannot use LiveValidation on an "+c.toLowerCase()+" input!");default:throw new Error("LiveValidation::getElementType - Element must be an input, select, or textarea - "+a.toLowerCase()+" was given!");}},doValidations:function(c){var a=this;a.validationFailed=false;for(var b=0,d=c.length;b<d;++b){a.validationFailed=!a.validateElement(c[b].type,c[b].params);if(a.validationFailed)return false}a.message=a.validMessage;return true},validateElement:function(d,e){var b=true,a=this;switch(d){case Validate.Presence:case Validate.Confirmation:case Validate.Acceptance:a.displayMessageWhenEmpty=b;break;case Validate.Custom:if(e.displayMessageWhenEmpty)a.displayMessageWhenEmpty=b}var c=a.elementType==LiveValidation.SELECT?a.element.options[a.element.selectedIndex].value:a.element.value;if(d==Validate.Acceptance){if(a.elementType!=LiveValidation.CHECKBOX)throw new Error("LiveValidation::validateElement - Element to validate acceptance must be a checkbox!");c=a.element.checked}var f=b;try{d(c,e)}catch(g){if(g instanceof Validate.Error){if(c!==""||c===""&&a.displayMessageWhenEmpty){a.validationFailed=b;a.message=g.message.split("\n")[0];f=false}}else throw g;}finally{return f}},validate:function(d){var a=this;if(!a.element.disabled){var c=[],f=-1,b;while(b=a.validations[++f])(!d||d.type==="blur"&&!b.onlyOnSubmit||!b.onlyOnBlur&&!b.onlyOnSubmit)&&c.push(b);if(!c.length)return true;a.beforeValidation();var e=a.doValidations(c);if(e){a.beforeValid();a.onValid();a.afterValid();return true}else{a.beforeInvalid();a.onInvalid();a.afterInvalid();return false}a.afterValidation()}else return true},enable:function(){this.element.disabled=false;return this},disable:function(){this.element.disabled=true;this.removeMessageAndFieldClass();return this},createMessageSpan:function(){var a=document.createElement("span"),b=document.createTextNode(this.message);a.appendChild(b);return a},insertMessage:function(b){var a=this;a.removeMessage();if(!a.validationFailed&&!a.validMessage)return;if(a.displayMessageWhenEmpty&&(a.elementType==LiveValidation.CHECKBOX||a.element.value=="")||a.element.value!=""){var d=a.validationFailed?a.invalidClass:a.validClass;b.className+=" "+a.messageClass+" "+d;var c=a.insertAfterWhatNode.parentNode;if(a.insertAfterWhatNode.nextSibling)c.insertBefore(b,a.insertAfterWhatNode.nextSibling);else c.appendChild(b)}},addFieldClass:function(){var a=this;a.removeFieldClass();if(!a.validationFailed){if(a.displayMessageWhenEmpty||a.element.value!="")if(a.element.className.indexOf(a.validFieldClass)==-1)a.element.className+=" "+a.validFieldClass}else if(a.element.className.indexOf(a.invalidFieldClass)==-1)a.element.className+=" "+a.invalidFieldClass},removeMessage:function(){var b,a=this.insertAfterWhatNode;while(a.nextSibling){if(a.nextSibling.nodeType===1){b=a.nextSibling;break}a=a.nextSibling}b&&b.className.indexOf(this.messageClass)!=-1&&this.insertAfterWhatNode.parentNode.removeChild(b)},removeFieldClass:function(){var a=this,b=a.element.className;if(b.indexOf(a.invalidFieldClass)!=-1)a.element.className=b.split(a.invalidFieldClass).join("");if(b.indexOf(a.validFieldClass)!=-1)a.element.className=b.split(a.validFieldClass).join(" ")},removeMessageAndFieldClass:function(){this.removeMessage();this.removeFieldClass()}};var LiveValidationForm=function(a){this.initialize(a)};LiveValidationForm.instances={};LiveValidationForm.getInstance=function(b){if(!b)throw new Error("LiveValidationForm::getInstance - No element reference or element id has been provided!");var a=b.nodeName?b:document.getElementById(b),c=Math.random()*Math.random();if(!a.id)a.id="formId_"+c.toString().replace(/\./,"")+(new Date).valueOf();if(!LiveValidationForm.instances[a.id])LiveValidationForm.instances[a.id]=new LiveValidationForm(a);return LiveValidationForm.instances[a.id]};LiveValidationForm.prototype={beforeValidation:function(){},onValid:function(){},onInvalid:function(){},afterValidation:function(){},initialize:function(c){var b=this;b.name=c.id;b.element=c;b.fields=[];b.oldOnSubmit=b.element.onsubmit||function(){};var a=b;b.element.onsubmit=function(c){var b=false;a.beforeValidation(),a.valid=LiveValidation.massValidate(a.fields);a.valid?a.onValid():a.onInvalid();a.afterValidation();if(a.valid)b=a.oldOnSubmit.call(this,c||window.event)!==false;if(!b)return b}},addField:function(a){this.fields.push(a)},removeField:function(d){var a=this;for(var c=[],b=0,e=a.fields.length;b<e;b++)a.fields[b]!==d&&c.push(a.fields[b]);a.fields=c},destroy:function(b){var a=this;if(a.fields.length!=0&&!b)return false;a.element.onsubmit=a.oldOnSubmit;LiveValidationForm.instances[a.name]=null;return true}};var Validate={Presence:function(a,b){var b=b||{},c=b.failureMessage||"Can't be empty!";(a===""||a===null||a===undefined)&&Validate.fail(c);return true},Numericality:function(b,a){var c=null,l=b,b=Number(b),a=a||{},e=a.minimum||a.minimum==0?a.minimum:c,d=a.maximum||a.maximum==0?a.maximum:c,f=a.is||a.is==0?a.is:c,k=a.notANumberMessage||"Must be a number!",i=a.notAnIntegerMessage||"Must be an integer!",j=a.wrongNumberMessage||"Must be "+f+"!",h=a.tooLowMessage||"Must not be less than "+e+"!",g=a.tooHighMessage||"Must not be more than "+d+"!";!isFinite(b)&&Validate.fail(k);a.onlyInteger&&(/\.0+$|\.$/.test(String(l))||b!=parseInt(b))&&Validate.fail(i);switch(true){case f!==c:b!=Number(f)&&Validate.fail(j);break;case e!==c&&d!==c:Validate.Numericality(b,{tooLowMessage:h,minimum:e});Validate.Numericality(b,{tooHighMessage:g,maximum:d});break;case e!==c:b<Number(e)&&Validate.fail(h);break;case d!==c:b>Number(d)&&Validate.fail(g)}return true},Format:function(b,a){var b=String(b),a=a||{},c=a.failureMessage||"Not valid!",d=a.pattern||/./,e=a.negate||false;!e&&!d.test(b)&&Validate.fail(c);e&&d.test(b)&&Validate.fail(c);return true},Email:function(c,a){var a=a||{},b=a.failureMessage||"Must be a valid email address!";Validate.Format(c,{failureMessage:b,pattern:/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i});return true},Length:function(c,a){var f=" characters long!",b=null,c=String(c),a=a||{},e=a.minimum||a.minimum==0?a.minimum:b,d=a.maximum||a.maximum==0?a.maximum:b,g=a.is||a.is==0?a.is:b,j=a.wrongLengthMessage||"Must be "+g+f,h=a.tooShortMessage||"Must not be less than "+e+f,i=a.tooLongMessage||"Must not be more than "+d+f;switch(true){case g!==b:c.length!=Number(g)&&Validate.fail(j);break;case e!==b&&d!==b:Validate.Length(c,{tooShortMessage:h,minimum:e});Validate.Length(c,{tooLongMessage:i,maximum:d});break;case e!==b:c.length<Number(e)&&Validate.fail(h);break;case d!==b:c.length>Number(d)&&Validate.fail(i);break;default:throw new Error("Validate::Length - Length(s) to validate against must be provided!");}return true},Inclusion:function(b,a){var d=true,a=a||{},j=a.failureMessage||"Must be included in the list!",l=a.caseSensitive===false?false:d;if(a.allowNull&&b==null)return d;!a.allowNull&&b==null&&Validate.fail(j);var c=a.within||[];if(!l){for(var i=[],h=0,k=c.length;h<k;++h){var f=c[h];if(typeof f=="string")f=f.toLowerCase();i.push(f)}c=i;if(typeof b=="string")b=b.toLowerCase()}for(var e=false,g=0,k=c.length;g<k;++g){if(c[g]==b)e=d;if(a.partialMatch)if(b.indexOf(c[g])!=-1)e=d}(!a.negate&&!e||a.negate&&e)&&Validate.fail(j);return d},Exclusion:function(b,a){var a=a||{};a.failureMessage=a.failureMessage||"Must not be included in the list!";a.negate=true;Validate.Inclusion(b,a);return true},Confirmation:function(d,a){if(!a.match)throw new Error("Validate::Confirmation - Error validating confirmation: Id of element to match must be provided!");var a=a||{},c=a.failureMessage||"Does not match!",b=a.match.nodeName?a.match:document.getElementById(a.match);if(!b)throw new Error("Validate::Confirmation - There is no reference with name of, or element with id of '"+a.match+"'!");d!=b.value&&Validate.fail(c);return true},Acceptance:function(c,a){var a=a||{},b=a.failureMessage||"Must be accepted!";!c&&Validate.fail(b);return true},Custom:function(d,a){var a=a||{},b=a.against||function(){return true},e=a.args||{},c=a.failureMessage||"Not valid!";!b(d,e)&&Validate.fail(c);return true},now:function(a,d,c){if(!a)throw new Error("Validate::now - Validation function must be provided!");var b=true;try{a(d,c||{})}catch(e){if(e instanceof Validate.Error)b=false;else throw e;}finally{return b}},fail:function(a){throw new Validate.Error(a);},Error:function(a){this.message=a;this.name="ValidationError"}};
+var LiveValidation=function(b,a){this.initialize(b,a)};LiveValidation.VERSION="1.4 standalone";LiveValidation.TEXTAREA=1;LiveValidation.TEXT=2;LiveValidation.PASSWORD=3;LiveValidation.CHECKBOX=4;LiveValidation.SELECT=5;LiveValidation.FILE=6;LiveValidation.massValidate=function(c){for(var a=true,b=0,e=c.length;b<e;++b){var d=c[b].validate();if(a)a=d}return a};LiveValidation.prototype={validClass:"LV_valid",invalidClass:"LV_invalid",messageClass:"LV_validation_message",validFieldClass:"LV_valid_field",invalidFieldClass:"LV_invalid_field",initialize:function(d,f){var a=this,c=a;if(!d)throw new Error("LiveValidation::initialize - No element reference or element id has been provided!");a.element=d.nodeName?d:document.getElementById(d);if(!a.element)throw new Error("LiveValidation::initialize - No element with reference or id of '"+d+"' exists!");a.validations=[];a.elementType=a.getElementType();a.form=a.element.form;var b=f||{};a.validMessage=b.validMessage===undefined?"Thankyou!":b.validMessage;var e=b.insertAfterWhatNode||a.element;a.insertAfterWhatNode=e.nodeType?e:document.getElementById(e);a.onlyOnBlur=b.onlyOnBlur||false;a.wait=b.wait||0;a.onlyOnSubmit=b.onlyOnSubmit||false;a.beforeValidation=b.beforeValidation||function(){};a.beforeValid=b.beforeValid||function(){};a.onValid=b.onValid||function(){this.insertMessage(this.createMessageSpan());this.addFieldClass()};a.afterValid=b.afterValid||function(){};a.beforeInvalid=b.beforeInvalid||function(){};a.onInvalid=b.onInvalid||function(){this.insertMessage(this.createMessageSpan());this.addFieldClass()};a.afterInvalid=b.afterInvalid||function(){};a.afterValidation=b.afterValidation||function(){};if(a.form){a.formObj=LiveValidationForm.getInstance(a.form);a.formObj.addField(a)}a.oldOnFocus=a.element.onfocus||function(){};a.oldOnBlur=a.element.onblur||function(){};a.oldOnClick=a.element.onclick||function(){};a.oldOnChange=a.element.onchange||function(){};a.oldOnKeyup=a.element.onkeyup||function(){};a.element.onfocus=function(a){c.doOnFocus(a);return c.oldOnFocus.call(this,a)};switch(a.elementType){case LiveValidation.CHECKBOX:a.element.onclick=function(a){c.validate(a);return c.oldOnClick.call(this,a)};case LiveValidation.SELECT:case LiveValidation.FILE:a.element.onchange=function(a){c.validate(a);return c.oldOnChange.call(this,a)};break;default:a.element.onkeyup=function(a){c.deferValidation(a);return c.oldOnKeyup.call(this,a)};a.element.onblur=function(a){c.doOnBlur(a);return c.oldOnBlur.call(this,a)}}},destroy:function(){var a=this;if(a.formObj){a.formObj.removeField(a);a.formObj.destroy()}a.element.onfocus=a.oldOnFocus;switch(a.elementType){case LiveValidation.CHECKBOX:a.element.onclick=a.oldOnClick;case LiveValidation.SELECT:case LiveValidation.FILE:a.element.onchange=a.oldOnChange;break;default:a.element.onkeyup=a.oldOnKeyup;a.element.onblur=a.oldOnBlur}a.validations=[];a.removeMessageAndFieldClass()},add:function(c,a){var b=this;b.validations.push({type:c,onlyOnBlur:a&&a.onlyOnBlur!==undefined?a.onlyOnBlur:b.onlyOnBlur,onlyOnSubmit:a&&a.onlyOnSubmit!==undefined?a.onlyOnSubmit:b.onlyOnSubmit,params:a||{}});return b},remove:function(f,e){var a=this;for(var d=[],b=0,g=a.validations.length;b<g;b++){var c=a.validations[b];c.type!=f&&c.params!=e&&d.push(c)}a.validations=d;return a},deferValidation:function(c){var a=this;a.wait>=300&&a.removeMessageAndFieldClass();var b=a;a.timeout&&clearTimeout(b.timeout);a.timeout=setTimeout(function(){b.validate(c)},b.wait)},doOnBlur:function(a){this.focused=false;this.validate(a)},doOnFocus:function(){this.focused=true;this.removeMessageAndFieldClass()},getElementType:function(){var b="INPUT",a=this.element.nodeName.toUpperCase(),c=this.element.type.toUpperCase();switch(true){case a=="TEXTAREA":return LiveValidation.TEXTAREA;case a==b&&c=="TEXT":return LiveValidation.TEXT;case a==b&&c=="PASSWORD":return LiveValidation.PASSWORD;case a==b&&c=="CHECKBOX":return LiveValidation.CHECKBOX;case a==b&&c=="FILE":return LiveValidation.FILE;case a=="SELECT":return LiveValidation.SELECT;case a==b:throw new Error("LiveValidation::getElementType - Cannot use LiveValidation on an "+c.toLowerCase()+" input!");default:throw new Error("LiveValidation::getElementType - Element must be an input, select, or textarea - "+a.toLowerCase()+" was given!");}},doValidations:function(c){var a=this;a.validationFailed=false;for(var b=0,d=c.length;b<d;++b){a.validationFailed=!a.validateElement(c[b].type,c[b].params);if(a.validationFailed)return false}a.message=a.validMessage;return true},validateElement:function(d,e){var b=true,a=this;switch(d){case Validate.Presence:case Validate.Confirmation:case Validate.Acceptance:a.displayMessageWhenEmpty=b;break;case Validate.Custom:if(e.displayMessageWhenEmpty)a.displayMessageWhenEmpty=b}var c=a.elementType==LiveValidation.SELECT?a.element.options[a.element.selectedIndex].value:a.element.value;if(d==Validate.Acceptance){if(a.elementType!=LiveValidation.CHECKBOX)throw new Error("LiveValidation::validateElement - Element to validate acceptance must be a checkbox!");c=a.element.checked}var f=b;try{d(c,e)}catch(g){if(g instanceof Validate.Error){if(c!==""||c===""&&a.displayMessageWhenEmpty){a.validationFailed=b;a.message=g.message.split("\n")[0];f=false}}else throw g;}finally{return f}},validate:function(d){var a=this;if(!a.element.disabled){var c=[],f=-1,b;while(b=a.validations[++f])(!d||d.type==="blur"&&!b.onlyOnSubmit||!b.onlyOnBlur&&!b.onlyOnSubmit)&&c.push(b);if(!c.length)return true;a.beforeValidation();var e=a.doValidations(c);if(e){a.beforeValid();a.onValid();a.afterValid();return true}else{a.beforeInvalid();a.onInvalid();a.afterInvalid();return false}a.afterValidation()}else return true},enable:function(){this.element.disabled=false;return this},disable:function(){this.element.disabled=true;this.removeMessageAndFieldClass();return this},createMessageSpan:function(){var a=document.createElement("span"),b=document.createTextNode(this.message);a.appendChild(b);return a},insertMessage:function(b){var a=this;a.removeMessage();if(!a.validationFailed&&typeof a.validMessage!=="string")return;if(a.displayMessageWhenEmpty&&(a.elementType==LiveValidation.CHECKBOX||a.element.value=="")||a.element.value!=""){var d=a.validationFailed?a.invalidClass:a.validClass;b.className+=" "+a.messageClass+" "+d;var c=a.insertAfterWhatNode.parentNode;if(a.insertAfterWhatNode.nextSibling)c.insertBefore(b,a.insertAfterWhatNode.nextSibling);else c.appendChild(b)}},addFieldClass:function(){var a=this;a.removeFieldClass();if(!a.validationFailed){if(a.displayMessageWhenEmpty||a.element.value!="")if(a.element.className.indexOf(a.validFieldClass)==-1)a.element.className+=" "+a.validFieldClass}else if(a.element.className.indexOf(a.invalidFieldClass)==-1)a.element.className+=" "+a.invalidFieldClass},removeMessage:function(){var b,a=this.insertAfterWhatNode;while(a.nextSibling){if(a.nextSibling.nodeType===1){b=a.nextSibling;break}a=a.nextSibling}b&&b.className.indexOf(this.messageClass)!=-1&&this.insertAfterWhatNode.parentNode.removeChild(b)},removeFieldClass:function(){var a=this,b=a.element.className;if(b.indexOf(a.invalidFieldClass)!=-1)a.element.className=b.split(a.invalidFieldClass).join("");if(b.indexOf(a.validFieldClass)!=-1)a.element.className=b.split(a.validFieldClass).join(" ")},removeMessageAndFieldClass:function(){this.removeMessage();this.removeFieldClass()}};var LiveValidationForm=function(a){this.initialize(a)};LiveValidationForm.instances={};LiveValidationForm.getInstance=function(b){if(!b)throw new Error("LiveValidationForm::getInstance - No element reference or element id has been provided!");var a=b.nodeName?b:document.getElementById(b),c=Math.random()*Math.random();if(!a.id)a.id="formId_"+c.toString().replace(/\./,"")+(new Date).valueOf();if(!LiveValidationForm.instances[a.id])LiveValidationForm.instances[a.id]=new LiveValidationForm(a);return LiveValidationForm.instances[a.id]};LiveValidationForm.prototype={beforeValidation:function(){},onValid:function(){},onInvalid:function(){},afterValidation:function(){},initialize:function(c){var b=this;b.name=c.id;b.element=c;b.fields=[];b.oldOnSubmit=b.element.onsubmit||function(){};var a=b;b.element.onsubmit=function(c){var b=false;a.beforeValidation(),a.valid=LiveValidation.massValidate(a.fields);a.valid?a.onValid():a.onInvalid();a.afterValidation();if(a.valid)b=a.oldOnSubmit.call(this,c||window.event)!==false;if(!b)return b}},addField:function(a){this.fields.push(a)},removeField:function(d){var a=this;for(var c=[],b=0,e=a.fields.length;b<e;b++)a.fields[b]!==d&&c.push(a.fields[b]);a.fields=c},destroy:function(b){var a=this;if(a.fields.length!=0&&!b)return false;a.element.onsubmit=a.oldOnSubmit;LiveValidationForm.instances[a.name]=null;return true}};var Validate={Presence:function(a,b){var b=b||{},c=b.failureMessage||"Can't be empty!";(a===""||a===null||a===undefined)&&Validate.fail(c);return true},Numericality:function(b,a){var c=null,l=b,b=Number(b),a=a||{},e=a.minimum||a.minimum==0?a.minimum:c,d=a.maximum||a.maximum==0?a.maximum:c,f=a.is||a.is==0?a.is:c,k=a.notANumberMessage||"Must be a number!",i=a.notAnIntegerMessage||"Must be an integer!",j=a.wrongNumberMessage||"Must be "+f+"!",h=a.tooLowMessage||"Must not be less than "+e+"!",g=a.tooHighMessage||"Must not be more than "+d+"!";!isFinite(b)&&Validate.fail(k);a.onlyInteger&&(/\.0+$|\.$/.test(String(l))||b!=parseInt(b))&&Validate.fail(i);switch(true){case f!==c:b!=Number(f)&&Validate.fail(j);break;case e!==c&&d!==c:Validate.Numericality(b,{tooLowMessage:h,minimum:e});Validate.Numericality(b,{tooHighMessage:g,maximum:d});break;case e!==c:b<Number(e)&&Validate.fail(h);break;case d!==c:b>Number(d)&&Validate.fail(g)}return true},Format:function(b,a){var b=String(b),a=a||{},c=a.failureMessage||"Not valid!",d=a.pattern||/./,e=a.negate||false;!e&&!d.test(b)&&Validate.fail(c);e&&d.test(b)&&Validate.fail(c);return true},Email:function(c,a){var a=a||{},b=a.failureMessage||"Must be a valid email address!";Validate.Format(c,{failureMessage:b,pattern:/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i});return true},Length:function(c,a){var f=" characters long!",b=null,c=String(c),a=a||{},e=a.minimum||a.minimum==0?a.minimum:b,d=a.maximum||a.maximum==0?a.maximum:b,g=a.is||a.is==0?a.is:b,j=a.wrongLengthMessage||"Must be "+g+f,h=a.tooShortMessage||"Must not be less than "+e+f,i=a.tooLongMessage||"Must not be more than "+d+f;switch(true){case g!==b:c.length!=Number(g)&&Validate.fail(j);break;case e!==b&&d!==b:Validate.Length(c,{tooShortMessage:h,minimum:e});Validate.Length(c,{tooLongMessage:i,maximum:d});break;case e!==b:c.length<Number(e)&&Validate.fail(h);break;case d!==b:c.length>Number(d)&&Validate.fail(i);break;default:throw new Error("Validate::Length - Length(s) to validate against must be provided!");}return true},Inclusion:function(b,a){var d=true,a=a||{},j=a.failureMessage||"Must be included in the list!",l=a.caseSensitive===false?false:d;if(a.allowNull&&b==null)return d;!a.allowNull&&b==null&&Validate.fail(j);var c=a.within||[];if(!l){for(var i=[],h=0,k=c.length;h<k;++h){var f=c[h];if(typeof f=="string")f=f.toLowerCase();i.push(f)}c=i;if(typeof b=="string")b=b.toLowerCase()}for(var e=false,g=0,k=c.length;g<k;++g){if(c[g]==b)e=d;if(a.partialMatch)if(b.indexOf(c[g])!=-1)e=d}(!a.negate&&!e||a.negate&&e)&&Validate.fail(j);return d},Exclusion:function(b,a){var a=a||{};a.failureMessage=a.failureMessage||"Must not be included in the list!";a.negate=true;Validate.Inclusion(b,a);return true},Confirmation:function(d,a){if(!a.match)throw new Error("Validate::Confirmation - Error validating confirmation: Id of element to match must be provided!");var a=a||{},c=a.failureMessage||"Does not match!",b=a.match.nodeName?a.match:document.getElementById(a.match);if(!b)throw new Error("Validate::Confirmation - There is no reference with name of, or element with id of '"+a.match+"'!");d!=b.value&&Validate.fail(c);return true},Acceptance:function(c,a){var a=a||{},b=a.failureMessage||"Must be accepted!";!c&&Validate.fail(b);return true},Custom:function(d,a){var a=a||{},b=a.against||function(){return true},e=a.args||{},c=a.failureMessage||"Not valid!";!b(d,e)&&Validate.fail(c);return true},now:function(a,d,c){if(!a)throw new Error("Validate::now - Validation function must be provided!");var b=true;try{a(d,c||{})}catch(e){if(e instanceof Validate.Error)b=false;else throw e;}finally{return b}},fail:function(a){throw new Validate.Error(a);},Error:function(a){this.message=a;this.name="ValidationError"}};
Please sign in to comment.
Something went wrong with that request. Please try again.