LaravelTest

Форк
0
1657 строк · 49.7 Кб
1
/*!
2
 * jQuery Validation Plugin v1.19.3
3
 *
4
 * https://jqueryvalidation.org/
5
 *
6
 * Copyright (c) 2021 Jörn Zaefferer
7
 * Released under the MIT license
8
 */
9
(function( factory ) {
10
	if ( typeof define === "function" && define.amd ) {
11
		define( ["jquery"], factory );
12
	} else if (typeof module === "object" && module.exports) {
13
		module.exports = factory( require( "jquery" ) );
14
	} else {
15
		factory( jQuery );
16
	}
17
}(function( $ ) {
18

19
$.extend( $.fn, {
20

21
	// https://jqueryvalidation.org/validate/
22
	validate: function( options ) {
23

24
		// If nothing is selected, return nothing; can't chain anyway
25
		if ( !this.length ) {
26
			if ( options && options.debug && window.console ) {
27
				console.warn( "Nothing selected, can't validate, returning nothing." );
28
			}
29
			return;
30
		}
31

32
		// Check if a validator for this form was already created
33
		var validator = $.data( this[ 0 ], "validator" );
34
		if ( validator ) {
35
			return validator;
36
		}
37

38
		// Add novalidate tag if HTML5.
39
		this.attr( "novalidate", "novalidate" );
40

41
		validator = new $.validator( options, this[ 0 ] );
42
		$.data( this[ 0 ], "validator", validator );
43

44
		if ( validator.settings.onsubmit ) {
45

46
			this.on( "click.validate", ":submit", function( event ) {
47

48
				// Track the used submit button to properly handle scripted
49
				// submits later.
50
				validator.submitButton = event.currentTarget;
51

52
				// Allow suppressing validation by adding a cancel class to the submit button
53
				if ( $( this ).hasClass( "cancel" ) ) {
54
					validator.cancelSubmit = true;
55
				}
56

57
				// Allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
58
				if ( $( this ).attr( "formnovalidate" ) !== undefined ) {
59
					validator.cancelSubmit = true;
60
				}
61
			} );
62

63
			// Validate the form on submit
64
			this.on( "submit.validate", function( event ) {
65
				if ( validator.settings.debug ) {
66

67
					// Prevent form submit to be able to see console output
68
					event.preventDefault();
69
				}
70

71
				function handle() {
72
					var hidden, result;
73

74
					// Insert a hidden input as a replacement for the missing submit button
75
					// The hidden input is inserted in two cases:
76
					//   - A user defined a `submitHandler`
77
					//   - There was a pending request due to `remote` method and `stopRequest()`
78
					//     was called to submit the form in case it's valid
79
					if ( validator.submitButton && ( validator.settings.submitHandler || validator.formSubmitted ) ) {
80
						hidden = $( "<input type='hidden'/>" )
81
							.attr( "name", validator.submitButton.name )
82
							.val( $( validator.submitButton ).val() )
83
							.appendTo( validator.currentForm );
84
					}
85

86
					if ( validator.settings.submitHandler && !validator.settings.debug ) {
87
						result = validator.settings.submitHandler.call( validator, validator.currentForm, event );
88
						if ( hidden ) {
89

90
							// And clean up afterwards; thanks to no-block-scope, hidden can be referenced
91
							hidden.remove();
92
						}
93
						if ( result !== undefined ) {
94
							return result;
95
						}
96
						return false;
97
					}
98
					return true;
99
				}
100

101
				// Prevent submit for invalid forms or custom submit handlers
102
				if ( validator.cancelSubmit ) {
103
					validator.cancelSubmit = false;
104
					return handle();
105
				}
106
				if ( validator.form() ) {
107
					if ( validator.pendingRequest ) {
108
						validator.formSubmitted = true;
109
						return false;
110
					}
111
					return handle();
112
				} else {
113
					validator.focusInvalid();
114
					return false;
115
				}
116
			} );
117
		}
118

119
		return validator;
120
	},
121

122
	// https://jqueryvalidation.org/valid/
123
	valid: function() {
124
		var valid, validator, errorList;
125

126
		if ( $( this[ 0 ] ).is( "form" ) ) {
127
			valid = this.validate().form();
128
		} else {
129
			errorList = [];
130
			valid = true;
131
			validator = $( this[ 0 ].form ).validate();
132
			this.each( function() {
133
				valid = validator.element( this ) && valid;
134
				if ( !valid ) {
135
					errorList = errorList.concat( validator.errorList );
136
				}
137
			} );
138
			validator.errorList = errorList;
139
		}
140
		return valid;
141
	},
142

143
	// https://jqueryvalidation.org/rules/
144
	rules: function( command, argument ) {
145
		var element = this[ 0 ],
146
			isContentEditable = typeof this.attr( "contenteditable" ) !== "undefined" && this.attr( "contenteditable" ) !== "false",
147
			settings, staticRules, existingRules, data, param, filtered;
148

149
		// If nothing is selected, return empty object; can't chain anyway
150
		if ( element == null ) {
151
			return;
152
		}
153

154
		if ( !element.form && isContentEditable ) {
155
			element.form = this.closest( "form" )[ 0 ];
156
			element.name = this.attr( "name" );
157
		}
158

159
		if ( element.form == null ) {
160
			return;
161
		}
162

163
		if ( command ) {
164
			settings = $.data( element.form, "validator" ).settings;
165
			staticRules = settings.rules;
166
			existingRules = $.validator.staticRules( element );
167
			switch ( command ) {
168
			case "add":
169
				$.extend( existingRules, $.validator.normalizeRule( argument ) );
170

171
				// Remove messages from rules, but allow them to be set separately
172
				delete existingRules.messages;
173
				staticRules[ element.name ] = existingRules;
174
				if ( argument.messages ) {
175
					settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages );
176
				}
177
				break;
178
			case "remove":
179
				if ( !argument ) {
180
					delete staticRules[ element.name ];
181
					return existingRules;
182
				}
183
				filtered = {};
184
				$.each( argument.split( /\s/ ), function( index, method ) {
185
					filtered[ method ] = existingRules[ method ];
186
					delete existingRules[ method ];
187
				} );
188
				return filtered;
189
			}
190
		}
191

192
		data = $.validator.normalizeRules(
193
		$.extend(
194
			{},
195
			$.validator.classRules( element ),
196
			$.validator.attributeRules( element ),
197
			$.validator.dataRules( element ),
198
			$.validator.staticRules( element )
199
		), element );
200

201
		// Make sure required is at front
202
		if ( data.required ) {
203
			param = data.required;
204
			delete data.required;
205
			data = $.extend( { required: param }, data );
206
		}
207

208
		// Make sure remote is at back
209
		if ( data.remote ) {
210
			param = data.remote;
211
			delete data.remote;
212
			data = $.extend( data, { remote: param } );
213
		}
214

215
		return data;
216
	}
217
} );
218

219
// JQuery trim is deprecated, provide a trim method based on String.prototype.trim
220
var trim = function( str ) {
221

222
	// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim#Polyfill
223
	return str.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "" );
224
};
225

226
// Custom selectors
227
$.extend( $.expr.pseudos || $.expr[ ":" ], {		// '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support
228

229
	// https://jqueryvalidation.org/blank-selector/
230
	blank: function( a ) {
231
		return !trim( "" + $( a ).val() );
232
	},
233

234
	// https://jqueryvalidation.org/filled-selector/
235
	filled: function( a ) {
236
		var val = $( a ).val();
237
		return val !== null && !!trim( "" + val );
238
	},
239

240
	// https://jqueryvalidation.org/unchecked-selector/
241
	unchecked: function( a ) {
242
		return !$( a ).prop( "checked" );
243
	}
244
} );
245

246
// Constructor for validator
247
$.validator = function( options, form ) {
248
	this.settings = $.extend( true, {}, $.validator.defaults, options );
249
	this.currentForm = form;
250
	this.init();
251
};
252

253
// https://jqueryvalidation.org/jQuery.validator.format/
254
$.validator.format = function( source, params ) {
255
	if ( arguments.length === 1 ) {
256
		return function() {
257
			var args = $.makeArray( arguments );
258
			args.unshift( source );
259
			return $.validator.format.apply( this, args );
260
		};
261
	}
262
	if ( params === undefined ) {
263
		return source;
264
	}
265
	if ( arguments.length > 2 && params.constructor !== Array  ) {
266
		params = $.makeArray( arguments ).slice( 1 );
267
	}
268
	if ( params.constructor !== Array ) {
269
		params = [ params ];
270
	}
271
	$.each( params, function( i, n ) {
272
		source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() {
273
			return n;
274
		} );
275
	} );
276
	return source;
277
};
278

