PageSourceSearch

https://www.51selling.com/Resources/static/js/jquery.validate.js

js 51selling.com collected 2026-10-02 00:45:43 UTC 39,383 bytes, 1,186 lines download raw bytes

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