Updated coding style

This commit is contained in:
Robert
2013-01-29 15:07:40 +02:00
committed by Jörn Zaefferer
parent b5cd04e327
commit 0d394a7418

66
jquery.validate.js vendored
View File

@@ -18,31 +18,31 @@ $.extend($.fn, {
// if nothing is selected, return nothing; can't chain anyway // if nothing is selected, return nothing; can't chain anyway
if ( !this.length ) { if ( !this.length ) {
if ( options && options.debug && window.console ) { if ( options && options.debug && window.console ) {
console.warn( "nothing selected, can't validate, returning nothing" ); console.warn( "Nothing selected, can't validate, returning nothing." );
} }
return; return;
} }
// check if a validator for this form was already created // check if a validator for this form was already created
var validator = $.data(this[0], 'validator'); var validator = $.data( this[0], "validator" );
if ( validator ) { if ( validator ) {
return validator; return validator;
} }
// Add novalidate tag if HTML5. // Add novalidate tag if HTML5.
this.attr('novalidate', 'novalidate'); this.attr( "novalidate", "novalidate" );
validator = new $.validator( options, this[0] ); validator = new $.validator( options, this[0] );
$.data(this[0], 'validator', validator); $.data( this[0], "validator", validator );
if ( validator.settings.onsubmit ) { if ( validator.settings.onsubmit ) {
this.validateDelegate( ":submit", "click", function(ev) { this.validateDelegate( ":submit", "click", function( event ) {
if ( validator.settings.submitHandler ) { if ( validator.settings.submitHandler ) {
validator.submitButton = ev.target; validator.submitButton = event.target;
} }
// allow suppressing validation by adding a cancel class to the submit button // allow suppressing validation by adding a cancel class to the submit button
if ( $(ev.target).hasClass('cancel') ) { if ( $(event.target).hasClass("cancel") ) {
validator.cancelSubmit = true; validator.cancelSubmit = true;
} }
}); });
@@ -92,7 +92,7 @@ $.extend($.fn, {
}, },
// http://docs.jquery.com/Plugins/Validation/valid // http://docs.jquery.com/Plugins/Validation/valid
valid: function() { valid: function() {
if ( $(this[0]).is('form')) { if ( $(this[0]).is("form")) {
return this.validate().form(); return this.validate().form();
} else { } else {
var valid = true; var valid = true;
@@ -118,7 +118,7 @@ $.extend($.fn, {
var element = this[0]; var element = this[0];
if ( command ) { if ( command ) {
var settings = $.data(element.form, 'validator').settings; var settings = $.data(element.form, "validator").settings;
var staticRules = settings.rules; var staticRules = settings.rules;
var existingRules = $.validator.staticRules(element); var existingRules = $.validator.staticRules(element);
switch(command) { switch(command) {
@@ -234,7 +234,7 @@ $.extend($.validator, {
} }
}, },
onkeyup: function( element, event ) { onkeyup: function( element, event ) {
if ( event.which === 9 && this.elementValue(element) === '' ) { if ( event.which === 9 && this.elementValue(element) === "" ) {
return; return;
} else if ( element.name in this.submitted || element === this.lastElement ) { } else if ( element.name in this.submitted || element === this.lastElement ) {
this.element(element); this.element(element);
@@ -251,14 +251,14 @@ $.extend($.validator, {
} }
}, },
highlight: function( element, errorClass, validClass ) { highlight: function( element, errorClass, validClass ) {
if (element.type === 'radio') { if ( element.type === "radio" ) {
this.findByName(element.name).addClass(errorClass).removeClass(validClass); this.findByName(element.name).addClass(errorClass).removeClass(validClass);
} else { } else {
$(element).addClass(errorClass).removeClass(validClass); $(element).addClass(errorClass).removeClass(validClass);
} }
}, },
unhighlight: function( element, errorClass, validClass ) { unhighlight: function( element, errorClass, validClass ) {
if (element.type === 'radio') { if ( element.type === "radio" ) {
this.findByName(element.name).removeClass(errorClass).addClass(validClass); this.findByName(element.name).removeClass(errorClass).addClass(validClass);
} else { } else {
$(element).removeClass(errorClass).addClass(validClass); $(element).removeClass(errorClass).addClass(validClass);
@@ -490,7 +490,7 @@ $.extend($.validator, {
}, },
errors: function() { errors: function() {
var errorClass = this.settings.errorClass.replace(' ', '.'); var errorClass = this.settings.errorClass.replace(" ", ".");
return $(this.settings.errorElement + "." + errorClass, this.errorContext); return $(this.settings.errorElement + "." + errorClass, this.errorContext);
}, },
@@ -514,14 +514,14 @@ $.extend($.validator, {
}, },
elementValue: function( element ) { elementValue: function( element ) {
var type = $(element).attr('type'), var type = $(element).attr("type"),
val = $(element).val(); val = $(element).val();
if ( type === 'radio' || type === 'checkbox' ) { if ( type === "radio" || type === "checkbox" ) {
return $('input[name="' + $(element).attr('name') + '"]:checked').val(); return $("input[name='" + $(element).attr("name") + "']:checked").val();
} }
if ( typeof val === 'string' ) { if ( typeof val === "string" ) {
return val.replace(/\r/g, ""); return val.replace(/\r/g, "");
} }
return val; return val;
@@ -560,7 +560,7 @@ $.extend($.validator, {
} }
} catch(e) { } catch(e) {
if ( this.settings.debug && window.console ) { if ( this.settings.debug && window.console ) {
console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e); console.log( "Exception occured when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
} }
throw e; throw e;
} }
@@ -577,7 +577,7 @@ $.extend($.validator, {
// return the custom message for the given element and validation method // return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute // specified in the element's HTML5 data attribute
customDataMessage: function( element, method ) { customDataMessage: function( element, method ) {
return $(element).data('msg-' + method.toLowerCase()) || (element.attributes && $(element).attr('data-msg-' + method.toLowerCase())); return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase()));
}, },
// return the custom message for the given element name and validation method // return the custom message for the given element name and validation method
@@ -613,7 +613,7 @@ $.extend($.validator, {
if ( typeof message === "function" ) { if ( typeof message === "function" ) {
message = message.call(this, rule.parameters, element); message = message.call(this, rule.parameters, element);
} else if (theregex.test(message)) { } else if (theregex.test(message)) {
message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters); message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
} }
this.errorList.push({ this.errorList.push({
message: message, message: message,
@@ -711,7 +711,7 @@ $.extend($.validator, {
errorsFor: function( element ) { errorsFor: function( element ) {
var name = this.idOrName(element); var name = this.idOrName(element);
return this.errors().filter(function() { return this.errors().filter(function() {
return $(this).attr('for') === name; return $(this).attr("for") === name;
}); });
}, },
@@ -732,16 +732,16 @@ $.extend($.validator, {
}, },
findByName: function( name ) { findByName: function( name ) {
return $(this.currentForm).find('[name="' + name + '"]'); return $(this.currentForm).find("[name='" + name + "']");
}, },
getLength: function( value, element ) { getLength: function( value, element ) {
switch( element.nodeName.toLowerCase() ) { switch( element.nodeName.toLowerCase() ) {
case 'select': case "select":
return $("option:selected", element).length; return $("option:selected", element).length;
case 'input': case "input":
if ( this.checkable( element) ) { if ( this.checkable( element) ) {
return this.findByName(element.name).filter(':checked').length; return this.findByName(element.name).filter(":checked").length;
} }
} }
return value.length; return value.length;
@@ -822,9 +822,9 @@ $.extend($.validator, {
classRules: function( element ) { classRules: function( element ) {
var rules = {}; var rules = {};
var classes = $(element).attr('class'); var classes = $(element).attr("class");
if ( classes ) { if ( classes ) {
$.each(classes.split(' '), function() { $.each(classes.split(" "), function() {
if ( this in $.validator.classRuleSettings ) { if ( this in $.validator.classRuleSettings ) {
$.extend(rules, $.validator.classRuleSettings[this]); $.extend(rules, $.validator.classRuleSettings[this]);
} }
@@ -841,7 +841,7 @@ $.extend($.validator, {
var value; var value;
// support for <input required> in both html5 and older browsers // support for <input required> in both html5 and older browsers
if (method === 'required') { if ( method === "required" ) {
value = $element.get(0).getAttribute(method); value = $element.get(0).getAttribute(method);
// Some browsers return an empty string for the required attribute // Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup // and non-HTML5 browsers might have required="" markup
@@ -873,7 +873,7 @@ $.extend($.validator, {
var method, value, var method, value,
rules = {}, $element = $(element); rules = {}, $element = $(element);
for (method in $.validator.methods) { for (method in $.validator.methods) {
value = $element.data('rule-' + method.toLowerCase()); value = $element.data("rule-" + method.toLowerCase());
if ( value !== undefined ) { if ( value !== undefined ) {
rules[method] = value; rules[method] = value;
} }
@@ -883,7 +883,7 @@ $.extend($.validator, {
staticRules: function( element ) { staticRules: function( element ) {
var rules = {}; var rules = {};
var validator = $.data(element.form, 'validator'); var validator = $.data(element.form, "validator");
if ( validator.settings.rules ) { if ( validator.settings.rules ) {
rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {}; rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
} }
@@ -922,17 +922,17 @@ $.extend($.validator, {
}); });
// clean number parameters // clean number parameters
$.each(['minlength', 'maxlength', 'min', 'max'], function() { $.each(["minlength", "maxlength", "min", "max"], function() {
if ( rules[this] ) { if ( rules[this] ) {
rules[this] = Number(rules[this]); rules[this] = Number(rules[this]);
} }
}); });
$.each(['rangelength', 'range'], function() { $.each(["rangelength", "range"], function() {
var parts; var parts;
if ( rules[this] ) { if ( rules[this] ) {
if ( $.isArray(rules[this]) ) { if ( $.isArray(rules[this]) ) {
rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
} else if (typeof rules[this] === 'string') { } else if ( typeof rules[this] === "string" ) {
parts = rules[this].split(/[\s,]+/); parts = rules[this].split(/[\s,]+/);
rules[this] = [Number(parts[0]), Number(parts[1])]; rules[this] = [Number(parts[0]), Number(parts[1])];
} }