279
$.extend( $.validator, {
280

281
	defaults: {
282
		messages: {},
283
		groups: {},
284
		rules: {},
285
		errorClass: "error",
286
		pendingClass: "pending",
287
		validClass: "valid",
288
		errorElement: "label",
289
		focusCleanup: false,
290
		focusInvalid: true,
291
		errorContainer: $( [] ),
292
		errorLabelContainer: $( [] ),
293
		onsubmit: true,
294
		ignore: ":hidden",
295
		ignoreTitle: false,
296
		onfocusin: function( element ) {
297
			this.lastActive = element;
298

299
			// Hide error label and remove error class on focus if enabled
300
			if ( this.settings.focusCleanup ) {
301
				if ( this.settings.unhighlight ) {
302
					this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
303
				}
304
				this.hideThese( this.errorsFor( element ) );
305
			}
306
		},
307
		onfocusout: function( element ) {
308
			if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) {
309
				this.element( element );
310
			}
311
		},
312
		onkeyup: function( element, event ) {
313

314
			// Avoid revalidate the field when pressing one of the following keys
315
			// Shift       => 16
316
			// Ctrl        => 17
317
			// Alt         => 18
318
			// Caps lock   => 20
319
			// End         => 35
320
			// Home        => 36
321
			// Left arrow  => 37
322
			// Up arrow    => 38
323
			// Right arrow => 39
324
			// Down arrow  => 40
325
			// Insert      => 45
326
			// Num lock    => 144
327
			// AltGr key   => 225
328
			var excludedKeys = [
329
				16, 17, 18, 20, 35, 36, 37,
330
				38, 39, 40, 45, 144, 225
331
			];
332

333
			if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
334
				return;
335
			} else if ( element.name in this.submitted || element.name in this.invalid ) {
336
				this.element( element );
337
			}
338
		},
339
		onclick: function( element ) {
340

341
			// Click on selects, radiobuttons and checkboxes
342
			if ( element.name in this.submitted ) {
343
				this.element( element );
344

345
			// Or option elements, check parent select in that case
346
			} else if ( element.parentNode.name in this.submitted ) {
347
				this.element( element.parentNode );
348
			}
349
		},
350
		highlight: function( element, errorClass, validClass ) {
351
			if ( element.type === "radio" ) {
352
				this.findByName( element.name ).addClass( errorClass ).removeClass( validClass );
353
			} else {
354
				$( element ).addClass( errorClass ).removeClass( validClass );
355
			}
356
		},
357
		unhighlight: function( element, errorClass, validClass ) {
358
			if ( element.type === "radio" ) {
359
				this.findByName( element.name ).removeClass( errorClass ).addClass( validClass );
360
			} else {
361
				$( element ).removeClass( errorClass ).addClass( validClass );
362
			}
363
		}
364
	},
365

366
	// https://jqueryvalidation.org/jQuery.validator.setDefaults/
367
	setDefaults: function( settings ) {
368
		$.extend( $.validator.defaults, settings );
369
	},
370

371
	messages: {
372
		required: "This field is required.",
373
		remote: "Please fix this field.",
374
		email: "Please enter a valid email address.",
375
		url: "Please enter a valid URL.",
376
		date: "Please enter a valid date.",
377
		dateISO: "Please enter a valid date (ISO).",
378
		number: "Please enter a valid number.",
379
		digits: "Please enter only digits.",
380
		equalTo: "Please enter the same value again.",
381
		maxlength: $.validator.format( "Please enter no more than {0} characters." ),
382
		minlength: $.validator.format( "Please enter at least {0} characters." ),
383
		rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
384
		range: $.validator.format( "Please enter a value between {0} and {1}." ),
385
		max: $.validator.format( "Please enter a value less than or equal to {0}." ),
386
		min: $.validator.format( "Please enter a value greater than or equal to {0}." ),
387
		step: $.validator.format( "Please enter a multiple of {0}." )
388
	},
389

390
	autoCreateRanges: false,
391

392
	prototype: {
393

394
		init: function() {
395
			this.labelContainer = $( this.settings.errorLabelContainer );
396
			this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm );
397
			this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
398
			this.submitted = {};
399
			this.valueCache = {};
400
			this.pendingRequest = 0;
401
			this.pending = {};
402
			this.invalid = {};
403
			this.reset();
404

405
			var currentForm = this.currentForm,
406
				groups = ( this.groups = {} ),
407
				rules;
408
			$.each( this.settings.groups, function( key, value ) {
409
				if ( typeof value === "string" ) {
410
					value = value.split( /\s/ );
411
				}
412
				$.each( value, function( index, name ) {
413
					groups[ name ] = key;
414
				} );
415
			} );
416
			rules = this.settings.rules;
417
			$.each( rules, function( key, value ) {
418
				rules[ key ] = $.validator.normalizeRule( value );
419
			} );
420

421
			function delegate( event ) {
422
				var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
423

424
				// Set form expando on contenteditable
425
				if ( !this.form && isContentEditable ) {
426
					this.form = $( this ).closest( "form" )[ 0 ];
427
					this.name = $( this ).attr( "name" );
428
				}
429

430
				// Ignore the element if it belongs to another form. This will happen mainly
431
				// when setting the `form` attribute of an input to the id of another form.
432
				if ( currentForm !== this.form ) {
433
					return;
434
				}
435

436
				var validator = $.data( this.form, "validator" ),
437
					eventType = "on" + event.type.replace( /^validate/, "" ),
438
					settings = validator.settings;
439
				if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
440
					settings[ eventType ].call( validator, this, event );
441
				}
442
			}
