PageSourceSearch

https://www.wjir.org/jquery_validation/jquery.validate.js

js wjir.org collected 2026-10-09 03:45:35 UTC 40,949 bytes, 1,257 lines download raw bytes

1/**
2 * jQuery Validation Plugin @VERSION
3 *
4 * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
5 * http://docs.jquery.com/Plugins/Validation
6 *
7 * Copyright (c) 2012 Jörn Zaefferer
8 *
9 * Dual licensed under the MIT and GPL licenses:
10 *   http://www.opensource.org/licenses/mit-license.php
11 *   http://www.gnu.org/licenses/gpl.html
12 */
13
14(function($) {
15
16$.extend($.fn, {
17	// http://docs.jquery.com/Plugins/Validation/validate
18	validate: function( options ) {
19
20		// if nothing is selected, return nothing; can't chain anyway
21		if (!this.length) {
22			
23			if (options && options.debug && window.console) {
24				console.warn( "nothing selected, can't validate, returning nothing" );
25			}
26			return;
27		}
28
29		// check if a validator for this form was already created
30		var validator = $.data(this[0], 'validator');
31		if ( validator ) {
32			return validator;
33		}
34
35		// Add novalidate tag if HTML5.
36		this.attr('novalidate', 'novalidate');
37
38		validator = new $.validator( options, this[0] );
39		$.data(this[0], 'validator', validator);
40
41		if ( validator.settings.onsubmit ) {
42
43			this.validateDelegate( ":submit", "click", function(ev) {
44				if ( validator.settings.submitHandler ) {
45					validator.submitButton = ev.target;
46				}
47				// allow suppressing validation by adding a cancel class to the submit button
48				if ( $(ev.target).hasClass('cancel') ) {
49					validator.cancelSubmit = true;
50				}
51			});
52
53			// validate the form on submit
54			this.submit( function( event ) {
55				if ( validator.settings.debug ) {
56					// prevent form submit to be able to see console output
57					event.preventDefault();
58				}
59				function handle() {
60					var hidden;
61					if ( validator.settings.submitHandler ) {
62						if (validator.submitButton) {
63							// insert a hidden input as a replacement for the missing submit button
64							hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
65						}
66						validator.settings.submitHandler.call( validator, validator.currentForm, event );
67						if (validator.submitButton) {
68							// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
69							hidden.remove();
70						}
71						return false;
72					}
73					return true;
74				}
75
76				// prevent submit for invalid forms or custom submit handlers
77				if ( validator.cancelSubmit ) {
78					validator.cancelSubmit = false;
79					return handle();
80				}
81				if ( validator.form() ) {
82					if ( validator.pendingRequest ) {
83						validator.formSubmitted = true;
84						return false;
85					}
86					return handle();
87				} else {
88					validator.focusInvalid();
89					return false;
90				}
91			});
92		}
93
94		return validator;
95	},
96	// http://docs.jquery.com/Plugins/Validation/valid
97	valid: function() {
98		if ( $(this[0]).is('form')) {
99			return this.validate().form();
100		} else {
101			var valid = true;
102			var validator = $(this[0].form).validate();
103			this.each(function() {
104				valid &= validator.element(this);
105			});
106			return valid;
107		}
108	},
109	// attributes: space seperated list of attributes to retrieve and remove
110	removeAttrs: function(attributes) {
111		var result = {},
112			$element = this;
113		$.each(attributes.split(/\s/), function(index, value) {
114			result[value] = $element.attr(value);
115			$element.removeAttr(value);
116		});
117		return result;
118	},
119	// http://docs.jquery.com/Plugins/Validation/rules
120	rules: function(command, argument) {
121		var element = this[0];
122
123		if (command) {
124			var settings = $.data(element.form, 'validator').settings;
125			var staticRules = settings.rules;
126			var existingRules = $.validator.staticRules(element);
127			switch(command) {
128			case "add":
129				$.extend(existingRules, $.validator.normalizeRule(argument));
130				staticRules[element.name] = existingRules;
131				if (argument.messages) {
132					settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
133				}
134				break;
135			case "remove":
136				if (!argument) {
137					delete staticRules[element.name];
138					return existingRules;
139				}
140				var filtered = {};
141				$.each(argument.split(/\s/), function(index, method) {
142					filtered[method] = existingRules[method];
143					delete existingRules[method];
144				});
145				return filtered;
146			}
147		}
148
149		var data = $.validator.normalizeRules(
150		$.extend(
151			{},
152			$.validator.metadataRules(element),
153			$.validator.classRules(element),
154			$.validator.attributeRules(element),
155			$.validator.staticRules(element)
156		), element);
157
158		// make sure required is at front
159		if (data.required) {
160			var param = data.required;
161			delete data.required;
162			data = $.extend({required: param}, data);
163		}
164
165		return data;
166	}
167});
168
169// Custom selectors
170$.extend($.expr[":"], {
171	// http://docs.jquery.com/Plugins/Validation/blank
172	blank: function(a) {return !$.trim("" + a.value);},
173	// http://docs.jquery.com/Plugins/Validation/filled
174	filled: function(a) {return !!$.trim("" + a.value);},
175	// http://docs.jquery.com/Plugins/Validation/unchecked
176	unchecked: function(a) {return !a.checked;}
177});
178
179// constructor for validator
180$.validator = function( options, form ) {
181	this.settings = $.extend( true, {}, $.validator.defaults, options );
182	this.currentForm = form;
183	this.init();
184};
185
186$.validator.format = function(source, params) {
187	if ( arguments.length === 1 ) {
188		return function() {
189			
190			var args = $.makeArray(arguments);
191			args.unshift(source);
192			return $.validator.format.apply( this, args );
193		};
194	}
195	if ( arguments.length > 2 && params.constructor !== Array  ) {
196		params = $.makeArray(arguments).slice(1);
197	}
198	if ( params.constructor !== Array ) {
199		params = [ params ];
200	}
201	$.each(params, function(i, n) {
202		source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
203	});
204	return source;
205};
206
207$.extend($.validator, {
208
209	defaults: {
210		messages: {},
211		groups: {},
212		rules: {},
213		errorClass: "error",
214		validClass: "valid",
215		errorElement: "div",
216		focusInvalid: true,
217		errorContainer: $( [] ),
218		errorLabelContainer: $( [] ),
219		onsubmit: true,
220		ignore: ":hidden",
221		ignoreTitle: false,
222		onfocusin: function(element, event) {
223			this.lastActive = element;
224
225			// hide error label and remove error class on focus if enabled
226			if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
227				if ( this.settings.unhighlight ) {
228					this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.val
228idClass );
229				}
230				this.addWrapper(this.errorsFor(element)).hide();
231			}
232		},
233		onfocusout: function(element, event) {
234			if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
235				this.element(element);
236			}
237		},
238		onkeyup: function(element, event) {
239			if ( element.name in this.submitted || element === this.lastElement ) {
240				this.element(element);
241			}
242		},
243		onclick: function(element, event) {
244			// click on selects, radiobuttons and checkboxes
245			if ( element.name in this.submitted ) {
246				this.element(element);
247			}
248			// or option elements, check parent select in that case
249			else if (element.parentNode.name in this.submitted) {
250				this.element(element.parentNode);
251			}
252		},
253		highlight: function(element, errorClass, validClass) {
254			if (element.type === 'radio') {
255				this.findByName(element.name).addClass(errorClass).removeClass(validClass);
256			} else {
257				$(element).addClass(errorClass).removeClass(validClass);
258			}
259		},
260		unhighlight: function(element, errorClass, validClass) {
261			if (element.type === 'radio') {
262				this.findByName(element.name).removeClass(errorClass).addClass(validClass);
263			} else {
264				$(element).removeClass(errorClass).addClass(validClass);
265			}
266		}
267	},
268
269	// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
270	setDefaults: function(settings) {
271		$.extend( $.validator.defaults, settings );
272	},
273
274	messages: {
275		required:"<img src='images/err_img.gif' /> Please Enter This Field...",
276		remote: "<img src='images/err_img.gif' /> Please fix this field.",
277		email: "<img src='images/err_img.gif' /> Please enter a valid email address.",
278	
279		url: "<img src='images/err_img.gif' /> Please enter a valid URL.",
280		date: "<img src='images/err_img.gif' /> Please enter a valid date.",
281		dateISO: "<img src='images/err_img.gif' /> Please enter a valid date (ISO).",
282		number: "<img src='images/err_img.gif' /> Please enter a valid number.",
283		digits: "<img src='images/err_img.gif' /> Please Enter Only Digits..",
284		creditcard: "<img src='images/err_img.gif' /> Please enter a valid credit card number.",
285		equalTo: "<img src='images/err_img.gif' /> New Pass And Confirm Pass Not Matched",
286		accept: "<img src='images/err_img.gif' /> Please enter a value with a valid extension.",
287		maxlength: $.validator.format("<img src='images/err_img.gif' /> Please enter no more than {0} characters."),
288		minlength: $.validator.format("<img src='images/err_img.gif' /> Please Enter Min {0} Char.."),
289		rangelength: $.validator.format("<img src='images/err_img.gif' /> Please enter a value between {0} and {1} characters long."),
290		range: $.validator.format("<img src='images/err_img.gif' /> Please Enter a value between {0} and {1}."),
291		max: $.validator.format("<img src='images/err_img.gif' /> Please enter a value less than or equal to {0}."),
292		min: $.validator.format("<img src='images/err_img.gif' /> Please enter a value greater than or equal to {0}.")
293	},
294
295	autoCreateRanges: false,
296
297	prototype: {
298
299		init: function() {
300			this.labelContainer = $(this.settings.errorLabelContainer);
301			this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
302			this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
303			this.submitted = {};
304			this.valueCache = {};
305			this.pendingRequest = 0;
306			this.pending = {};
307			this.invalid = {};
308			this.reset();
309
310			var groups = (this.groups = {});
311			$.each(this.settings.groups, function(key, value) {
312				$.each(value.split(/\s/), function(index, name) {
313					groups[name] = key;
314				});
315			});
316			var rules = this.settings.rules;
317			$.each(rules, function(key, value) {
318				rules[key] = $.validator.normalizeRule(value);
319			});
320
321			function delegate(event) {
322				var validator = $.data(this[0].form, "validator"),
323					eventType = "on" + event.type.replace(/^validate/, "");
324				if (validator.settings[eventType]) {
325					validator.settings[eventType].call(validator, this[0], event);
326				}
327			}
328			$(this.currentForm)
329				.validateDelegate("[type='text'], [type='password'], [type='file'], select, textarea, " +
330					"[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
331					"[type='email'], [type='datetime'], [type='date'], [type='month'], " +
332					"[type='week'], [type='time'], [type='datetime-local'], " +
333					"[type='range'], [type='color'] ",
334					"focusin focusout keyup", delegate)
335				.validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
336
337			if (this.settings.invalidHandler) {
338				$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
339			}
340		},
341
342		// http://docs.jquery.com/Plugins/Validation/Validator/form
343		form: function() {
344			this.checkForm();
345			$.extend(this.submitted, this.errorMap);
346			this.invalid = $.extend({}, this.errorMap);
347			if (!this.valid()) {
348				$(this.currentForm).triggerHandler("invalid-form", [this]);
349			}
350			this.showErrors();
351			return this.valid();
352		},
353
354		checkForm: function() {
355			this.prepareForm();
356			for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
357				this.check( elements[i] );
358			}
359			return this.valid();
360		},
361
362		// http://docs.jquery.com/Plugins/Validation/Validator/element
363		element: function( element ) {
364			element = this.validationTargetFor( this.clean( element ) );
365			this.lastElement = element;
366			this.prepareElement( element );
367			this.currentElements = $(element);
368			var result = this.check( element ) !== false;
369			if (result) {
370				delete this.invalid[element.name];
371			} else {
372				this.invalid[element.name] = true;
373			}
374			if ( !this.numberOfInvalids() ) {
375				// Hide error containers on last error
376				this.toHide = this.toHide.add( this.containers );
377			}
378			this.showErrors();
379			return result;
380		},
381
382		// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
383		showErrors: function(errors) {
384			if(errors) {
385				// add items to error list and map
386				$.extend( this.errorMap, errors );
387				this.errorList = [];
388				for ( var name in errors ) {
389					this.errorList.push({
390						message: errors[name],
391						element: this.findByName(name)[0]
392					});
393				}
394				// remove items from success list
395				this.successList = $.grep( this.successList, function(element) {
396					return !(element.name in errors);
397				});
398			}
399			if (this.settings.showErrors) {
400				this.settings.showErrors.call( this, this.errorMap, this.errorList );
401			} else {
402				this.defaultShowErrors();
403			}
404		},
405
406		// http://docs.jquery.com/Plugins/Validation/Validator/resetForm
407		resetForm: function() {
408			if ( $.fn.resetForm ) {
409				$( this.currentForm ).resetForm();
410			}
411			this.submitted = {};
412			this.lastElement = null;
413			this.prepareForm();
414			this.hideErrors();
415			this.elements().removeClass( this.settings.errorClass );
416		},
417
418		numberOfInvalids: function() {
419			return this.objectLength(this.invalid);
420		},
421
422		objectLength: function( obj ) {
423			var count = 0;
424			for ( var i in obj ) {
425				count++;
426			}
427			return count;
428		},
429
430		hideErrors: function() {
431			this.addWrapper( this.toHide ).hide();
432		},
433
434		valid: function() {
435			return this.size() === 0;
436		},
437
438		size: function() {
439			return this.errorList.length;
440		},
441
442		focusInvalid: function() {
443			if( this.settings.focusInvalid ) {
444				try {
445					$(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
446					.filter(":visible")
447					.focus()
448					// manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
449					.trigger("focusin");
450				} catch(e) {
451					// ignore IE throwing errors when focusing hidden elements
452				}
453			}
454		},
455
456		findLastActive: function() {
457			var lastActive = this.lastActive;
458			return lastActive && $.grep(this.errorList, function(n) {
459				return n.element.name === lastActive.name;
460			}).length === 1 && lastActive;
461		},
462
463		elements: function() {
464			var validator = this,
465				rulesCache = {};
466
467			// select all valid inputs inside the form (no submit or reset buttons)
468			return $(this.currentForm)
469			.find("input, select, textarea")
470			.not(":submit, :reset, :image, [disabled]")
471			.not( this.settings.ignore )
472			.filter(function() {
473				if ( !this.name && validator.settings.debug && window.console ) {
474					console.error( "%o has no name assigned", this);
475				}
476
477				// select only the first element for each name, and only those with rules specified
478				if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
479					return false;
480				}
481
482				rulesCache[this.name] = true;
483				return true;
484			});
485		},
486
487		clean: function( selector ) {
488			return $( selector )[0];
489		},
490
491		errors: function() {
492			var errorClass = this.settings.errorClass.replace(' ', '.');
493			return $( this.settings.errorElement + "." + errorClass, this.errorContext );
494		},
495
496		reset: function() {
497			this.successList = [];
498			this.errorList = [];
499			this.errorMap = {};
500			this.toShow = $([]);
501			this.toHide = $([]);
502			this.currentElements = $([]);
503		},
504
505		prepareForm: function() {
506			this.reset();
507			this.toHide = this.errors().add( this.containers );
508		},
509
510		prepareElement: function( element ) {
511			this.reset();
512			this.toHide = this.errorsFor(element);
513		},
514
515		elementValue: function( element ) {
516			var val = $(element).val();
517			if( typeof val === 'string' ) {
518				return val.replace(/\r/g, "");
519			}
520			return val;
521		},
522
523		check: function( element ) {
524			element = this.validationTargetFor( this.clean( element ) );
525
526			var rules = $(element).rules();
527			var dependencyMismatch = false;
528			var val = this.elementValue(element);
529			var result;
530
531			for (var method in rules ) {
532				var rule = { method: method, parameters: rules[method] };
533				try {
534
535					result = $.validator.methods[method].call( this, val, element, rule.parameters );
536
537					// if a method indicates that the field is optional and therefore valid,
538					// don't mark it as valid when there are no other rules
539					if ( result === "dependency-mismatch" ) {
540						dependencyMismatch = true;
541						continue;
542					}
543					dependencyMismatch = false;
544
545					if ( result === "pending" ) {
546						this.toHide = this.toHide.not( this.errorsFor(element) );
547						return;
548					}
549
550					if( !result ) {
551						this.formatAndAdd( element, rule );
552						return false;
553					}
554				} catch(e) {
555					if ( this.settings.debug && window.console ) {
556						console.log("exception occured when checking element " + element.i
556d + ", check the '" + rule.method + "' method", e);
557					}
558					throw e;
559				}
560			}
561			if (dependencyMismatch) {
562				return;
563			}
564			if ( this.objectLength(rules) ) {
565				this.successList.push(element);
566			}
567			return true;
568		},
569
570		// return the custom message for the given element and validation method
571		// specified in the element's "messages" metadata
572		customMetaMessage: function(element, method) {
573			if (!$.metadata) {
574				return;
575			}
576			var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata();
577			return meta && meta.messages && meta.messages[method];
578		},
579
580		// return the custom message for the given element name and validation method
581		customMessage: function( name, method ) {
582			var m = this.settings.messages[name];
583			return m && (m.constructor === String ? m : m[method]);
584		},
585
586		// return the first defined argument, allowing empty strings
587		findDefined: function() {
588			for(var i = 0; i < arguments.length; i++) {
589				if (arguments[i] !== undefined) {
590					return arguments[i];
591				}
592			}
593			return undefined;
594		},
595
596		defaultMessage: function( element, method) {
597			return this.findDefined(
598				this.customMessage( element.name, method ),
599				this.customMetaMessage( element, method ),
600				// title is never undefined, so handle empty string as undefined
601				!this.settings.ignoreTitle && element.title || undefined,
602				$.validator.messages[method],
603				"<strong>Warning: No message defined for " + element.name + "</strong>"
604			);
605		},
606
607		formatAndAdd: function( element, rule ) {
608			var message = this.defaultMessage( element, rule.method ),
609				theregex = /\$?\{(\d+)\}/g;
610			if ( typeof message === "function" ) {
611				message = message.call(this, rule.parameters, element);
612			} else if (theregex.test(message)) {
613				message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters);
614			}
615			this.errorList.push({
616				message: message,
617				element: element
618			});
619
620			this.errorMap[element.name] = message;
621			this.submitted[element.name] = message;
622		},
623
624		addWrapper: function(toToggle) {
625			if ( this.settings.wrapper ) {
626				toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
627			}
628			return toToggle;
629		},
630
631		defaultShowErrors: function() {
632			var i, elements;
633			for ( i = 0; this.errorList[i]; i++ ) {
634				var error = this.errorList[i];
635				if ( this.settings.highlight ) {
636					this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
637				}
638				this.showLabel( error.element, error.message );
639			}
640			if( this.errorList.length ) {
641				this.toShow = this.toShow.add( this.containers );
642			}
643			if (this.settings.success) {
644				for ( i = 0; this.successList[i]; i++ ) {
645					this.showLabel( this.successList[i] );
646				}
647			}
648			if (this.settings.unhighlight) {
649				for ( i = 0, elements = this.validElements(); elements[i]; i++ ) {
650					this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
651				}
652			}
653			this.toHide = this.toHide.not( this.toShow );
654			this.hideErrors();
655			this.addWrapper( this.toShow ).show();
656		},
657
658		validElements: function() {
659			return this.currentElements.not(this.invalidElements());
660		},
661
662		invalidElements: function() {
663			return $(this.errorList).map(function() {
664				return this.element;
665			});
666		},
667
668		showLabel: function(element, message) {
669			var label = this.errorsFor( element );
670			if ( label.length ) {
671				// refresh error/success class
672				label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
673
674				// check if we have a generated label, replace the message then
675				if ( label.attr("generated") ) {
676					label.html(message);
677				}
678			} else {
679				// create label
680				label = $("<" + this.settings.errorElement + "/>")
681					.attr({"for":  this.idOrName(element), generated: true})
682					.addClass(this.settings.errorClass)
683					.html(message || "");
684				if ( this.settings.wrapper ) {
685					// make sure the element is visible, even in IE
686					// actually showing the wrapped element is handled elsewhere
687					label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
688				}
689				if ( !this.labelContainer.append(label).length ) {
690					if ( this.settings.errorPlacement ) {
691						this.settings.errorPlacement(label, $(element) );
692					} else {
693					label.insertAfter(element);
694					}
695				}
696			}
697			if ( !message && this.settings.success ) {
698				label.text("");
699				if ( typeof this.settings.success === "string" ) {
700					label.addClass( this.settings.success );
701				} else {
702					this.settings.success( label );
703				}
704			}
705			this.toShow = this.toShow.add(label);
706		},
707
708		errorsFor: function(element) {
709			var name = this.idOrName(element);
710			return this.errors().filter(function() {
711				return $(this).attr('for') === name;
712			});
713		},
714
715		idOrName: function(element) {
716			return this.groups[element.name] || (this.checkable(element) ? element.name : element.i
716d || element.name);
717		},
718
719		validationTargetFor: function(element) {
720			// if radio/checkbox, validate first element in group instead
721			if (this.checkable(element)) {
722				element = this.findByName( element.name ).not(this.settings.ignore)[0];
723			}
724			return element;
725		},
726
727		checkable: function( element ) {
728			return (/radio|checkbox/i).test(element.type);
729		},
730
731		findByName: function( name ) {
732			// select by name and filter by form for performance over form.find("[name=...]")
733			var form = this.currentForm;
734			return $(document.getElementsByName(name)).map(function(index, element) {
735				return element.form === form && element.name === name && element  || null;
736			});
737		},
738
739		getLength: function(value, element) {
740			switch( element.nodeName.toLowerCase() ) {
741			case 'select':
742				return $("option:selected", element).length;
743			case 'input':
744				if( this.checkable( element) ) {
745					return this.findByName(element.name).filter(':checked').length;
746				}
747			}
748			return value.length;
749		},
750
751		depend: function(param, element) {
752			return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
753		},
754
755		dependTypes: {
756			"boolean": function(param, element) {
757				return param;
758			},
759			"string": function(param, element) {
760				return !!$(param, element.form).length;
761			},
762			"function": function(param, element) {
763				return param(element);
764			}
765		},
766
767		optional: function(element) {
768			var val = this.elementValue(element);
769			return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch";
770		},
771
772		startRequest: function(element) {
773			if (!this.pending[element.name]) {
774				this.pendingRequest++;
775				this.pending[element.name] = true;
776			}
777		},
778
779		stopRequest: function(element, valid) {
780			this.pendingRequest--;
781			// sometimes synchronization fails, make sure pendingRequest is never < 0
782			if (this.pendingRequest < 0) {
783				this.pendingRequest = 0;
784			}
785			delete this.pending[element.name];
786			if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
787				$(this.currentForm).submit();
788				this.formSubmitted = false;
789			} else if (!valid && this.pendingRequest === 0 && this.formSubmitted) {
790				$(this.currentForm).triggerHandler("invalid-form", [this]);
791				this.formSubmitted = false;
792			}
793		},
794
795		previousValue: function(element) {
796			return $.data(element, "previousValue") || $.data(element, "previousValue", {
797				old: null,
798				valid: true,
799				message: this.defaultMessage( element, "remote" )
800			});
801		}
802
803	},
804
805	classRuleSettings: {
806		required: {required: true},
807		email: {email: true},
808
809		url: {url: true},
810		date: {date: true},
811		dateISO: {dateISO: true},
812		number: {number: true},
813		digits: {digits: true},
814		creditcard: {creditcard: true}
815	},
816
817	addClassRules: function(className, rules) {
818		if ( className.constructor === String ) {
819			this.classRuleSettings[className] = rules;
820		} else {
821			$.extend(this.classRuleSettings, className);
822		}
823	},
824
825	classRules: function(element) {
826		var rules = {};
827		var classes = $(element).attr('class');
828		if ( classes ) {
829			$.each(classes.split(' '), function() {
830				if (this in $.validator.classRuleSettings) {
831					$.extend(rules, $.validator.classRuleSettings[this]);
832				}
833			});
834		}
835		return rules;
836	},
837
838	attributeRules: function(element) {
839		var rules = {};
840		var $element = $(element);
841
842		for (var method in $.validator.methods) {
843			var value;
844
845			// support for <input required> in both html5 and older browsers
846			if (method === 'required') {
847				value = $element.get(0).getAttribute(method);
848				// Some browsers return an empty string for the required attribute
849				// and non-HTML5 browsers might have required="" markup
850				if (value === "") {
851					value = true;
852				} else if (value === "false") {
853					value = false;
854				}
855				// force non-HTML5 browsers to return bool
856				value = !!value;
857			} else {
858				value = $element.attr(method);
859			}
860
861			if (value) {
862				rules[method] = value;
863			} else if ($element[0].getAttribute("type") === method) {
864				rules[method] = true;
865			}
866		}
867
868		// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
869		if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
870			delete rules.maxlength;
871		}
872
873		return rules;
874	},
875
876	metadataRules: function(element) {
877		if (!$.metadata) {
878			return {};
879		}
880
881		var meta = $.data(element.form, 'validator').settings.meta;
882		return meta ?
883			$(element).metadata()[meta] :
884			$(element).metadata();
885	},
886
887	staticRules: function(element) {
888		var rules = {};
889		var validator = $.data(element.form, 'validator');
890		if (validator.settings.rules) {
891			rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
892		}
893		return rules;
894	},
895
896	normalizeRules: function(rules, element) {
897		// handle dependency check
898		$.each(rules, function(prop, val) {
899			// ignore rule when param is explicitly false, eg. required:false
900			if (val === false) {
901				delete rules[prop];
902				return;
903			}
904			if (val.param || val.depends) {
905				var keepRule = true;
906				switch (typeof val.depends) {
907					case "string":
908						keepRule = !!$(val.depends, element.form).length;
909						break;
910					case "function":
911						keepRule = val.depends.call(element, element);
912						break;
913				}
914				if (keepRule) {
915					rules[prop] = val.param !== undefined ? val.param : true;
916				} else {
917					delete rules[prop];
918				}
919			}
920		});
921
922		// evaluate parameters
923		$.each(rules, function(rule, parameter) {
924			rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
925		});
926
927		// clean number parameters
928		$.each(['minlength', 'maxlength', 'min', 'max'], function() {
929			if (rules[this]) {
930				rules[this] = Number(rules[this]);
931			}
932		});
933		$.each(['rangelength', 'range'], function() {
934			if (rules[this]) {
935				rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
936			}
937		});
938
939		if ($.validator.autoCreateRanges) {
940			// auto-create ranges
941			if (rules.min && rules.max) {
942				rules.range = [rules.min, rules.max];
943				delete rules.min;
944				delete rules.max;
945			}
946			if (rules.minlength && rules.maxlength) {
947				rules.rangelength = [rules.minlength, rules.maxlength];
948				delete rules.minlength;
949				delete rules.maxlength;
950			}
951		}
952
953		// To support custom messages in metadata ignore rule methods titled "messages"
954		if (rules.messages) {
955			delete rules.messages;
956		}
957
958		return rules;
959	},
960
961	// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
962	normalizeRule: function(data) {
963		if( typeof data === "string" ) {
964			var transformed = {};
965			$.each(data.split(/\s/), function() {
966				transformed[this] = true;
967			});
968			data = transformed;
969		}
970		return data;
971	},
972
973	// http://docs.jquery.com/Plugins/Validation/Validator/addMethod
974	addMethod: function(name, method, message) {
975		$.validator.methods[name] = method;
976		$.validator.messages[name] = message !== undefined ? message : $.validator.messages[name];
977		if (method.length < 3) {
978			$.validator.addClassRules(name, $.validator.normalizeRule(name));
979		}
980	},
981
982	methods: {
983
984		// http://docs.jquery.com/Plugins/Validation/Methods/required
985		required: function(value, element, param) {
986			// check if dependency is met
987			if ( !this.depend(param, element) ) {
988				return "dependency-mismatch";
989			}
990			if ( element.nodeName.toLowerCase() === "select" ) {
991				// could be an array for select-multiple or a string, both are fine this way
992				var val = $(element).val();
993				return val && val.length > 0;
994			}
995			if ( this.checkable(element) ) {
996				return this.getLength(value, element) > 0;
997			}
998			return $.trim(value).length > 0;
999		},
1000
1001		// http://docs.jquery.com/Plugins/Validation/Methods/remote
1002		remote: function(value, element, param) {
1003			if ( this.optional(element) ) {
1004				return "dependency-mismatch";
1005			}
1006
1007			var previous = this.previousValue(element);
1008			if (!this.settings.messages[element.name] ) {
1009				this.settings.messages[element.name] = {};
1010			}
1011			previous.originalMessage = this.settings.messages[element.name].remote;
1012			this.settings.messages[element.name].remote = previous.message;
1013
1014			param = typeof param === "string" && {url:param} || param;
1015
1016			if ( this.pending[element.name] ) {
1017				return "pending";
1018			}
1019			if ( previous.old === value ) {
1020				return previous.valid;
1021			}
1022
1023			previous.old = value;
1024			var validator = this;
1025			this.startRequest(element);
1026			var data = {};
1027			data[element.name] = value;
1028			$.ajax($.extend(true, {
1029				url: param,
1030				mode: "abort",
1031				port: "validate" + element.name,
1032				dataType: "json",
1033				data: data,
1034				success: function(response) {
1035					validator.settings.messages[element.name].remote = previous.originalMessage;
1036					var valid = response === true;
1037					if ( valid ) {
1038						var submitted = validator.formSubmitted;
1039						validator.prepareElement(element);
1040						validator.formSubmitted = submitted;
1041						validator.successList.push(element);
1042						validator.showErrors();
1043					} else {
1044						var errors = {};
1045						var message = response || validator.defaultMessage( element, "remote" );
1046						errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
1047						validator.showErrors(errors);
1048					}
1049					previous.valid = valid;
1050					validator.stopRequest(element, valid);
1051				}
1052			}, param));
1053			return "pending";
1054		},
1055
1056		// http://docs.jquery.com/Plugins/Validation/Methods/minlength
1057		minlength: function(value, element, param) {
1058			var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
1059			return this.optional(element) || length >= param;
1060		},
1061
1062		// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
1063		maxlength: function(value, element, param) {
1064			var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
1065			return this.optional(element) || length <= param;
1066		},
1067
1068		// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
1069		rangelength: function(value, element, param) {
1070			var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
1071			return this.optional(element) || ( length >= param[0] && length <= param[1] );
1072		},
1073
1074		// http://docs.jquery.com/Plugins/Validation/Methods/min
1075		min: function( value, element, param ) {
1076			return this.optional(element) || value >= param;
1077		},
1078
1079		// http://docs.jquery.com/Plugins/Validation/Methods/max
1080		max: function( value, element, param ) {
1081			return this.optional(element) || value <= param;
1082		},
1083
1084		// http://docs.jquery.com/Plugins/Validation/Methods/range
1085		range: function( value, element, param ) {
1086			return this.optional(element) || ( value >= param[0] && value <= param[1] );
1087		},
1088
1089		// http://docs.jquery.com/Plugins/Validation/Methods/email
1090		email: function(value, element) {
1091			// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
1092	
1093				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);
1094				
1095		},
1096	
1097		// http://docs.jquery.com/Plugins/Validation/Methods/url
1098		url: function(value, element) {
1099			// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
1100			return this.optional(element) || /^(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.test(value);
1101		
1102		},
1103
1104		// http://docs.jquery.com/Plugins/Validation/Methods/date
1105		date: function(value, element) {
1106			return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
1107		},
1108
1109		// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
1110		dateISO: function(value, element) {
1111			return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value);
1112		},
1113
1114		// http://docs.jquery.com/Plugins/Validation/Methods/number
1115		number: function(value, element) {
1116			return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
1117		},
1118
1119		// http://docs.jquery.com/Plugins/Validation/Methods/digits
1120		digits: function(value, element) {
1121			return this.optional(element) || /^\d+$/.test(value);
1122		},
1123
1124		// http://docs.jquery.com/Plugins/Validation/Methods/creditcard
1125		// based on http://en.wikipedia.org/wiki/Luhn
1126		creditcard: function(value, element) {
1127			if ( this.optional(element) ) {
1128				return "dependency-mismatch";
1129			}
1130			// accept only spaces, digits and dashes
1131			if (/[^0-9 \-]+/.test(value)) {
1132				return false;
1133			}
1134			var nCheck = 0,
1135				nDigit = 0,
1136				bEven = false;
1137
1138			value = value.replace(/\D/g, "");
1139
1140			for (var n = value.length - 1; n >= 0; n--) {
1141				var cDigit = value.charAt(n);
1142				nDigit = parseInt(cDigit, 10);
1143				if (bEven) {
1144					if ((nDigit *= 2) > 9) {
1145						nDigit -= 9;
1146					}
1147				}
1148				nCheck += nDigit;
1149				bEven = !bEven;
1150			}
1151
1152			return (nCheck % 10) === 0;
1153		},
1154
1155		// http://docs.jquery.com/Plugins/Validation/Methods/accept
1156		accept: function(value, element, param) {
1157			param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
1158			return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
1159		},
1160
1161		// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
1162		equalTo: function(value, element, param) {
1163			// bind to the blur event of the target in order to revalidate whenever the target field is updated
1164			// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
1165			var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
1166				$(element).valid();
1167			});
1168			return value === target.val();
1169		}
1170
1171	}
1172
1173});
1174
1175// deprecated, use $.validator.format instead
1176$.format = $.validator.format;
1177
1178}(jQuery));
1179
1180// ajax mode: abort
1181// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1182// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
1183(function($) {
1184	var pendingRequests = {};
1185	// Use a prefilter if available (1.5+)
1186	if ( $.ajaxPrefilter ) {
1187		$.ajaxPrefilter(function(settings, _, xhr) {
1188			var port = settings.port;
1189			if (settings.mode === "abort") {
1190				if ( pendingRequests[port] ) {
1191					pendingRequests[port].abort();
1192				}
1193				pendingRequests[port] = xhr;
1194			}
1195		});
1196	} else {
1197		// Proxy ajax
1198		var ajax = $.ajax;
1199		$.ajax = function(settings) {
1200			var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
1201				port = ( "port" in settings ? settings : $.ajaxSettings ).port;
1202			if (mode === "abort") {
1203				if ( pendingRequests[port] ) {
1204					pendingRequests[port].abort();
1205				}
1206				return (pendingRequests[port] = ajax.apply(this, arguments));
1207			}
1208			return ajax.apply(this, arguments);
1209		};
1210	}
1211}(jQuery));
1212
1213// provides cross-browser focusin and focusout events
1214// IE has native support, in other browsers, use event caputuring (neither bubbles)
1215
1216// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
1217// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
1218(function($) {
1219	// only implement if not provided by jQuery core (since 1.4)
1220	// TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
1221	if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
1222		$.each({
1223			focus: 'focusin',
1224			blur: 'focusout'
1225		}, function( original, fix ){
1226			$.event.special[fix] = {
1227				setup:function() {
1228					this.addEventListener( original, handler, true );
1229				},
1230				teardown:function() {
1231					this.removeEventListener( original, handler, true );
1232				},
1233				handler: function(e) {
1234					var args = arguments;
1235					args[0] = $.event.fix(e);
1236					args[0].type = fix;
1237					return $.event.handle.apply(this, args);
1238				}
1239			};
1240			function handler(e) {
1241				e = $.event.fix(e);
1242				e.type = fix;
1243				return $.event.handle.call(this, e);
1244			}
1245		});
1246	}
1247	$.extend($.fn, {
1248		validateDelegate: function(delegate, type, handler) {
1249			return this.bind(type, function(event) {
1250				var target = $(event.target);
1251				if (target.is(delegate)) {
1252					return handler.apply(target, arguments);
1253				}
1254			});
1255		}
1256	});
1257}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.