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

314
jquery.validate.js vendored
View File

@@ -16,33 +16,33 @@ $.extend($.fn, {
validate: function( options ) { validate: function( options ) {
// 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;
} }
}); });
@@ -56,12 +56,12 @@ $.extend($.fn, {
function handle() { function handle() {
var hidden; var hidden;
if ( validator.settings.submitHandler ) { if ( validator.settings.submitHandler ) {
if (validator.submitButton) { if ( validator.submitButton ) {
// insert a hidden input as a replacement for the missing submit button // insert a hidden input as a replacement for the missing submit button
hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm); hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
} }
validator.settings.submitHandler.call( validator, validator.currentForm, event ); validator.settings.submitHandler.call( validator, validator.currentForm, event );
if (validator.submitButton) { if ( validator.submitButton ) {
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced // and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden.remove(); hidden.remove();
} }
@@ -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;
@@ -104,38 +104,38 @@ $.extend($.fn, {
} }
}, },
// attributes: space seperated list of attributes to retrieve and remove // attributes: space seperated list of attributes to retrieve and remove
removeAttrs: function(attributes) { removeAttrs: function( attributes ) {
var result = {}, var result = {},
$element = this; $element = this;
$.each(attributes.split(/\s/), function(index, value) { $.each(attributes.split(/\s/), function( index, value ) {
result[value] = $element.attr(value); result[value] = $element.attr(value);
$element.removeAttr(value); $element.removeAttr(value);
}); });
return result; return result;
}, },
// http://docs.jquery.com/Plugins/Validation/rules // http://docs.jquery.com/Plugins/Validation/rules
rules: function(command, argument) { rules: function( command, argument ) {
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) {
case "add": case "add":
$.extend(existingRules, $.validator.normalizeRule(argument)); $.extend(existingRules, $.validator.normalizeRule(argument));
staticRules[element.name] = existingRules; staticRules[element.name] = existingRules;
if (argument.messages) { if ( argument.messages ) {
settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages ); settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
} }
break; break;
case "remove": case "remove":
if (!argument) { if ( !argument ) {
delete staticRules[element.name]; delete staticRules[element.name];
return existingRules; return existingRules;
} }
var filtered = {}; var filtered = {};
$.each(argument.split(/\s/), function(index, method) { $.each(argument.split(/\s/), function( index, method ) {
filtered[method] = existingRules[method]; filtered[method] = existingRules[method];
delete existingRules[method]; delete existingRules[method];
}); });
@@ -153,7 +153,7 @@ $.extend($.fn, {
), element); ), element);
// make sure required is at front // make sure required is at front
if (data.required) { if ( data.required ) {
var param = data.required; var param = data.required;
delete data.required; delete data.required;
data = $.extend({required: param}, data); data = $.extend({required: param}, data);
@@ -166,11 +166,11 @@ $.extend($.fn, {
// Custom selectors // Custom selectors
$.extend($.expr[":"], { $.extend($.expr[":"], {
// http://docs.jquery.com/Plugins/Validation/blank // http://docs.jquery.com/Plugins/Validation/blank
blank: function(a) {return !$.trim("" + a.value);}, blank: function( a ) { return !$.trim("" + a.value); },
// http://docs.jquery.com/Plugins/Validation/filled // http://docs.jquery.com/Plugins/Validation/filled
filled: function(a) {return !!$.trim("" + a.value);}, filled: function( a ) { return !!$.trim("" + a.value); },
// http://docs.jquery.com/Plugins/Validation/unchecked // http://docs.jquery.com/Plugins/Validation/unchecked
unchecked: function(a) {return !a.checked;} unchecked: function( a ) { return !a.checked; }
}); });
// constructor for validator // constructor for validator
@@ -180,7 +180,7 @@ $.validator = function( options, form ) {
this.init(); this.init();
}; };
$.validator.format = function(source, params) { $.validator.format = function( source, params ) {
if ( arguments.length === 1 ) { if ( arguments.length === 1 ) {
return function() { return function() {
var args = $.makeArray(arguments); var args = $.makeArray(arguments);
@@ -194,8 +194,8 @@ $.validator.format = function(source, params) {
if ( params.constructor !== Array ) { if ( params.constructor !== Array ) {
params = [ params ]; params = [ params ];
} }
$.each(params, function(i, n) { $.each(params, function( i, n ) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() { source = source.replace( new RegExp("\\{" + i + "\\}", "g"), function() {
return n; return n;
}); });
}); });
@@ -212,12 +212,12 @@ $.extend($.validator, {
validClass: "valid", validClass: "valid",
errorElement: "label", errorElement: "label",
focusInvalid: true, focusInvalid: true,
errorContainer: $( [] ), errorContainer: $([]),
errorLabelContainer: $( [] ), errorLabelContainer: $([]),
onsubmit: true, onsubmit: true,
ignore: ":hidden", ignore: ":hidden",
ignoreTitle: false, ignoreTitle: false,
onfocusin: function(element, event) { onfocusin: function( element, event ) {
this.lastActive = element; this.lastActive = element;
// hide error label and remove error class on focus if enabled // hide error label and remove error class on focus if enabled
@@ -228,37 +228,37 @@ $.extend($.validator, {
this.addWrapper(this.errorsFor(element)).hide(); this.addWrapper(this.errorsFor(element)).hide();
} }
}, },
onfocusout: function(element, event) { onfocusout: function( element, event ) {
if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
this.element(element); this.element(element);
} }
}, },
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);
} }
}, },
onclick: function(element, event) { onclick: function( element, event ) {
// click on selects, radiobuttons and checkboxes // click on selects, radiobuttons and checkboxes
if ( element.name in this.submitted ) { if ( element.name in this.submitted ) {
this.element(element); this.element(element);
} }
// or option elements, check parent select in that case // or option elements, check parent select in that case
else if (element.parentNode.name in this.submitted) { else if ( element.parentNode.name in this.submitted ) {
this.element(element.parentNode); this.element(element.parentNode);
} }
}, },
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);
@@ -267,7 +267,7 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
setDefaults: function(settings) { setDefaults: function( settings ) {
$.extend( $.validator.defaults, settings ); $.extend( $.validator.defaults, settings );
}, },
@@ -306,23 +306,23 @@ $.extend($.validator, {
this.reset(); this.reset();
var groups = (this.groups = {}); var groups = (this.groups = {});
$.each(this.settings.groups, function(key, value) { $.each(this.settings.groups, function( key, value ) {
if (typeof value === "string") { if ( typeof value === "string" ) {
value = value.split(/\s/); value = value.split(/\s/);
} }
$.each(value, function(index, name) { $.each(value, function( index, name ) {
groups[name] = key; groups[name] = key;
}); });
}); });
var rules = this.settings.rules; var rules = this.settings.rules;
$.each(rules, function(key, value) { $.each(rules, function( key, value ) {
rules[key] = $.validator.normalizeRule(value); rules[key] = $.validator.normalizeRule(value);
}); });
function delegate(event) { function delegate(event) {
var validator = $.data(this[0].form, "validator"), var validator = $.data(this[0].form, "validator"),
eventType = "on" + event.type.replace(/^validate/, ""); eventType = "on" + event.type.replace(/^validate/, "");
if (validator.settings[eventType]) { if ( validator.settings[eventType] ) {
validator.settings[eventType].call(validator, this[0], event); validator.settings[eventType].call(validator, this[0], event);
} }
} }
@@ -335,7 +335,7 @@ $.extend($.validator, {
"focusin focusout keyup", delegate) "focusin focusout keyup", delegate)
.validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate); .validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
if (this.settings.invalidHandler) { if ( this.settings.invalidHandler ) {
$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler); $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
} }
}, },
@@ -345,7 +345,7 @@ $.extend($.validator, {
this.checkForm(); this.checkForm();
$.extend(this.submitted, this.errorMap); $.extend(this.submitted, this.errorMap);
this.invalid = $.extend({}, this.errorMap); this.invalid = $.extend({}, this.errorMap);
if (!this.valid()) { if ( !this.valid() ) {
$(this.currentForm).triggerHandler("invalid-form", [this]); $(this.currentForm).triggerHandler("invalid-form", [this]);
} }
this.showErrors(); this.showErrors();
@@ -367,7 +367,7 @@ $.extend($.validator, {
this.prepareElement( element ); this.prepareElement( element );
this.currentElements = $(element); this.currentElements = $(element);
var result = this.check( element ) !== false; var result = this.check( element ) !== false;
if (result) { if ( result ) {
delete this.invalid[element.name]; delete this.invalid[element.name];
} else { } else {
this.invalid[element.name] = true; this.invalid[element.name] = true;
@@ -381,8 +381,8 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
showErrors: function(errors) { showErrors: function( errors ) {
if(errors) { if ( errors ) {
// add items to error list and map // add items to error list and map
$.extend( this.errorMap, errors ); $.extend( this.errorMap, errors );
this.errorList = []; this.errorList = [];
@@ -393,11 +393,11 @@ $.extend($.validator, {
}); });
} }
// remove items from success list // remove items from success list
this.successList = $.grep( this.successList, function(element) { this.successList = $.grep( this.successList, function( element ) {
return !(element.name in errors); return !(element.name in errors);
}); });
} }
if (this.settings.showErrors) { if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList ); this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else { } else {
this.defaultShowErrors(); this.defaultShowErrors();
@@ -407,7 +407,7 @@ $.extend($.validator, {
// http://docs.jquery.com/Plugins/Validation/Validator/resetForm // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
resetForm: function() { resetForm: function() {
if ( $.fn.resetForm ) { if ( $.fn.resetForm ) {
$( this.currentForm ).resetForm(); $(this.currentForm).resetForm();
} }
this.submitted = {}; this.submitted = {};
this.lastElement = null; this.lastElement = null;
@@ -441,7 +441,7 @@ $.extend($.validator, {
}, },
focusInvalid: function() { focusInvalid: function() {
if( this.settings.focusInvalid ) { if ( this.settings.focusInvalid ) {
try { try {
$(this.findLastActive() || this.errorList.length && this.errorList[0].element || []) $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
.filter(":visible") .filter(":visible")
@@ -456,7 +456,7 @@ $.extend($.validator, {
findLastActive: function() { findLastActive: function() {
var lastActive = this.lastActive; var lastActive = this.lastActive;
return lastActive && $.grep(this.errorList, function(n) { return lastActive && $.grep(this.errorList, function( n ) {
return n.element.name === lastActive.name; return n.element.name === lastActive.name;
}).length === 1 && lastActive; }).length === 1 && lastActive;
}, },
@@ -486,12 +486,12 @@ $.extend($.validator, {
}, },
clean: function( selector ) { clean: function( selector ) {
return $( selector )[0]; return $(selector)[0];
}, },
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);
}, },
reset: function() { reset: function() {
@@ -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;
@@ -554,18 +554,18 @@ $.extend($.validator, {
return; return;
} }
if( !result ) { if ( !result ) {
this.formatAndAdd( element, rule ); this.formatAndAdd( element, rule );
return false; return false;
} }
} 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;
} }
} }
if (dependencyMismatch) { if ( dependencyMismatch ) {
return; return;
} }
if ( this.objectLength(rules) ) { if ( this.objectLength(rules) ) {
@@ -576,8 +576,8 @@ $.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
@@ -589,14 +589,14 @@ $.extend($.validator, {
// return the first defined argument, allowing empty strings // return the first defined argument, allowing empty strings
findDefined: function() { findDefined: function() {
for(var i = 0; i < arguments.length; i++) { for(var i = 0; i < arguments.length; i++) {
if (arguments[i] !== undefined) { if ( arguments[i] !== undefined ) {
return arguments[i]; return arguments[i];
} }
} }
return undefined; return undefined;
}, },
defaultMessage: function( element, method) { defaultMessage: function( element, method ) {
return this.findDefined( return this.findDefined(
this.customMessage( element.name, method ), this.customMessage( element.name, method ),
this.customDataMessage( element, method ), this.customDataMessage( element, 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,
@@ -624,7 +624,7 @@ $.extend($.validator, {
this.submitted[element.name] = message; this.submitted[element.name] = message;
}, },
addWrapper: function(toToggle) { addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) { if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
} }
@@ -640,15 +640,15 @@ $.extend($.validator, {
} }
this.showLabel( error.element, error.message ); this.showLabel( error.element, error.message );
} }
if( this.errorList.length ) { if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers ); this.toShow = this.toShow.add( this.containers );
} }
if (this.settings.success) { if ( this.settings.success ) {
for ( i = 0; this.successList[i]; i++ ) { for ( i = 0; this.successList[i]; i++ ) {
this.showLabel( this.successList[i] ); this.showLabel( this.successList[i] );
} }
} }
if (this.settings.unhighlight) { if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[i]; i++ ) { for ( i = 0, elements = this.validElements(); elements[i]; i++ ) {
this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass ); this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
} }
@@ -668,7 +668,7 @@ $.extend($.validator, {
}); });
}, },
showLabel: function(element, message) { showLabel: function( element, message ) {
var label = this.errorsFor( element ); var label = this.errorsFor( element );
if ( label.length ) { if ( label.length ) {
// refresh error/success class // refresh error/success class
@@ -708,20 +708,20 @@ $.extend($.validator, {
this.toShow = this.toShow.add(label); this.toShow = this.toShow.add(label);
}, },
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;
}); });
}, },
idOrName: function(element) { idOrName: function( element ) {
return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
}, },
validationTargetFor: function(element) { validationTargetFor: function( element ) {
// if radio/checkbox, validate first element in group instead // if radio/checkbox, validate first element in group instead
if (this.checkable(element)) { if ( this.checkable(element) ) {
element = this.findByName( element.name ).not(this.settings.ignore)[0]; element = this.findByName( element.name ).not(this.settings.ignore)[0];
} }
return element; return element;
@@ -732,53 +732,53 @@ $.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;
}, },
depend: function(param, element) { depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true; return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
}, },
dependTypes: { dependTypes: {
"boolean": function(param, element) { "boolean": function( param, element ) {
return param; return param;
}, },
"string": function(param, element) { "string": function( param, element ) {
return !!$(param, element.form).length; return !!$(param, element.form).length;
}, },
"function": function(param, element) { "function": function( param, element ) {
return param(element); return param(element);
} }
}, },
optional: function(element) { optional: function( element ) {
var val = this.elementValue(element); var val = this.elementValue(element);
return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch"; return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch";
}, },
startRequest: function(element) { startRequest: function( element ) {
if (!this.pending[element.name]) { if ( !this.pending[element.name] ) {
this.pendingRequest++; this.pendingRequest++;
this.pending[element.name] = true; this.pending[element.name] = true;
} }
}, },
stopRequest: function(element, valid) { stopRequest: function( element, valid ) {
this.pendingRequest--; this.pendingRequest--;
// sometimes synchronization fails, make sure pendingRequest is never < 0 // sometimes synchronization fails, make sure pendingRequest is never < 0
if (this.pendingRequest < 0) { if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0; this.pendingRequest = 0;
} }
delete this.pending[element.name]; delete this.pending[element.name];
@@ -791,7 +791,7 @@ $.extend($.validator, {
} }
}, },
previousValue: function(element) { previousValue: function( element ) {
return $.data(element, "previousValue") || $.data(element, "previousValue", { return $.data(element, "previousValue") || $.data(element, "previousValue", {
old: null, old: null,
valid: true, valid: true,
@@ -812,7 +812,7 @@ $.extend($.validator, {
creditcard: {creditcard: true} creditcard: {creditcard: true}
}, },
addClassRules: function(className, rules) { addClassRules: function( className, rules ) {
if ( className.constructor === String ) { if ( className.constructor === String ) {
this.classRuleSettings[className] = rules; this.classRuleSettings[className] = rules;
} else { } else {
@@ -820,12 +820,12 @@ $.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]);
} }
}); });
@@ -833,7 +833,7 @@ $.extend($.validator, {
return rules; return rules;
}, },
attributeRules: function(element) { attributeRules: function( element ) {
var rules = {}; var rules = {};
var $element = $(element); var $element = $(element);
@@ -841,11 +841,11 @@ $.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
if (value === "") { if ( value === "" ) {
value = true; value = true;
} }
// force non-HTML5 browsers to return bool // force non-HTML5 browsers to return bool
@@ -854,51 +854,51 @@ $.extend($.validator, {
value = $element.attr(method); value = $element.attr(method);
} }
if (value) { if ( value ) {
rules[method] = value; rules[method] = value;
} else if ($element[0].getAttribute("type") === method) { } else if ( $element[0].getAttribute("type") === method ) {
rules[method] = true; rules[method] = true;
} }
} }
// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { if ( rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength) ) {
delete rules.maxlength; delete rules.maxlength;
} }
return rules; return rules;
}, },
dataRules: function(element) { dataRules: function( element ) {
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;
} }
} }
return rules; return rules;
}, },
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]) || {};
} }
return rules; return rules;
}, },
normalizeRules: function(rules, element) { normalizeRules: function( rules, element ) {
// handle dependency check // handle dependency check
$.each(rules, function(prop, val) { $.each(rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false // ignore rule when param is explicitly false, eg. required:false
if (val === false) { if ( val === false ) {
delete rules[prop]; delete rules[prop];
return; return;
} }
if (val.param || val.depends) { if ( val.param || val.depends ) {
var keepRule = true; var keepRule = true;
switch (typeof val.depends) { switch (typeof val.depends) {
case "string": case "string":
@@ -908,7 +908,7 @@ $.extend($.validator, {
keepRule = val.depends.call(element, element); keepRule = val.depends.call(element, element);
break; break;
} }
if (keepRule) { if ( keepRule ) {
rules[prop] = val.param !== undefined ? val.param : true; rules[prop] = val.param !== undefined ? val.param : true;
} else { } else {
delete rules[prop]; delete rules[prop];
@@ -917,36 +917,36 @@ $.extend($.validator, {
}); });
// evaluate parameters // evaluate parameters
$.each(rules, function(rule, parameter) { $.each(rules, function( rule, parameter ) {
rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter; rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
}); });
// 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])];
} }
} }
}); });
if ($.validator.autoCreateRanges) { if ( $.validator.autoCreateRanges ) {
// auto-create ranges // auto-create ranges
if (rules.min && rules.max) { if ( rules.min && rules.max ) {
rules.range = [rules.min, rules.max]; rules.range = [rules.min, rules.max];
delete rules.min; delete rules.min;
delete rules.max; delete rules.max;
} }
if (rules.minlength && rules.maxlength) { if ( rules.minlength && rules.maxlength ) {
rules.rangelength = [rules.minlength, rules.maxlength]; rules.rangelength = [rules.minlength, rules.maxlength];
delete rules.minlength; delete rules.minlength;
delete rules.maxlength; delete rules.maxlength;
@@ -957,8 +957,8 @@ $.extend($.validator, {
}, },
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule: function(data) { normalizeRule: function( data ) {
if( typeof data === "string" ) { if ( typeof data === "string" ) {
var transformed = {}; var transformed = {};
$.each(data.split(/\s/), function() { $.each(data.split(/\s/), function() {
transformed[this] = true; transformed[this] = true;
@@ -969,10 +969,10 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Validator/addMethod // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
addMethod: function(name, method, message) { addMethod: function( name, method, message ) {
$.validator.methods[name] = method; $.validator.methods[name] = method;
$.validator.messages[name] = message !== undefined ? message : $.validator.messages[name]; $.validator.messages[name] = message !== undefined ? message : $.validator.messages[name];
if (method.length < 3) { if ( method.length < 3 ) {
$.validator.addClassRules(name, $.validator.normalizeRule(name)); $.validator.addClassRules(name, $.validator.normalizeRule(name));
} }
}, },
@@ -980,7 +980,7 @@ $.extend($.validator, {
methods: { methods: {
// http://docs.jquery.com/Plugins/Validation/Methods/required // http://docs.jquery.com/Plugins/Validation/Methods/required
required: function(value, element, param) { required: function( value, element, param ) {
// check if dependency is met // check if dependency is met
if ( !this.depend(param, element) ) { if ( !this.depend(param, element) ) {
return "dependency-mismatch"; return "dependency-mismatch";
@@ -997,7 +997,7 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/remote // http://docs.jquery.com/Plugins/Validation/Methods/remote
remote: function(value, element, param) { remote: function( value, element, param ) {
if ( this.optional(element) ) { if ( this.optional(element) ) {
return "dependency-mismatch"; return "dependency-mismatch";
} }
@@ -1026,7 +1026,7 @@ $.extend($.validator, {
port: "validate" + element.name, port: "validate" + element.name,
dataType: "json", dataType: "json",
data: data, data: data,
success: function(response) { success: function( response ) {
validator.settings.messages[element.name].remote = previous.originalMessage; validator.settings.messages[element.name].remote = previous.originalMessage;
var valid = response === true || response === "true"; var valid = response === true || response === "true";
if ( valid ) { if ( valid ) {
@@ -1051,19 +1051,19 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/minlength // http://docs.jquery.com/Plugins/Validation/Methods/minlength
minlength: function(value, element, param) { minlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
return this.optional(element) || length >= param; return this.optional(element) || length >= param;
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/maxlength // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
maxlength: function(value, element, param) { maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
return this.optional(element) || length <= param; return this.optional(element) || length <= param;
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/rangelength // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
rangelength: function(value, element, param) { rangelength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
return this.optional(element) || ( length >= param[0] && length <= param[1] ); return this.optional(element) || ( length >= param[0] && length <= param[1] );
}, },
@@ -1084,45 +1084,45 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/email // http://docs.jquery.com/Plugins/Validation/Methods/email
email: function(value, element) { email: function( value, element ) {
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
return this.optional(element) || /^((([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.test(value); return this.optional(element) || /^((([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.test(value);
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/url // http://docs.jquery.com/Plugins/Validation/Methods/url
url: function(value, element) { url: function( value, element ) {
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
return this.optional(element) || /^(https?|s?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.test(value); return this.optional(element) || /^(https?|s?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.test(value);
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/date // http://docs.jquery.com/Plugins/Validation/Methods/date
date: function(value, element) { date: function( value, element ) {
return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString()); return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString());
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/dateISO // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
dateISO: function(value, element) { dateISO: function( value, element ) {
return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value); return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value);
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/number // http://docs.jquery.com/Plugins/Validation/Methods/number
number: function(value, element) { number: function( value, element ) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value); return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/digits // http://docs.jquery.com/Plugins/Validation/Methods/digits
digits: function(value, element) { digits: function( value, element ) {
return this.optional(element) || /^\d+$/.test(value); return this.optional(element) || /^\d+$/.test(value);
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/creditcard // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
// based on http://en.wikipedia.org/wiki/Luhn // based on http://en.wikipedia.org/wiki/Luhn
creditcard: function(value, element) { creditcard: function( value, element ) {
if ( this.optional(element) ) { if ( this.optional(element) ) {
return "dependency-mismatch"; return "dependency-mismatch";
} }
// accept only spaces, digits and dashes // accept only spaces, digits and dashes
if (/[^0-9 \-]+/.test(value)) { if ( /[^0-9 \-]+/.test(value) ) {
return false; return false;
} }
var nCheck = 0, var nCheck = 0,
@@ -1134,8 +1134,8 @@ $.extend($.validator, {
for (var n = value.length - 1; n >= 0; n--) { for (var n = value.length - 1; n >= 0; n--) {
var cDigit = value.charAt(n); var cDigit = value.charAt(n);
nDigit = parseInt(cDigit, 10); nDigit = parseInt(cDigit, 10);
if (bEven) { if ( bEven ) {
if ((nDigit *= 2) > 9) { if ( (nDigit *= 2) > 9 ) {
nDigit -= 9; nDigit -= 9;
} }
} }
@@ -1147,11 +1147,11 @@ $.extend($.validator, {
}, },
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
equalTo: function(value, element, param) { equalTo: function( value, element, param ) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated // bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $(param); var target = $(param);
if (this.settings.onfocusout) { if ( this.settings.onfocusout ) {
target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() { target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
$(element).valid(); $(element).valid();
}); });
@@ -1175,9 +1175,9 @@ $.format = $.validator.format;
var pendingRequests = {}; var pendingRequests = {};
// Use a prefilter if available (1.5+) // Use a prefilter if available (1.5+)
if ( $.ajaxPrefilter ) { if ( $.ajaxPrefilter ) {
$.ajaxPrefilter(function(settings, _, xhr) { $.ajaxPrefilter(function( settings, _, xhr ) {
var port = settings.port; var port = settings.port;
if (settings.mode === "abort") { if ( settings.mode === "abort" ) {
if ( pendingRequests[port] ) { if ( pendingRequests[port] ) {
pendingRequests[port].abort(); pendingRequests[port].abort();
} }
@@ -1187,10 +1187,10 @@ $.format = $.validator.format;
} else { } else {
// Proxy ajax // Proxy ajax
var ajax = $.ajax; var ajax = $.ajax;
$.ajax = function(settings) { $.ajax = function( settings ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode, var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port; port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if (mode === "abort") { if ( mode === "abort" ) {
if ( pendingRequests[port] ) { if ( pendingRequests[port] ) {
pendingRequests[port].abort(); pendingRequests[port].abort();
} }
@@ -1205,10 +1205,10 @@ $.format = $.validator.format;
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
(function($) { (function($) {
$.extend($.fn, { $.extend($.fn, {
validateDelegate: function(delegate, type, handler) { validateDelegate: function( delegate, type, handler ) {
return this.bind(type, function(event) { return this.bind(type, function( event ) {
var target = $(event.target); var target = $(event.target);
if (target.is(delegate)) { if ( target.is(delegate) ) {
return handler.apply(target, arguments); return handler.apply(target, arguments);
} }
}); });