443

444
			$( this.currentForm )
445
				.on( "focusin.validate focusout.validate keyup.validate",
446
					":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
447
					"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
448
					"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
449
					"[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
450

451
				// Support: Chrome, oldIE
452
				// "select" is provided as event.target when clicking a option
453
				.on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate );
454

455
			if ( this.settings.invalidHandler ) {
456
				$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
457
			}
458
		},
459

460
		// https://jqueryvalidation.org/Validator.form/
461
		form: function() {
462
			this.checkForm();
463
			$.extend( this.submitted, this.errorMap );
464
			this.invalid = $.extend( {}, this.errorMap );
465
			if ( !this.valid() ) {
466
				$( this.currentForm ).triggerHandler( "invalid-form", [ this ] );
467
			}
468
			this.showErrors();
469
			return this.valid();
470
		},
471

472
		checkForm: function() {
473
			this.prepareForm();
474
			for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
475
				this.check( elements[ i ] );
476
			}
477
			return this.valid();
478
		},
479

480
		// https://jqueryvalidation.org/Validator.element/
481
		element: function( element ) {
482
			var cleanElement = this.clean( element ),
483
				checkElement = this.validationTargetFor( cleanElement ),
484
				v = this,
485
				result = true,
486
				rs, group;
487

488
			if ( checkElement === undefined ) {
489
				delete this.invalid[ cleanElement.name ];
490
			} else {
491
				this.prepareElement( checkElement );
492
				this.currentElements = $( checkElement );
493

494
				// If this element is grouped, then validate all group elements already
495
				// containing a value
496
				group = this.groups[ checkElement.name ];
497
				if ( group ) {
498
					$.each( this.groups, function( name, testgroup ) {
499
						if ( testgroup === group && name !== checkElement.name ) {
500
							cleanElement = v.validationTargetFor( v.clean( v.findByName( name ) ) );
501
							if ( cleanElement && cleanElement.name in v.invalid ) {
502
								v.currentElements.push( cleanElement );
503
								result = v.check( cleanElement ) && result;
504
							}
505
						}
506
					} );
507
				}
508

509
				rs = this.check( checkElement ) !== false;
510
				result = result && rs;
511
				if ( rs ) {
512
					this.invalid[ checkElement.name ] = false;
513
				} else {
514
					this.invalid[ checkElement.name ] = true;
515
				}
516

517
				if ( !this.numberOfInvalids() ) {
518

519
					// Hide error containers on last error
520
					this.toHide = this.toHide.add( this.containers );
521
				}
522
				this.showErrors();
523

524
				// Add aria-invalid status for screen readers
525
				$( element ).attr( "aria-invalid", !rs );
526
			}
527

528
			return result;
529
		},
530

531
		// https://jqueryvalidation.org/Validator.showErrors/
532
		showErrors: function( errors ) {
533
			if ( errors ) {
534
				var validator = this;
535

536
				// Add items to error list and map
537
				$.extend( this.errorMap, errors );
538
				this.errorList = $.map( this.errorMap, function( message, name ) {
539
					return {
540
						message: message,
541
						element: validator.findByName( name )[ 0 ]
542
					};
543
				} );
544

545
				// Remove items from success list
546
				this.successList = $.grep( this.successList, function( element ) {
547
					return !( element.name in errors );
548
				} );
549
			}
550
			if ( this.settings.showErrors ) {
551
				this.settings.showErrors.call( this, this.errorMap, this.errorList );
552
			} else {
553
				this.defaultShowErrors();
554
			}
555
		},
556

557
		// https://jqueryvalidation.org/Validator.resetForm/
558
		resetForm: function() {
559
			if ( $.fn.resetForm ) {
560
				$( this.currentForm ).resetForm();
561
			}
562
			this.invalid = {};
563
			this.submitted = {};
564
			this.prepareForm();
565
			this.hideErrors();
566
			var elements = this.elements()
567
				.removeData( "previousValue" )
568
				.removeAttr( "aria-invalid" );
569

570
			this.resetElements( elements );
571
		},
572

573
		resetElements: function( elements ) {
574
			var i;
575

576
			if ( this.settings.unhighlight ) {
577
				for ( i = 0; elements[ i ]; i++ ) {
578
					this.settings.unhighlight.call( this, elements[ i ],
579
						this.settings.errorClass, "" );
580
					this.findByName( elements[ i ].name ).removeClass( this.settings.validClass );
581
				}
582
			} else {
583
				elements
584
					.removeClass( this.settings.errorClass )
585
					.removeClass( this.settings.validClass );
586
			}
587
		},
588

589
		numberOfInvalids: function() {
590
			return this.objectLength( this.invalid );
591
		},
592

593
		objectLength: function( obj ) {
594
			/* jshint unused: false */
595
			var count = 0,
596
				i;
597
			for ( i in obj ) {
598

599
				// This check allows counting elements with empty error
600
				// message as invalid elements
601
				if ( obj[ i ] !== undefined && obj[ i ] !== null && obj[ i ] !== false ) {
602
					count++;
603
				}
604
			}
605
			return count;
606
		},
607

608
		hideErrors: function() {
609
			this.hideThese( this.toHide );
610
		},
611

612
		hideThese: function( errors ) {
613
			errors.not( this.containers ).text( "" );
614
			this.addWrapper( errors ).hide();
615
		},
616

617
		valid: function() {
618
			return this.size() === 0;
619
		},
620

621
		size: function() {
622
			return this.errorList.length;
623
		},
624

625
		focusInvalid: function() {
626
			if ( this.settings.focusInvalid ) {
627
				try {
628
					$( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [] )
629
					.filter( ":visible" )
630
					.trigger( "focus" )
631

632
					// Manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
633
					.trigger( "focusin" );
634
				} catch ( e ) {
635

636
					// Ignore IE throwing errors when focusing hidden elements
637
				}
638
			}
639
		},
640

641
		findLastActive: function() {
642
			var lastActive = this.lastActive;
643
			return lastActive && $.grep( this.errorList, function( n ) {
644
				return n.element.name === lastActive.name;
645
			} ).length === 1 && lastActive;
646
		},
647

648
		elements: function() {
649
			var validator = this,
650
				rulesCache = {};
651

652
			// Select all valid inputs inside the form (no submit or reset buttons)
653
			return $( this.currentForm )
654
			.find( "input, select, textarea, [contenteditable]" )
655
			.not( ":submit, :reset, :image, :disabled" )
656
			.not( this.settings.ignore )
657
			.filter( function() {
658
				var name = this.name || $( this ).attr( "name" ); // For contenteditable
659
				var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
660

661
				if ( !name && validator.settings.debug && window.console ) {
662
					console.error( "%o has no name assigned", this );
663
				}
664

665
				// Set form expando on contenteditable
666
				if ( isContentEditable ) {
667
					this.form = $( this ).closest( "form" )[ 0 ];
668
					this.name = name;
669
				}
670

671
				// Ignore elements that belong to other/nested forms
672
				if ( this.form !== validator.currentForm ) {
673
					return false;
674
				}
675

676
				// Select only the first element for each name, and only those with rules specified
677
				if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
678
					return false;
679
				}
680

681
				rulesCache[ name ] = true;
682
				return true;
683
			} );
684
		},
685

686
		clean: function( selector ) {
687
			return $( selector )[ 0 ];
688
		},
689

690
		errors: function() {
691
			var errorClass = this.settings.errorClass.split( " " ).join( "." );
692
			return $( this.settings.errorElement + "." + errorClass, this.errorContext );
693
		},
694

695
		resetInternals: function() {
696
			this.successList = [];
697
			this.errorList = [];
698
			this.errorMap = {};
699
			this.toShow = $( [] );
700
			this.toHide = $( [] );
701
		},
702

703
		reset: function() {
704
			this.resetInternals();
705
			this.currentElements = $( [] );
706
		},
707

708
		prepareForm: function() {
709
			this.reset();
710
			this.toHide = this.errors().add( this.containers );
711
		},
712

713
		prepareElement: function( element ) {
714
			this.reset();
715
			this.toHide = this.errorsFor( element );
716
		},
717

718
		elementValue: function( element ) {
719
			var $element = $( element ),
720
				type = element.type,
721
				isContentEditable = typeof $element.attr( "contenteditable" ) !== "undefined" && $element.attr( "contenteditable" ) !== "false",
722
				val, idx;
723

724
			if ( type === "radio" || type === "checkbox" ) {
725
				return this.findByName( element.name ).filter( ":checked" ).val();
726
			} else if ( type === "number" && typeof element.validity !== "undefined" ) {
727
				return element.validity.badInput ? "NaN" : $element.val();
728
			}
729

730
			if ( isContentEditable ) {
731
				val = $element.text();
732
			} else {
733
				val = $element.val();
734
			}
735

736
			if ( type === "file" ) {
737

738
				// Modern browser (chrome & safari)
739
				if ( val.substr( 0, 12 ) === "C:\\fakepath\\" ) {
740
					return val.substr( 12 );
741
				}
742

743
				// Legacy browsers
744
				// Unix-based path
745
				idx = val.lastIndexOf( "/" );
746
				if ( idx >= 0 ) {
747
					return val.substr( idx + 1 );
748
				}
749

750
				// Windows-based path
751
				idx = val.lastIndexOf( "\\" );
752
				if ( idx >= 0 ) {
753
					return val.substr( idx + 1 );
754
				}
755

756
				// Just the file name
757
				return val;
758
			}
759

760
			if ( typeof val === "string" ) {
761
				return val.replace( /\r/g, "" );
762
			}
763
			return val;
764
		},
765

766
		check: function( element ) {
767
			element = this.validationTargetFor( this.clean( element ) );
768

769
			var rules = $( element ).rules(),
770
				rulesCount = $.map( rules, function( n, i ) {
771
					return i;
772
				} ).length,
773
				dependencyMismatch = false,
774
				val = this.elementValue( element ),
775
				result, method, rule, normalizer;
776

777
			// Prioritize the local normalizer defined for this element over the global one
778
			// if the former exists, otherwise user the global one in case it exists.
779
			if ( typeof rules.normalizer === "function" ) {
780
				normalizer = rules.normalizer;
781
			} else if (	typeof this.settings.normalizer === "function" ) {
782
				normalizer = this.settings.normalizer;
783
			}
784

785
			// If normalizer is defined, then call it to retreive the changed value instead
786
			// of using the real one.
787
			// Note that `this` in the normalizer is `element`.
788
			if ( normalizer ) {
789
				val = normalizer.call( element, val );
790

791
				// Delete the normalizer from rules to avoid treating it as a pre-defined method.
792
				delete rules.normalizer;
793
			}
794

795
			for ( method in rules ) {
796
				rule = { method: method, parameters: rules[ method ] };
797
				try {
798
					result = $.validator.methods[ method ].call( this, val, element, rule.parameters );
799

800
					// If a method indicates that the field is optional and therefore valid,
801
					// don't mark it as valid when there are no other rules
802
					if ( result === "dependency-mismatch" && rulesCount === 1 ) {
803
						dependencyMismatch = true;
804
						continue;
805
					}
806
					dependencyMismatch = false;
807

808
					if ( result === "pending" ) {
809
						this.toHide = this.toHide.not( this.errorsFor( element ) );
810
						return;
811
					}
812

813
					if ( !result ) {
814
						this.formatAndAdd( element, rule );
815
						return false;
816
					}
817
				} catch ( e ) {
818
					if ( this.settings.debug && window.console ) {
819
						console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
820
					}
821
					if ( e instanceof TypeError ) {
822
						e.message += ".  Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.";
823
					}
824

825
					throw e;
826
				}
827
			}
828
			if ( dependencyMismatch ) {
829
				return;
830
			}
831
			if ( this.objectLength( rules ) ) {
832
				this.successList.push( element );
833
			}
834
			return true;
835
		},
836

837
		// Return the custom message for the given element and validation method
838
		// specified in the element's HTML5 data attribute
839
		// return the generic message if present and no method specific message is present
840
		customDataMessage: function( element, method ) {
841
			return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() +
842
				method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" );
843
		},
844

845
		// Return the custom message for the given element name and validation method
846
		customMessage: function( name, method ) {
847
			var m = this.settings.messages[ name ];
848
			return m && ( m.constructor === String ? m : m[ method ] );
849
		},
850

851
		// Return the first defined argument, allowing empty strings
852
		findDefined: function() {
853
			for ( var i = 0; i < arguments.length; i++ ) {
854
				if ( arguments[ i ] !== undefined ) {
855
					return arguments[ i ];
856
				}
857
			}
858
			return undefined;
859
		},
860

861
		// The second parameter 'rule' used to be a string, and extended to an object literal
862
		// of the following form:
863
		// rule = {
864
		//     method: "method name",
865
		//     parameters: "the given method parameters"
866
		// }
867
		//
868
		// The old behavior still supported, kept to maintain backward compatibility with
869
		// old code, and will be removed in the next major release.
870
		defaultMessage: function( element, rule ) {
871
			if ( typeof rule === "string" ) {
872
				rule = { method: rule };
873
			}
874

875
			var message = this.findDefined(
876
					this.customMessage( element.name, rule.method ),
877
					this.customDataMessage( element, rule.method ),
878

879
					// 'title' is never undefined, so handle empty string as undefined
880
					!this.settings.ignoreTitle && element.title || undefined,
881
					$.validator.messages[ rule.method ],
882
					"<strong>Warning: No message defined for " + element.name + "</strong>"
883
				),
884
				theregex = /\$?\{(\d+)\}/g;
885
			if ( typeof message === "function" ) {
886
				message = message.call( this, rule.parameters, element );
887
			} else if ( theregex.test( message ) ) {
888
				message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters );
889
			}
890

891
			return message;
892
		},
893

894
		formatAndAdd: function( element, rule ) {
895
			var message = this.defaultMessage( element, rule );
896

897
			this.errorList.push( {
898
				message: message,
899
				element: element,
900
				method: rule.method
901
			} );
902

903
			this.errorMap[ element.name ] = message;
904
			this.submitted[ element.name ] = message;
905
		},
906

907
		addWrapper: function( toToggle ) {
908
			if ( this.settings.wrapper ) {
909
				toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
910
			}
911
			return toToggle;
912
		},
913

914
		defaultShowErrors: function() {
915
			var i, elements, error;
916
			for ( i = 0; this.errorList[ i ]; i++ ) {
917
				error = this.errorList[ i ];
918
				if ( this.settings.highlight ) {
919
					this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
920
				}
921
				this.showLabel( error.element, error.message );
922
			}
923
			if ( this.errorList.length ) {
924
				this.toShow = this.toShow.add( this.containers );
925
			}
926
			if ( this.settings.success ) {
927
				for ( i = 0; this.successList[ i ]; i++ ) {
928
					this.showLabel( this.successList[ i ] );
929
				}
930
			}
931
			if ( this.settings.unhighlight ) {
932
				for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) {
933
					this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass );
934
				}
935
			}
936
			this.toHide = this.toHide.not( this.toShow );
937
			this.hideErrors();
938
			this.addWrapper( this.toShow ).show();
939
		},
940

941
		validElements: function() {
942
			return this.currentElements.not( this.invalidElements() );
943
		},
944

945
		invalidElements: function() {
946
			return $( this.errorList ).map( function() {
947
				return this.element;
948
			} );
949
		},
950

951
		showLabel: function( element, message ) {
952
			var place, group, errorID, v,
953
				error = this.errorsFor( element ),
954
				elementID = this.idOrName( element ),
955
				describedBy = $( element ).attr( "aria-describedby" );
956

957
			if ( error.length ) {
958

959
				// Refresh error/success class
960
				error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
961

962
				// Replace message on existing label
963
				error.html( message );
964
			} else {
965

966
				// Create error element
967
				error = $( "<" + this.settings.errorElement + ">" )
968
					.attr( "id", elementID + "-error" )
969
					.addClass( this.settings.errorClass )
970
					.html( message || "" );
971

972
				// Maintain reference to the element to be placed into the DOM
973
				place = error;
974
				if ( this.settings.wrapper ) {
975

976
					// Make sure the element is visible, even in IE
977
					// actually showing the wrapped element is handled elsewhere
978
					place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent();
979
				}
980
				if ( this.labelContainer.length ) {
981
					this.labelContainer.append( place );
982
				} else if ( this.settings.errorPlacement ) {
983
					this.settings.errorPlacement.call( this, place, $( element ) );
984
				} else {
985
					place.insertAfter( element );
986
				}
987

988
				// Link error back to the element
989
				if ( error.is( "label" ) ) {
990

991
					// If the error is a label, then associate using 'for'
992
					error.attr( "for", elementID );
993

994
					// If the element is not a child of an associated label, then it's necessary
995
					// to explicitly apply aria-describedby
996
				} else if ( error.parents( "label[for='" + this.escapeCssMeta( elementID ) + "']" ).length === 0 ) {
997
					errorID = error.attr( "id" );
998

999
					// Respect existing non-error aria-describedby
1000
					if ( !describedBy ) {
1001
						describedBy = errorID;
1002
					} else if ( !describedBy.match( new RegExp( "\\b" + this.escapeCssMeta( errorID ) + "\\b" ) ) ) {
1003

1004
						// Add to end of list if not already present
1005
						describedBy += " " + errorID;
1006
					}
1007
					$( element ).attr( "aria-describedby", describedBy );
1008

1009
					// If this element is grouped, then assign to all elements in the same group
1010
					group = this.groups[ element.name ];
1011
					if ( group ) {
1012
						v = this;
1013
						$.each( v.groups, function( name, testgroup ) {
1014
							if ( testgroup === group ) {
1015
								$( "[name='" + v.escapeCssMeta( name ) + "']", v.currentForm )
1016
									.attr( "aria-describedby", error.attr( "id" ) );
1017
							}
1018
						} );
1019
					}
1020
				}
1021
			}
1022
			if ( !message && this.settings.success ) {
1023
				error.text( "" );
1024
				if ( typeof this.settings.success === "string" ) {
1025
					error.addClass( this.settings.success );
1026
				} else {
1027
					this.settings.success( error, element );
1028
				}
1029
			}
1030
			this.toShow = this.toShow.add( error );
1031
		},
1032

1033
		errorsFor: function( element ) {
1034
			var name = this.escapeCssMeta( this.idOrName( element ) ),
1035
				describer = $( element ).attr( "aria-describedby" ),
1036
				selector = "label[for='" + name + "'], label[for='" + name + "'] *";
1037

1038
			// 'aria-describedby' should directly reference the error element
1039
			if ( describer ) {
1040
				selector = selector + ", #" + this.escapeCssMeta( describer )
1041
					.replace( /\s+/g, ", #" );
1042
			}
1043

1044
			return this
1045
				.errors()
1046
				.filter( selector );
1047
		},
1048

1049
		// See https://api.jquery.com/category/selectors/, for CSS
1050
		// meta-characters that should be escaped in order to be used with JQuery
1051
		// as a literal part of a name/id or any selector.
1052
		escapeCssMeta: function( string ) {
1053
			return string.replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" );
1054
		},
1055

1056
		idOrName: function( element ) {
1057
			return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name );
1058
		},
1059

1060
		validationTargetFor: function( element ) {
1061

1062
			// If radio/checkbox, validate first element in group instead
1063
			if ( this.checkable( element ) ) {
1064
				element = this.findByName( element.name );
1065
			}
1066

1067
			// Always apply ignore filter
1068
			return $( element ).not( this.settings.ignore )[ 0 ];
1069
		},
1070

1071
		checkable: function( element ) {
1072
			return ( /radio|checkbox/i ).test( element.type );
1073
		},
1074

1075
		findByName: function( name ) {
1076
			return $( this.currentForm ).find( "[name='" + this.escapeCssMeta( name ) + "']" );
1077
		},
1078

1079
		getLength: function( value, element ) {
1080
			switch ( element.nodeName.toLowerCase() ) {
1081
			case "select":
1082
				return $( "option:selected", element ).length;
1083
			case "input":
1084
				if ( this.checkable( element ) ) {
1085
					return this.findByName( element.name ).filter( ":checked" ).length;
1086
				}
1087
			}
1088
			return value.length;
1089
		},
1090

1091
		depend: function( param, element ) {
1092
			return this.dependTypes[ typeof param ] ? this.dependTypes[ typeof param ]( param, element ) : true;
1093
		},
1094

1095
		dependTypes: {
1096
			"boolean": function( param ) {
1097
				return param;
1098
			},
1099
			"string": function( param, element ) {
1100
				return !!$( param, element.form ).length;
1101
			},
1102
			"function": function( param, element ) {
1103
				return param( element );
1104
			}
1105
		},
1106

1107
		optional: function( element ) {
1108
			var val = this.elementValue( element );
1109
			return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
1110
		},
1111

1112
		startRequest: function( element ) {
1113
			if ( !this.pending[ element.name ] ) {
1114
				this.pendingRequest++;
1115
				$( element ).addClass( this.settings.pendingClass );
1116
				this.pending[ element.name ] = true;
1117
			}
1118
		},
1119

1120
		stopRequest: function( element, valid ) {
1121
			this.pendingRequest--;
1122

1123
			// Sometimes synchronization fails, make sure pendingRequest is never < 0
1124
			if ( this.pendingRequest < 0 ) {
1125
				this.pendingRequest = 0;
1126
			}
1127
			delete this.pending[ element.name ];
1128
			$( element ).removeClass( this.settings.pendingClass );
1129
			if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
1130
				$( this.currentForm ).submit();
1131

1132
				// Remove the hidden input that was used as a replacement for the
1133
				// missing submit button. The hidden input is added by `handle()`
1134
				// to ensure that the value of the used submit button is passed on
1135
				// for scripted submits triggered by this method
1136
				if ( this.submitButton ) {
1137
					$( "input:hidden[name='" + this.submitButton.name + "']", this.currentForm ).remove();
1138
				}
1139

1140
				this.formSubmitted = false;
1141
			} else if ( !valid && this.pendingRequest === 0 && this.formSubmitted ) {
1142
				$( this.currentForm ).triggerHandler( "invalid-form", [ this ] );
1143
				this.formSubmitted = false;
1144
			}
1145
		},
1146

1147
		previousValue: function( element, method ) {
1148
			method = typeof method === "string" && method || "remote";
1149

1150
			return $.data( element, "previousValue" ) || $.data( element, "previousValue", {
1151
				old: null,
1152
				valid: true,
1153
				message: this.defaultMessage( element, { method: method } )
1154
			} );
1155
		},
1156

1157
		// Cleans up all forms and elements, removes validator-specific events
1158
		destroy: function() {
1159
			this.resetForm();
1160

1161
			$( this.currentForm )
1162
				.off( ".validate" )
1163
				.removeData( "validator" )
1164
				.find( ".validate-equalTo-blur" )
1165
					.off( ".validate-equalTo" )
1166
					.removeClass( "validate-equalTo-blur" )
1167
				.find( ".validate-lessThan-blur" )
1168
					.off( ".validate-lessThan" )
1169
					.removeClass( "validate-lessThan-blur" )
1170
				.find( ".validate-lessThanEqual-blur" )
1171
					.off( ".validate-lessThanEqual" )
1172
					.removeClass( "validate-lessThanEqual-blur" )
1173
				.find( ".validate-greaterThanEqual-blur" )
1174
					.off( ".validate-greaterThanEqual" )
1175
					.removeClass( "validate-greaterThanEqual-blur" )
1176
				.find( ".validate-greaterThan-blur" )
1177
					.off( ".validate-greaterThan" )
1178
					.removeClass( "validate-greaterThan-blur" );
1179
		}
1180

1181
	},
1182

1183
	classRuleSettings: {
1184
		required: { required: true },
1185
		email: { email: true },
1186
		url: { url: true },
1187
		date: { date: true },
1188
		dateISO: { dateISO: true },
1189
		number: { number: true },
1190
		digits: { digits: true },
1191
		creditcard: { creditcard: true }
1192
	},
1193

1194
	addClassRules: function( className, rules ) {
1195
		if ( className.constructor === String ) {
1196
			this.classRuleSettings[ className ] = rules;
1197
		} else {
1198
			$.extend( this.classRuleSettings, className );
1199
		}
1200
	},
1201

1202
	classRules: function( element ) {
1203
		var rules = {},
1204
			classes = $( element ).attr( "class" );
1205

1206
		if ( classes ) {
1207
			$.each( classes.split( " " ), function() {
1208
				if ( this in $.validator.classRuleSettings ) {
1209
					$.extend( rules, $.validator.classRuleSettings[ this ] );
1210
				}
1211
			} );
1212
		}
1213
		return rules;
1214
	},
1215

1216
	normalizeAttributeRule: function( rules, type, method, value ) {
1217

1218
		// Convert the value to a number for number inputs, and for text for backwards compability
1219
		// allows type="date" and others to be compared as strings
1220
		if ( /min|max|step/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
1221
			value = Number( value );
1222

1223
			// Support Opera Mini, which returns NaN for undefined minlength
1224
			if ( isNaN( value ) ) {
1225
				value = undefined;
1226
			}
1227
		}
1228

1229
		if ( value || value === 0 ) {
1230
			rules[ method ] = value;
1231
		} else if ( type === method && type !== "range" ) {
1232

1233
			// Exception: the jquery validate 'range' method
1234
			// does not test for the html5 'range' type
1235
			rules[ method ] = true;
1236
		}
1237
	},
1238

1239
	attributeRules: function( element ) {
1240
		var rules = {},
1241
			$element = $( element ),
1242
			type = element.getAttribute( "type" ),
1243
			method, value;
1244

1245
		for ( method in $.validator.methods ) {
1246

1247
			// Support for <input required> in both html5 and older browsers
1248
			if ( method === "required" ) {
1249
				value = element.getAttribute( method );
1250

1251
				// Some browsers return an empty string for the required attribute
1252
				// and non-HTML5 browsers might have required="" markup
1253
				if ( value === "" ) {
1254
					value = true;
1255
				}
1256

1257
				// Force non-HTML5 browsers to return bool
1258
				value = !!value;
1259
			} else {
1260
				value = $element.attr( method );
1261
			}
1262

1263
			this.normalizeAttributeRule( rules, type, method, value );
1264
		}
1265

1266
		// 'maxlength' may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs
1267
		if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) {
1268
			delete rules.maxlength;
1269
		}
1270

1271
		return rules;
1272
	},
1273

1274
	dataRules: function( element ) {
1275
		var rules = {},
1276
			$element = $( element ),
1277
			type = element.getAttribute( "type" ),
1278
			method, value;
1279

1280
		for ( method in $.validator.methods ) {
1281
			value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() );
1282

1283
			// Cast empty attributes like `data-rule-required` to `true`
1284
			if ( value === "" ) {
1285
				value = true;
1286
			}
1287

1288
			this.normalizeAttributeRule( rules, type, method, value );
1289
		}
1290
		return rules;
1291
	},
1292

1293
	staticRules: function( element ) {
1294
		var rules = {},
1295
			validator = $.data( element.form, "validator" );
1296

1297
		if ( validator.settings.rules ) {
1298
			rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {};
1299
		}
1300
		return rules;
1301
	},
1302

1303
	normalizeRules: function( rules, element ) {
1304

1305
		// Handle dependency check
1306
		$.each( rules, function( prop, val ) {
1307

1308
			// Ignore rule when param is explicitly false, eg. required:false
1309
			if ( val === false ) {
1310
				delete rules[ prop ];
1311
				return;
1312
			}
1313
			if ( val.param || val.depends ) {
1314
				var keepRule = true;
1315
				switch ( typeof val.depends ) {
1316
				case "string":
1317
					keepRule = !!$( val.depends, element.form ).length;
1318
					break;
1319
				case "function":
1320
					keepRule = val.depends.call( element, element );
1321
					break;
1322
				}
1323
				if ( keepRule ) {
1324
					rules[ prop ] = val.param !== undefined ? val.param : true;
1325
				} else {
1326
					$.data( element.form, "validator" ).resetElements( $( element ) );
1327
					delete rules[ prop ];
1328
				}
1329
			}
1330
		} );
1331

1332
		// Evaluate parameters
1333
		$.each( rules, function( rule, parameter ) {
1334
			rules[ rule ] = typeof parameter === "function" && rule !== "normalizer" ? parameter( element ) : parameter;
1335
		} );
1336

1337
		// Clean number parameters
1338
		$.each( [ "minlength", "maxlength" ], function() {
1339
			if ( rules[ this ] ) {
1340
				rules[ this ] = Number( rules[ this ] );
1341
			}
1342
		} );
1343
		$.each( [ "rangelength", "range" ], function() {
1344
			var parts;
1345
			if ( rules[ this ] ) {
1346
				if ( Array.isArray( rules[ this ] ) ) {
1347
					rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ];
1348
				} else if ( typeof rules[ this ] === "string" ) {
1349
					parts = rules[ this ].replace( /[\[\]]/g, "" ).split( /[\s,]+/ );
1350
					rules[ this ] = [ Number( parts[ 0 ] ), Number( parts[ 1 ] ) ];
1351
				}
1352
			}
1353
		} );
1354

1355
		if ( $.validator.autoCreateRanges ) {
1356

1357
			// Auto-create ranges
1358
			if ( rules.min != null && rules.max != null ) {
1359
				rules.range = [ rules.min, rules.max ];
1360
				delete rules.min;
1361
				delete rules.max;
1362
			}
1363
			if ( rules.minlength != null && rules.maxlength != null ) {
1364
				rules.rangelength = [ rules.minlength, rules.maxlength ];
1365
				delete rules.minlength;
1366
				delete rules.maxlength;
1367
			}
1368
		}
1369

1370
		return rules;
1371
	},
1372

1373
	// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
1374
	normalizeRule: function( data ) {
1375
		if ( typeof data === "string" ) {
1376
			var transformed = {};
1377
			$.each( data.split( /\s/ ), function() {
1378
				transformed[ this ] = true;
1379
			} );
1380
			data = transformed;
1381
		}
1382
		return data;
1383
	},
1384

1385
	// https://jqueryvalidation.org/jQuery.validator.addMethod/
1386
	addMethod: function( name, method, message ) {
1387
		$.validator.methods[ name ] = method;
1388
		$.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ];
1389
		if ( method.length < 3 ) {
1390
			$.validator.addClassRules( name, $.validator.normalizeRule( name ) );
1391
		}
1392
	},
1393

1394
	// https://jqueryvalidation.org/jQuery.validator.methods/
1395
	methods: {
1396

1397
		// https://jqueryvalidation.org/required-method/
1398
		required: function( value, element, param ) {
1399

1400
			// Check if dependency is met
1401
			if ( !this.depend( param, element ) ) {
1402
				return "dependency-mismatch";
1403
			}
1404
			if ( element.nodeName.toLowerCase() === "select" ) {
1405

1406
				// Could be an array for select-multiple or a string, both are fine this way
1407
				var val = $( element ).val();
1408
				return val && val.length > 0;
1409
			}
1410
			if ( this.checkable( element ) ) {
1411
				return this.getLength( value, element ) > 0;
1412
			}
1413
			return value !== undefined && value !== null && value.length > 0;
1414
		},
1415

1416
		// https://jqueryvalidation.org/email-method/
1417
		email: function( value, element ) {
1418

1419
			// From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
1420
			// Retrieved 2014-01-14
1421
			// If you have a problem with this implementation, report a bug against the above spec
1422
			// Or use custom methods to implement your own email validation
1423
			return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
1424
		},
1425

1426
		// https://jqueryvalidation.org/url-method/
1427
		url: function( value, element ) {
1428

1429
			// Copyright (c) 2010-2013 Diego Perini, MIT licensed
1430
			// https://gist.github.com/dperini/729294
1431
			// see also https://mathiasbynens.be/demo/url-regex
1432
			// modified to allow protocol-relative URLs
1433
			return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
1434
		},
1435

1436
		// https://jqueryvalidation.org/date-method/
1437
		date: ( function() {
1438
			var called = false;
1439

1440
			return function( value, element ) {
1441
				if ( !called ) {
1442
					called = true;
1443
					if ( this.settings.debug && window.console ) {
1444
						console.warn(
1445
							"The `date` method is deprecated and will be removed in version '2.0.0'.\n" +
1446
							"Please don't use it, since it relies on the Date constructor, which\n" +
1447
							"behaves very differently across browsers and locales. Use `dateISO`\n" +
1448
							"instead or one of the locale specific methods in `localizations/`\n" +
1449
							"and `additional-methods.js`."
1450
						);
1451
					}
1452
				}
1453

1454
				return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
1455
			};
1456
		}() ),
1457

1458
		// https://jqueryvalidation.org/dateISO-method/
1459
		dateISO: function( value, element ) {
1460
			return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
1461
		},
1462

1463
		// https://jqueryvalidation.org/number-method/
1464
		number: function( value, element ) {
1465
			return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
1466
		},
1467

1468
		// https://jqueryvalidation.org/digits-method/
1469
		digits: function( value, element ) {
1470
			return this.optional( element ) || /^\d+$/.test( value );
1471
		},
1472

1473
		// https://jqueryvalidation.org/minlength-method/
1474
		minlength: function( value, element, param ) {
1475
			var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1476
			return this.optional( element ) || length >= param;
1477
		},
1478

1479
		// https://jqueryvalidation.org/maxlength-method/
1480
		maxlength: function( value, element, param ) {
1481
			var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1482
			return this.optional( element ) || length <= param;
1483
		},
1484

1485
		// https://jqueryvalidation.org/rangelength-method/
1486
		rangelength: function( value, element, param ) {
1487
			var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1488
			return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
1489
		},
1490

1491
		// https://jqueryvalidation.org/min-method/
1492
		min: function( value, element, param ) {
1493
			return this.optional( element ) || value >= param;
1494
		},
1495

1496
		// https://jqueryvalidation.org/max-method/
1497
		max: function( value, element, param ) {
1498
			return this.optional( element ) || value <= param;
1499
		},
1500

1501
		// https://jqueryvalidation.org/range-method/
1502
		range: function( value, element, param ) {
1503
			return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] );
1504
		},
1505

1506
		// https://jqueryvalidation.org/step-method/
1507
		step: function( value, element, param ) {
1508
			var type = $( element ).attr( "type" ),
1509
				errorMessage = "Step attribute on input type " + type + " is not supported.",
1510
				supportedTypes = [ "text", "number", "range" ],
1511
				re = new RegExp( "\\b" + type + "\\b" ),
1512
				notSupported = type && !re.test( supportedTypes.join() ),
1513
				decimalPlaces = function( num ) {
1514
					var match = ( "" + num ).match( /(?:\.(\d+))?$/ );
1515
					if ( !match ) {
1516
						return 0;
1517
					}
1518

1519
					// Number of digits right of decimal point.
1520
					return match[ 1 ] ? match[ 1 ].length : 0;
1521
				},
1522
				toInt = function( num ) {
1523
					return Math.round( num * Math.pow( 10, decimals ) );
1524
				},
1525
				valid = true,
1526
				decimals;
1527

1528
			// Works only for text, number and range input types
1529
			// TODO find a way to support input types date, datetime, datetime-local, month, time and week
1530
			if ( notSupported ) {
1531
				throw new Error( errorMessage );
1532
			}
1533

1534
			decimals = decimalPlaces( param );
1535

1536
			// Value can't have too many decimals
1537
			if ( decimalPlaces( value ) > decimals || toInt( value ) % toInt( param ) !== 0 ) {
1538
				valid = false;
1539
			}
1540

1541
			return this.optional( element ) || valid;
1542
		},
1543

1544
		// https://jqueryvalidation.org/equalTo-method/
1545
		equalTo: function( value, element, param ) {
1546

1547
			// Bind to the blur event of the target in order to revalidate whenever the target field is updated
1548
			var target = $( param );
1549
			if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) {
1550
				target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() {
1551
					$( element ).valid();
1552
				} );
1553
			}
1554
			return value === target.val();
1555
		},
1556

1557
		// https://jqueryvalidation.org/remote-method/
1558
		remote: function( value, element, param, method ) {
1559
			if ( this.optional( element ) ) {
1560
				return "dependency-mismatch";
1561
			}
1562

1563
			method = typeof method === "string" && method || "remote";
1564

1565
			var previous = this.previousValue( element, method ),
1566
				validator, data, optionDataString;
1567

1568
			if ( !this.settings.messages[ element.name ] ) {
1569
				this.settings.messages[ element.name ] = {};
1570
			}
1571
			previous.originalMessage = previous.originalMessage || this.settings.messages[ element.name ][ method ];
1572
			this.settings.messages[ element.name ][ method ] = previous.message;
1573

1574
			param = typeof param === "string" && { url: param } || param;
1575
			optionDataString = $.param( $.extend( { data: value }, param.data ) );
1576
			if ( previous.old === optionDataString ) {
1577
				return previous.valid;
1578
			}
1579

1580
			previous.old = optionDataString;
1581
			validator = this;
1582
			this.startRequest( element );
1583
			data = {};
1584
			data[ element.name ] = value;
1585
			$.ajax( $.extend( true, {
1586
				mode: "abort",
1587
				port: "validate" + element.name,
1588
				dataType: "json",
1589
				data: data,
1590
				context: validator.currentForm,
1591
				success: function( response ) {
1592
					var valid = response === true || response === "true",
1593
						errors, message, submitted;
1594

1595
					validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
1596
					if ( valid ) {
1597
						submitted = validator.formSubmitted;
1598
						validator.resetInternals();
1599
						validator.toHide = validator.errorsFor( element );
1600
						validator.formSubmitted = submitted;
1601
						validator.successList.push( element );
1602
						validator.invalid[ element.name ] = false;
1603
						validator.showErrors();
1604
					} else {
1605
						errors = {};
1606
						message = response || validator.defaultMessage( element, { method: method, parameters: value } );
1607
						errors[ element.name ] = previous.message = message;
1608
						validator.invalid[ element.name ] = true;
1609
						validator.showErrors( errors );
1610
					}
1611
					previous.valid = valid;
1612
					validator.stopRequest( element, valid );
1613
				}
1614
			}, param ) );
1615
			return "pending";
1616
		}
1617
	}
1618

1619
} );
1620

1621
// Ajax mode: abort
1622
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1623
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
1624

1625
var pendingRequests = {},
1626
	ajax;
1627

1628
// Use a prefilter if available (1.5+)
1629
if ( $.ajaxPrefilter ) {
1630
	$.ajaxPrefilter( function( settings, _, xhr ) {
1631
		var port = settings.port;
1632
		if ( settings.mode === "abort" ) {
1633
			if ( pendingRequests[ port ] ) {
1634
				pendingRequests[ port ].abort();
1635
			}
1636
			pendingRequests[ port ] = xhr;
1637
		}
1638
	} );
1639
} else {
1640

1641
	// Proxy ajax
1642
	ajax = $.ajax;
1643
	$.ajax = function( settings ) {
1644
		var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
1645
			port = ( "port" in settings ? settings : $.ajaxSettings ).port;
1646
		if ( mode === "abort" ) {
1647
			if ( pendingRequests[ port ] ) {
1648
				pendingRequests[ port ].abort();
1649
			}
1650
			pendingRequests[ port ] = ajax.apply( this, arguments );
1651
			return pendingRequests[ port ];
1652
		}
1653
		return ajax.apply( this, arguments );
1654
	};
1655
}
1656
return $;
1657
}));

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.