vendor: 27,807 bytes, lines 1-910
1/*! 2 * jQuery Validation Plugin v1.17.0 3 * 4 * https://jqueryvalidation.org/ 5 * 6 * Copyright (c) 2017 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 function handle() { 71 var hidden, result; 72 73 // Insert a hidden input as a replacement for the missing submit button 74 // The hidden input is inserted in two cases: 75 // - A user defined a `submitHandler` 76 // - There was a pending request due to `remote` method and `stopRequest()` 77 // was called to submit the form in case it's valid 78 if ( validator.submitButton && ( validator.settings.submitHandler || validator.formSubmitted ) ) { 79 hidden = $( "<input type='hidden'/>" ) 80 .attr( "name", validator.submitButton.name ) 81 .val( $( validator.submitButton ).val() ) 82 .appendTo( validator.currentForm ); 83 } 84 85 if ( validator.settings.submitHandler ) { 86 result = validator.settings.submitHandler.call( validator, validator.currentForm, event ); 87 if ( hidden ) { 88 89 // And clean up afterwards; thanks to no-block-scope, hidden can be referenced 90 hidden.remove(); 91 } 92 if ( result !== undefined ) { 93 return result; 94 } 95 return false; 96 } 97 return true; 98 } 99 100 // Prevent submit for invalid forms or custom submit handlers 101 if ( validator.cancelSubmit ) { 102 validator.cancelSubmit = false; 103 return handle(); 104 } 105 if ( validator.form() ) { 106 if ( validator.pendingRequest ) { 107 validator.formSubmitted = true; 108 return false; 109 } 110 return handle(); 111 } else { 112 validator.focusInvalid(); 113 return false; 114 } 115 } ); 116 } 117 118 return validator; 119 }, 120 121 // https://jqueryvalidation.org/valid/ 122 valid: function() { 123 var valid, validator, errorList; 124 125 if ( $( this[ 0 ] ).is( "form" ) ) { 126 valid = this.validate().form(); 127 } else { 128 errorList = []; 129 valid = true; 130 validator = $( this[ 0 ].form ).validate(); 131 this.each( function() { 132 valid = validator.element( this ) && valid; 133 if ( !valid ) { 134 errorList = errorList.concat( validator.errorList ); 135 } 136 } ); 137 validator.errorList = errorList; 138 } 139 return valid; 140 }, 141 142 // https://jqueryvalidation.org/rules/ 143 rules: function( command, argument ) { 144 var element = this[ 0 ], 145 settings, staticRules, existingRules, data, param, filtered; 146 147 // If nothing is selected, return empty object; can't chain anyway 148 if ( element == null ) { 149 return; 150 } 151 152 if ( !element.form && element.hasAttribute( "contenteditable" ) ) { 153 element.form = this.closest( "form" )[ 0 ]; 154 element.name = this.attr( "name" ); 155 } 156 157 if ( element.form == null ) { 158 return; 159 } 160 161 if ( command ) { 162 settings = $.data( element.form, "validator" ).settings; 163 staticRules = settings.rules; 164 existingRules = $.validator.staticRules( element ); 165 switch ( command ) { 166 case "add": 167 $.extend( existingRules, $.validator.normalizeRule( argument ) ); 168 169 // Remove messages from rules, but allow them to be set separately 170 delete existingRules.messages; 171 staticRules[ element.name ] = existingRules; 172 if ( argument.messages ) { 173 settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages ); 174 } 175 break; 176 case "remove": 177 if ( !argument ) { 178 delete staticRules[ element.name ]; 179 return existingRules; 180 } 181 filtered = {}; 182 $.each( argument.split( /\s/ ), function( index, method ) { 183 filtered[ method ] = existingRules[ method ]; 184 delete existingRules[ method ]; 185 } ); 186 return filtered; 187 } 188 } 189 190 data = $.validator.normalizeRules( 191 $.extend( 192 {}, 193 $.validator.classRules( element ), 194 $.validator.attributeRules( element ), 195 $.validator.dataRules( element ), 196 $.validator.staticRules( element ) 197 ), element ); 198 199 // Make sure required is at front 200 if ( data.required ) { 201 param = data.required; 202 delete data.required; 203 data = $.extend( { required: param }, data ); 204 } 205 206 // Make sure remote is at back 207 if ( data.remote ) { 208 param = data.remote; 209 delete data.remote; 210 data = $.extend( data, { remote: param } ); 211 } 212 213 return data; 214 } 215} ); 216 217// Custom selectors 218$.extend( $.expr.pseudos || $.expr[ ":" ], { // '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support 219 220 // https://jqueryvalidation.org/blank-selector/ 221 blank: function( a ) { 222 return !$.trim( "" + $( a ).val() ); 223 }, 224 225 // https://jqueryvalidation.org/filled-selector/ 226 filled: function( a ) { 227 var val = $( a ).val(); 228 return val !== null && !!$.trim( "" + val ); 229 }, 230 231 // https://jqueryvalidation.org/unchecked-selector/ 232 unchecked: function( a ) { 233 return !$( a ).prop( "checked" ); 234 } 235} ); 236 237// Constructor for validator 238$.validator = function( options, form ) { 239 this.settings = $.extend( true, {}, $.validator.defaults, options ); 240 this.currentForm = form; 241 this.init(); 242}; 243 244// https://jqueryvalidation.org/jQuery.validator.format/ 245$.validator.format = function( source, params ) { 246 if ( arguments.length === 1 ) { 247 return function() { 248 var args = $.makeArray( arguments ); 249 args.unshift( source ); 250 return $.validator.format.apply( this, args ); 251 }; 252 } 253 if ( params === undefined ) { 254 return source; 255 } 256 if ( arguments.length > 2 && params.constructor !== Array ) { 257 params = $.makeArray( arguments ).slice( 1 ); 258 } 259 if ( params.constructor !== Array ) { 260 params = [ params ]; 261 } 262 $.each( params, function( i, n ) { 263 source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() { 264 return n; 265 } ); 266 } ); 267 return source; 268}; 269 270$.extend( $.validator, { 271 272 defaults: { 273 messages: {}, 274 groups: {}, 275 rules: {}, 276 errorClass: "error", 277 pendingClass: "pending", 278 validClass: "valid", 279 errorElement: "label", 280 focusCleanup: false, 281 focusInvalid: true, 282 errorContainer: $( [] ), 283 errorLabelContainer: $( [] ), 284 onsubmit: true, 285 ignore: ":hidden", 286 ignoreTitle: false, 287 onfocusin: function( element ) { 288 this.lastActive = element; 289 290 // Hide error label and remove error class on focus if enabled 291 if ( this.settings.focusCleanup ) { 292 if ( this.settings.unhighlight ) { 293 this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass ); 294 } 295 this.hideThese( this.errorsFor( element ) ); 296 } 297 }, 298 onfocusout: function( element ) { 299 if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) { 300 this.element( element ); 301 } 302 }, 303 onkeyup: function( element, event ) { 304 305 // Avoid revalidate the field when pressing one of the following keys 306 // Shift => 16 307 // Ctrl => 17 308 // Alt => 18 309 // Caps lock => 20 310 // End => 35 311 // Home => 36 312 // Left arrow => 37 313 // Up arrow => 38 314 // Right arrow => 39 315 // Down arrow => 40 316 // Insert => 45 317 // Num lock => 144 318 // AltGr key => 225 319 var excludedKeys = [ 320 16, 17, 18, 20, 35, 36, 37, 321 38, 39, 40, 45, 144, 225 322 ]; 323 324 if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) { 325 return; 326 } else if ( element.name in this.submitted || element.name in this.invalid ) { 327 this.element( element ); 328 } 329 }, 330 onclick: function( element ) { 331 332 // Click on selects, radiobuttons and checkboxes 333 if ( element.name in this.submitted ) { 334 this.element( element ); 335 336 // Or option elements, check parent select in that case 337 } else if ( element.parentNode.name in this.submitted ) { 338 this.element( element.parentNode ); 339 } 340 }, 341 highlight: function( element, errorClass, validClass ) { 342 if ( element.type === "radio" ) { 343 this.findByName( element.name ).addClass( errorClass ).removeClass( validClass ); 344 } else { 345 $( element ).addClass( errorClass ).removeClass( validClass ); 346 } 347 }, 348 unhighlight: function( element, errorClass, validClass ) { 349 if ( element.type === "radio" ) { 350 this.findByName( element.name ).removeClass( errorClass ).addClass( validClass ); 351 } else { 352 $( element ).removeClass( errorClass ).addClass( validClass ); 353 } 354 } 355 }, 356 357 // https://jqueryvalidation.org/jQuery.validator.setDefaults/ 358 setDefaults: function( settings ) { 359 $.extend( $.validator.defaults, settings ); 360 }, 361 362 messages: { 363 required: "This field is required.", 364 remote: "Please fix this field.", 365 email: "Please enter a valid email address.", 366 url: "Please enter a valid URL.", 367 date: "Please enter a valid date.", 368 dateISO: "Please enter a valid date (ISO).", 369 number: "Please enter a valid number.", 370 digits: "Please enter only digits.", 371 equalTo: "Please enter the same value again.", 372 maxlength: $.validator.format( "Please enter no more than {0} characters." ), 373 minlength: $.validator.format( "Please enter at least {0} characters." ), 374 rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ), 375 range: $.validator.format( "Please enter a value between {0} and {1}." ), 376 max: $.validator.format( "Please enter a value less than or equal to {0}." ), 377 min: $.validator.format( "Please enter a value greater than or equal to {0}." ), 378 step: $.validator.format( "Please enter a multiple of {0}." ) 379 }, 380 381 autoCreateRanges: false, 382 383 prototype: { 384 385 init: function() { 386 this.labelContainer = $( this.settings.errorLabelContainer ); 387 this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm ); 388 this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer ); 389 this.submitted = {}; 390 this.valueCache = {}; 391 this.pendingRequest = 0; 392 this.pending = {}; 393 this.invalid = {}; 394 this.reset(); 395 396 var groups = ( this.groups = {} ), 397 rules; 398 $.each( this.settings.groups, function( key, value ) { 399 if ( typeof value === "string" ) { 400 value = value.split( /\s/ ); 401 } 402 $.each( value, function( index, name ) { 403 groups[ name ] = key; 404 } ); 405 } ); 406 rules = this.settings.rules; 407 $.each( rules, function( key, value ) { 408 rules[ key ] = $.validator.normalizeRule( value ); 409 } ); 410 411 function delegate( event ) { 412 413 // Set form expando on contenteditable 414 if ( !this.form && this.hasAttribute( "contenteditable" ) ) { 415 this.form = $( this ).closest( "form" )[ 0 ]; 416 this.name = $( this ).attr( "name" ); 417 } 418 419 var validator = $.data( this.form, "validator" ), 420 eventType = "on" + event.type.replace( /^validate/, "" ), 421 settings = validator.settings; 422 if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) { 423 settings[ eventType ].call( validator, this, event ); 424 } 425 } 426 427 $( this.currentForm ) 428 .on( "focusin.validate focusout.validate keyup.validate", 429 ":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " + 430 "[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " + 431 "[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " + 432 "[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate ) 433 434 // Support: Chrome, oldIE 435 // "select" is provided as event.target when clicking a option 436 .on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate ); 437 438 if ( this.settings.invalidHandler ) { 439 $( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler ); 440 } 441 }, 442 443 // https://jqueryvalidation.org/Validator.form/ 444 form: function() { 445 this.checkForm(); 446 $.extend( this.submitted, this.errorMap ); 447 this.invalid = $.extend( {}, this.errorMap ); 448 if ( !this.valid() ) { 449 $( this.currentForm ).triggerHandler( "invalid-form", [ this ] ); 450 } 451 this.showErrors(); 452 return this.valid(); 453 }, 454 455 checkForm: function() { 456 this.prepareForm(); 457 for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) { 458 this.check( elements[ i ] ); 459 } 460 return this.valid(); 461 462 //this.prepareForm(); 463 //for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) { 464 // if (this.findByName(elements[i].name).length != undefined && this.findByName(elements[i].name).length > 1) { 465 // for (var cnt = 0; cnt < this.findByName(elements[i].name).length; cnt++) { 466 // this.check(this.findByName(elements[i].name)[cnt]); 467 // } 468 // } else { 469 // this.check(elements[i]); 470 // } 471 //} 472 //return this.valid(); 473 }, 474 475 // https://jqueryvalidation.org/Validator.element/ 476 element: function( element ) { 477 var cleanElement = this.clean( element ), 478 checkElement = this.validationTargetFor( cleanElement ), 479 v = this, 480 result = true, 481 rs, group; 482 483 if ( checkElement === undefined ) { 484 delete this.invalid[ cleanElement.name ]; 485 } else { 486 this.prepareElement( checkElement ); 487 this.currentElements = $( checkElement ); 488 489 // If this element is grouped, then validate all group elements already 490 // containing a value 491 group = this.groups[ checkElement.name ]; 492 if ( group ) { 493 $.each( this.groups, function( name, testgroup ) { 494 if ( testgroup === group && name !== checkElement.name ) { 495 cleanElement = v.validationTargetFor( v.clean( v.findByName( name ) ) ); 496 if ( cleanElement && cleanElement.name in v.invalid ) { 497 v.currentElements.push( cleanElement ); 498 result = v.check( cleanElement ) && result; 499 } 500 } 501 } ); 502 } 503 504 rs = this.check( checkElement ) !== false; 505 result = result && rs; 506 if ( rs ) { 507 this.invalid[ checkElement.name ] = false; 508 } else { 509 this.invalid[ checkElement.name ] = true; 510 } 511 512 if ( !this.numberOfInvalids() ) { 513 514 // Hide error containers on last error 515 this.toHide = this.toHide.add( this.containers ); 516 } 517 this.showErrors(); 518 519 // Add aria-invalid status for screen readers 520 $( element ).attr( "aria-invalid", !rs ); 521 } 522 523 return result; 524 }, 525 526 // https://jqueryvalidation.org/Validator.showErrors/ 527 showErrors: function( errors ) { 528 if ( errors ) { 529 var validator = this; 530 531 // Add items to error list and map 532 $.extend( this.errorMap, errors ); 533 this.errorList = $.map( this.errorMap, function( message, name ) { 534 return { 535 message: message, 536 element: validator.findByName( name )[ 0 ] 537 }; 538 } ); 539 540 // Remove items from success list 541 this.successList = $.grep( this.successList, function( element ) { 542 return !( element.name in errors ); 543 } ); 544 } 545 if ( this.settings.showErrors ) { 546 this.settings.showErrors.call( this, this.errorMap, this.errorList ); 547 } else { 548 this.defaultShowErrors(); 549 } 550 }, 551 552 // https://jqueryvalidation.org/Validator.resetForm/ 553 resetForm: function() { 554 if ( $.fn.resetForm ) { 555 $( this.currentForm ).resetForm(); 556 } 557 this.invalid = {}; 558 this.submitted = {}; 559 this.prepareForm(); 560 this.hideErrors(); 561 var elements = this.elements() 562 .removeData( "previousValue" ) 563 .removeAttr( "aria-invalid" ); 564 565 this.resetElements( elements ); 566 }, 567 568 resetElements: function( elements ) { 569 var i; 570 571 if ( this.settings.unhighlight ) { 572 for ( i = 0; elements[ i ]; i++ ) { 573 this.settings.unhighlight.call( this, elements[ i ], 574 this.settings.errorClass, "" ); 575 this.findByName( elements[ i ].name ).removeClass( this.settings.validClass ); 576 } 577 } else { 578 elements 579 .removeClass( this.settings.errorClass ) 580 .removeClass( this.settings.validClass ); 581 } 582 }, 583 584 numberOfInvalids: function() { 585 return this.objectLength( this.invalid ); 586 }, 587 588 objectLength: function( obj ) { 589 /* jshint unused: false */ 590 var count = 0, 591 i; 592 for ( i in obj ) { 593 594 // This check allows counting elements with empty error 595 // message as invalid elements 596 if ( obj[ i ] !== undefined && obj[ i ] !== null && obj[ i ] !== false ) { 597 count++; 598 } 599 } 600 return count; 601 }, 602 603 hideErrors: function() { 604 this.hideThese( this.toHide ); 605 }, 606 607 hideThese: function( errors ) { 608 errors.not( this.containers ).text( "" ); 609 this.addWrapper( errors ).hide(); 610 }, 611 612 valid: function() { 613 return this.size() === 0; 614 }, 615 616 size: function() { 617 return this.errorList.length; 618 }, 619 620 focusInvalid: function() { 621 if ( this.settings.focusInvalid ) { 622 try { 623 $( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [] ) 624 .filter( ":visible" ) 625 .focus() 626 627 // Manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find 628 .trigger( "focusin" ); 629 } catch ( e ) { 630 631 // Ignore IE throwing errors when focusing hidden elements 632 } 633 } 634 }, 635 636 findLastActive: function() { 637 var lastActive = this.lastActive; 638 return lastActive && $.grep( this.errorList, function( n ) { 639 return n.element.name === lastActive.name; 640 } ).length === 1 && lastActive; 641 }, 642 643 elements: function() { 644 var validator = this, 645 rulesCache = {}; 646 647 // Select all valid inputs inside the form (no submit or reset buttons) 648 return $( this.currentForm ) 649 .find( "input, select, textarea, [contenteditable]" ) 650 .not( ":submit, :reset, :image, :disabled" ) 651 .not( this.settings.ignore ) 652 .filter( function() { 653 var name = this.name || $( this ).attr( "name" ); // For contenteditable 654 if ( !name && validator.settings.debug && window.console ) { 655 console.error( "%o has no name assigned", this ); 656 } 657 658 // Set form expando on contenteditable 659 if ( this.hasAttribute( "contenteditable" ) ) { 660 this.form = $( this ).closest( "form" )[ 0 ]; 661 this.name = name; 662 } 663 664 // Select only the first element for each name, and only those with rules specified 665 if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) { 666 return false; 667 } 668 669 rulesCache[ name ] = true; 670 return true; 671 } ); 672 }, 673 674 clean: function( selector ) { 675 return $( selector )[ 0 ]; 676 }, 677 678 errors: function() { 679 var errorClass = this.settings.errorClass.split( " " ).join( "." ); 680 return $( this.settings.errorElement + "." + errorClass, this.errorContext ); 681 }, 682 683 resetInternals: function() { 684 this.successList = []; 685 this.errorList = []; 686 this.errorMap = {}; 687 this.toShow = $( [] ); 688 this.toHide = $( [] ); 689 }, 690 691 reset: function() { 692 this.resetInternals(); 693 this.currentElements = $( [] ); 694 }, 695 696 prepareForm: function() { 697 this.reset(); 698 this.toHide = this.errors().add( this.containers ); 699 }, 700 701 prepareElement: function( element ) { 702 this.reset(); 703 this.toHide = this.errorsFor( element ); 704 }, 705 706 elementValue: function( element ) { 707 var $element = $( element ), 708 type = element.type, 709 val, idx; 710 711 if ( type === "radio" || type === "checkbox" ) { 712 return this.findByName( element.name ).filter( ":checked" ).val(); 713 } else if ( type === "number" && typeof element.validity !== "undefined" ) { 714 return element.validity.badInput ? "NaN" : $element.val(); 715 } 716 717 if ( element.hasAttribute( "contenteditable" ) ) { 718 val = $element.text(); 719 } else { 720 val = $element.val(); 721 } 722 723 if ( type === "file" ) { 724 725 // Modern browser (chrome & safari) 726 if ( val.substr( 0, 12 ) === "C:\\fakepath\\" ) { 727 return val.substr( 12 ); 728 } 729 730 // Legacy browsers 731 // Unix-based path 732 idx = val.lastIndexOf( "/" ); 733 if ( idx >= 0 ) { 734 return val.substr( idx + 1 ); 735 } 736 737 // Windows-based path 738 idx = val.lastIndexOf( "\\" ); 739 if ( idx >= 0 ) { 740 return val.substr( idx + 1 ); 741 } 742 743 // Just the file name 744 return val; 745 } 746 747 if ( typeof val === "string" ) { 748 return val.replace( /\r/g, "" ); 749 } 750 return val; 751 }, 752 753 check: function( element ) { 754 element = this.validationTargetFor( this.clean( element ) ); 755 756 var rules = $( element ).rules(), 757 rulesCount = $.map( rules, function( n, i ) { 758 return i; 759 } ).length, 760 dependencyMismatch = false, 761 val = this.elementValue( element ), 762 result, method, rule, normalizer; 763 764 // Prioritize the local normalizer defined for this element over the global one 765 // if the former exists, otherwise user the global one in case it exists. 766 if ( typeof rules.normalizer === "function" ) { 767 normalizer = rules.normalizer; 768 } else if ( typeof this.settings.normalizer === "function" ) { 769 normalizer = this.settings.normalizer; 770 } 771 772 // If normalizer is defined, then call it to retreive the changed value instead 773 // of using the real one. 774 // Note that `this` in the normalizer is `element`. 775 if ( normalizer ) { 776 val = normalizer.call( element, val ); 777 778 if ( typeof val !== "string" ) { 779 throw new TypeError( "The normalizer should return a string value." ); 780 } 781 782 // Delete the normalizer from rules to avoid treating it as a pre-defined method. 783 delete rules.normalizer; 784 } 785 786 for ( method in rules ) { 787 rule = { method: method, parameters: rules[ method ] }; 788 try { 789 result = $.validator.methods[ method ].call( this, val, element, rule.parameters ); 790 791 // If a method indicates that the field is optional and therefore valid, 792 // don't mark it as valid when there are no other rules 793 if ( result === "dependency-mismatch" && rulesCount === 1 ) { 794 dependencyMismatch = true; 795 continue; 796 } 797 dependencyMismatch = false; 798 799 if ( result === "pending" ) { 800 this.toHide = this.toHide.not( this.errorsFor( element ) ); 801 return; 802 } 803 804 if ( !result ) { 805 this.formatAndAdd( element, rule ); 806 return false; 807 } 808 } catch ( e ) { 809 if ( this.settings.debug && window.console ) { 810 console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e ); 811 } 812 if ( e instanceof TypeError ) { 813 e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method."; 814 } 815 816 throw e; 817 } 818 } 819 if ( dependencyMismatch ) { 820 return; 821 } 822 if ( this.objectLength( rules ) ) { 823 this.successList.push( element ); 824 } 825 return true; 826 }, 827 828 // Return the custom message for the given element and validation method 829 // specified in the element's HTML5 data attribute 830 // return the generic message if present and no method specific message is present 831 customDataMessage: function( element, method ) { 832 return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() + 833 method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" ); 834 }, 835 836 // Return the custom message for the given element name and validation method 837 customMessage: function( name, method ) { 838 var m = this.settings.messages[ name ]; 839 return m && ( m.constructor === String ? m : m[ method ] ); 840 }, 841 842 // Return the first defined argument, allowing empty strings 843 findDefined: function() { 844 for ( var i = 0; i < arguments.length; i++ ) { 845 if ( arguments[ i ] !== undefined ) { 846 return arguments[ i ]; 847 } 848 } 849 return undefined; 850 }, 851 852 // The second parameter 'rule' used to be a string, and extended to an object literal 853 // of the following form: 854 // rule = { 855 // method: "method name", 856 // parameters: "the given method parameters" 857 // } 858 // 859 // The old behavior still supported, kept to maintain backward compatibility with 860 // old code, and will be removed in the next major release. 861 defaultMessage: function( element, rule ) { 862 if ( typeof rule === "string" ) { 863 rule = { method: rule }; 864 } 865 866 var message = this.findDefined( 867 this.customMessage( element.name, rule.method ), 868 this.customDataMessage( element, rule.method ), 869 870 // 'title' is never undefined, so handle empty string as undefined 871 !this.settings.ignoreTitle && element.title || undefined, 872 $.validator.messages[ rule.method ], 873 "<strong>Warning: No message defined for " + element.name + "</strong>" 874 ), 875 theregex = /\$?\{(\d+)\}/g; 876 if ( typeof message === "function" ) { 877 message = message.call( this, rule.parameters, element ); 878 } else if ( theregex.test( message ) ) { 879 message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters ); 880 } 881 882 return message; 883 }, 884 885 formatAndAdd: function( element, rule ) { 886 var message = this.defaultMessage( element, rule ); 887 888 this.errorList.push( { 889 message: message, 890 element: element, 891 method: rule.method 892 } ); 893 894 this.errorMap[ element.name ] = message; 895 this.submitted[ element.name ] = message; 896 }, 897 898 addWrapper: function( toToggle ) { 899 if ( this.settings.wrapper ) { 900 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); 901 } 902 return toToggle; 903 }, 904 905 defaultShowErrors: function() { 906 var i, elements, error; 907 for ( i = 0; this.errorList[ i ]; i++ ) { 908 error = this.errorList[ i ]; 909 if ( this.settings.highlight ) { 910 this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.val
910idClass ); 911 } 912 this.showLabel( error.element, error.message ); 913 } 914 if ( this.errorList.length ) { 915 this.toShow = this.toShow.add( this.containers ); 916 } 917 if ( this.settings.success ) { 918 for ( i = 0; this.successList[ i ]; i++ ) { 919 this.showLabel( this.successList[ i ] ); 920 } 921 } 922 if ( this.settings.unhighlight ) { 923 for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) { 924 this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass ); 925 } 926 } 927 this.toHide = this.toHide.not( this.toShow ); 928 this.hideErrors(); 929 this.addWrapper( this.toShow ).show(); 930 }, 931 932 validElements: function() { 933 return this.currentElements.not( this.invalidElements() ); 934 }, 935 936 invalidElements: function() { 937 return $( this.errorList ).map( function() { 938 return this.element; 939 } ); 940 }, 941 942 showLabel: function( element, message ) { 943 var place, group, errorID, v, 944 error = this.errorsFor( element ), 945 elementID = this.idOrName( element ), 946 describedBy = $( element ).attr( "aria-describedby" ); 947 948 if ( error.length ) { 949 950 // Refresh error/success class 951 error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass ); 952 953 // Replace message on existing label 954 error.html( message ); 955 } else { 956 957 // Create error element 958 error = $( "<" + this.settings.errorElement + ">" ) 959 .attr( "id", elementID + "-error" ) 960 .addClass( this.settings.errorClass ) 961 .html( message || "" ); 962 963 // Maintain reference to the element to be placed into the DOM 964 place = error; 965 if ( this.settings.wrapper ) { 966 967 // Make sure the element is visible, even in IE 968 // actually showing the wrapped element is handled elsewhere 969 place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent(); 970 } 971 if ( this.labelContainer.length ) { 972 this.labelContainer.append( place ); 973 } else if ( this.settings.errorPlacement ) { 974 this.settings.errorPlacement.call( this, place, $( element ) ); 975 } else { 976 place.insertAfter( element ); 977 } 978 979 // Link error back to the element 980 if ( error.is( "label" ) ) { 981 982 // If the error is a label, then associate using 'for' 983 error.attr( "for", elementID ); 984 985 // If the element is not a child of an associated label, then it's necessary 986 // to explicitly apply aria-describedby 987 } else if ( error.parents( "label[for='" + this.escapeCssMeta( elementID ) + "']" ).length === 0 ) { 988 errorID = error.attr( "id" ); 989 990 // Respect existing non-error aria-describedby 991 if ( !describedBy ) { 992 describedBy = errorID; 993 } else if ( !describedBy.match( new RegExp( "\\b" + this.escapeCssMeta( errorID ) + "\\b" ) ) ) { 994 995 // Add to end of list if not already present 996 describedBy += " " + errorID; 997 } 998 $( element ).attr( "aria-describedby", describedBy ); 999 1000 // If this element is grouped, then assign to all elements in the same group 1001 group = this.groups[ element.name ]; 1002 if ( group ) { 1003 v = this; 1004 $.each( v.groups, function( name, testgroup ) { 1005 if ( testgroup === group ) { 1006 $( "[name='" + v.escapeCssMeta( name ) + "']", v.currentForm ) 1007 .attr( "aria-describedby", error.attr( "id" ) ); 1008 } 1009 } ); 1010 } 1011 } 1012 } 1013 if ( !message && this.settings.success ) { 1014 error.text( "" ); 1015 if ( typeof this.settings.success === "string" ) { 1016 error.addClass( this.settings.success ); 1017 } else { 1018 this.settings.success( error, element ); 1019 } 1020 } 1021 this.toShow = this.toShow.add( error ); 1022 }, 1023 1024 errorsFor: function( element ) { 1025 var name = this.escapeCssMeta( this.idOrName( element ) ), 1026 describer = $( element ).attr( "aria-describedby" ), 1027 selector = "label[for='" + name + "'], label[for='" + name + "'] *"; 1028 1029 // 'aria-describedby' should directly reference the error element 1030 if ( describer ) { 1031 selector = selector + ", #" + this.escapeCssMeta( describer ) 1032 .replace( /\s+/g, ", #" ); 1033 } 1034 1035 return this 1036 .errors() 1037 .filter( selector ); 1038 }, 1039 1040 // See https://api.jquery.com/category/selectors/, for CSS 1041 // meta-characters that should be escaped in order to be used with JQuery 1042 // as a literal part of a name/id or any selector. 1043 escapeCssMeta: function( string ) { 1044 return string.replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" ); 1045 }, 1046 1047 idOrName: function( element ) { 1048 return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.i
vendor: 9,881 bytes, lines 1048-1381
1048d || element.name ); 1049 }, 1050 1051 validationTargetFor: function( element ) { 1052 1053 // If radio/checkbox, validate first element in group instead 1054 if ( this.checkable( element ) ) { 1055 element = this.findByName( element.name ); 1056 } 1057 1058 // Always apply ignore filter 1059 return $( element ).not( this.settings.ignore )[ 0 ]; 1060 }, 1061 1062 checkable: function( element ) { 1063 return ( /radio|checkbox/i ).test( element.type ); 1064 }, 1065 1066 findByName: function( name ) { 1067 return $( this.currentForm ).find( "[name='" + this.escapeCssMeta( name ) + "']" ); 1068 }, 1069 1070 getLength: function( value, element ) { 1071 switch ( element.nodeName.toLowerCase() ) { 1072 case "select": 1073 return $( "option:selected", element ).length; 1074 case "input": 1075 if ( this.checkable( element ) ) { 1076 return this.findByName( element.name ).filter( ":checked" ).length; 1077 } 1078 } 1079 return value.length; 1080 }, 1081 1082 depend: function( param, element ) { 1083 return this.dependTypes[ typeof param ] ? this.dependTypes[ typeof param ]( param, element ) : true; 1084 }, 1085 1086 dependTypes: { 1087 "boolean": function( param ) { 1088 return param; 1089 }, 1090 "string": function( param, element ) { 1091 return !!$( param, element.form ).length; 1092 }, 1093 "function": function( param, element ) { 1094 return param( element ); 1095 } 1096 }, 1097 1098 optional: function( element ) { 1099 var val = this.elementValue( element ); 1100 return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch"; 1101 }, 1102 1103 startRequest: function( element ) { 1104 if ( !this.pending[ element.name ] ) { 1105 this.pendingRequest++; 1106 $( element ).addClass( this.settings.pendingClass ); 1107 this.pending[ element.name ] = true; 1108 } 1109 }, 1110 1111 stopRequest: function( element, valid ) { 1112 this.pendingRequest--; 1113 1114 // Sometimes synchronization fails, make sure pendingRequest is never < 0 1115 if ( this.pendingRequest < 0 ) { 1116 this.pendingRequest = 0; 1117 } 1118 delete this.pending[ element.name ]; 1119 $( element ).removeClass( this.settings.pendingClass ); 1120 if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) { 1121 $( this.currentForm ).submit(); 1122 1123 // Remove the hidden input that was used as a replacement for the 1124 // missing submit button. The hidden input is added by `handle()` 1125 // to ensure that the value of the used submit button is passed on 1126 // for scripted submits triggered by this method 1127 if ( this.submitButton ) { 1128 $( "input:hidden[name='" + this.submitButton.name + "']", this.currentForm ).remove(); 1129 } 1130 1131 this.formSubmitted = false; 1132 } else if ( !valid && this.pendingRequest === 0 && this.formSubmitted ) { 1133 $( this.currentForm ).triggerHandler( "invalid-form", [ this ] ); 1134 this.formSubmitted = false; 1135 } 1136 }, 1137 1138 previousValue: function( element, method ) { 1139 method = typeof method === "string" && method || "remote"; 1140 1141 return $.data( element, "previousValue" ) || $.data( element, "previousValue", { 1142 old: null, 1143 valid: true, 1144 message: this.defaultMessage( element, { method: method } ) 1145 } ); 1146 }, 1147 1148 // Cleans up all forms and elements, removes validator-specific events 1149 destroy: function() { 1150 this.resetForm(); 1151 1152 $( this.currentForm ) 1153 .off( ".validate" ) 1154 .removeData( "validator" ) 1155 .find( ".validate-equalTo-blur" ) 1156 .off( ".validate-equalTo" ) 1157 .removeClass( "validate-equalTo-blur" ); 1158 } 1159 1160 }, 1161 1162 classRuleSettings: { 1163 required: { required: true }, 1164 email: { email: true }, 1165 url: { url: true }, 1166 date: { date: true }, 1167 dateISO: { dateISO: true }, 1168 number: { number: true }, 1169 digits: { digits: true }, 1170 creditcard: { creditcard: true } 1171 }, 1172 1173 addClassRules: function( className, rules ) { 1174 if ( className.constructor === String ) { 1175 this.classRuleSettings[ className ] = rules; 1176 } else { 1177 $.extend( this.classRuleSettings, className ); 1178 } 1179 }, 1180 1181 classRules: function( element ) { 1182 var rules = {}, 1183 classes = $( element ).attr( "class" ); 1184 1185 if ( classes ) { 1186 $.each( classes.split( " " ), function() { 1187 if ( this in $.validator.classRuleSettings ) { 1188 $.extend( rules, $.validator.classRuleSettings[ this ] ); 1189 } 1190 } ); 1191 } 1192 return rules; 1193 }, 1194 1195 normalizeAttributeRule: function( rules, type, method, value ) { 1196 1197 // Convert the value to a number for number inputs, and for text for backwards compability 1198 // allows type="date" and others to be compared as strings 1199 if ( /min|max|step/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) { 1200 value = Number( value ); 1201 1202 // Support Opera Mini, which returns NaN for undefined minlength 1203 if ( isNaN( value ) ) { 1204 value = undefined; 1205 } 1206 } 1207 1208 if ( value || value === 0 ) { 1209 rules[ method ] = value; 1210 } else if ( type === method && type !== "range" ) { 1211 1212 // Exception: the jquery validate 'range' method 1213 // does not test for the html5 'range' type 1214 rules[ method ] = true; 1215 } 1216 }, 1217 1218 attributeRules: function( element ) { 1219 var rules = {}, 1220 $element = $( element ), 1221 type = element.getAttribute( "type" ), 1222 method, value; 1223 1224 for ( method in $.validator.methods ) { 1225 1226 // Support for <input required> in both html5 and older browsers 1227 if ( method === "required" ) { 1228 value = element.getAttribute( method ); 1229 1230 // Some browsers return an empty string for the required attribute 1231 // and non-HTML5 browsers might have required="" markup 1232 if ( value === "" ) { 1233 value = true; 1234 } 1235 1236 // Force non-HTML5 browsers to return bool 1237 value = !!value; 1238 } else { 1239 value = $element.attr( method ); 1240 } 1241 1242 this.normalizeAttributeRule( rules, type, method, value ); 1243 } 1244 1245 // 'maxlength' may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs 1246 if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) { 1247 delete rules.maxlength; 1248 } 1249 1250 return rules; 1251 }, 1252 1253 dataRules: function( element ) { 1254 var rules = {}, 1255 $element = $( element ), 1256 type = element.getAttribute( "type" ), 1257 method, value; 1258 1259 for ( method in $.validator.methods ) { 1260 value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() ); 1261 this.normalizeAttributeRule( rules, type, method, value ); 1262 } 1263 return rules; 1264 }, 1265 1266 staticRules: function( element ) { 1267 var rules = {}, 1268 validator = $.data( element.form, "validator" ); 1269 1270 if ( validator.settings.rules ) { 1271 rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {}; 1272 } 1273 return rules; 1274 }, 1275 1276 normalizeRules: function( rules, element ) { 1277 1278 // Handle dependency check 1279 $.each( rules, function( prop, val ) { 1280 1281 // Ignore rule when param is explicitly false, eg. required:false 1282 if ( val === false ) { 1283 delete rules[ prop ]; 1284 return; 1285 } 1286 if ( val.param || val.depends ) { 1287 var keepRule = true; 1288 switch ( typeof val.depends ) { 1289 case "string": 1290 keepRule = !!$( val.depends, element.form ).length; 1291 break; 1292 case "function": 1293 keepRule = val.depends.call( element, element ); 1294 break; 1295 } 1296 if ( keepRule ) { 1297 rules[ prop ] = val.param !== undefined ? val.param : true; 1298 } else { 1299 $.data( element.form, "validator" ).resetElements( $( element ) ); 1300 delete rules[ prop ]; 1301 } 1302 } 1303 } ); 1304 1305 // Evaluate parameters 1306 $.each( rules, function( rule, parameter ) { 1307 rules[ rule ] = $.isFunction( parameter ) && rule !== "normalizer" ? parameter( element ) : parameter; 1308 } ); 1309 1310 // Clean number parameters 1311 $.each( [ "minlength", "maxlength" ], function() { 1312 if ( rules[ this ] ) { 1313 rules[ this ] = Number( rules[ this ] ); 1314 } 1315 } ); 1316 $.each( [ "rangelength", "range" ], function() { 1317 var parts; 1318 if ( rules[ this ] ) { 1319 if ( $.isArray( rules[ this ] ) ) { 1320 rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ]; 1321 } else if ( typeof rules[ this ] === "string" ) { 1322 parts = rules[ this ].replace( /[\[\]]/g, "" ).split( /[\s,]+/ ); 1323 rules[ this ] = [ Number( parts[ 0 ] ), Number( parts[ 1 ] ) ]; 1324 } 1325 } 1326 } ); 1327 1328 if ( $.validator.autoCreateRanges ) { 1329 1330 // Auto-create ranges 1331 if ( rules.min != null && rules.max != null ) { 1332 rules.range = [ rules.min, rules.max ]; 1333 delete rules.min; 1334 delete rules.max; 1335 } 1336 if ( rules.minlength != null && rules.maxlength != null ) { 1337 rules.rangelength = [ rules.minlength, rules.maxlength ]; 1338 delete rules.minlength; 1339 delete rules.maxlength; 1340 } 1341 } 1342 1343 return rules; 1344 }, 1345 1346 // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} 1347 normalizeRule: function( data ) { 1348 if ( typeof data === "string" ) { 1349 var transformed = {}; 1350 $.each( data.split( /\s/ ), function() { 1351 transformed[ this ] = true; 1352 } ); 1353 data = transformed; 1354 } 1355 return data; 1356 }, 1357 1358 // https://jqueryvalidation.org/jQuery.validator.addMethod/ 1359 addMethod: function( name, method, message ) { 1360 $.validator.methods[ name ] = method; 1361 $.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ]; 1362 if ( method.length < 3 ) { 1363 $.validator.addClassRules( name, $.validator.normalizeRule( name ) ); 1364 } 1365 }, 1366 1367 // https://jqueryvalidation.org/jQuery.validator.methods/ 1368 methods: { 1369 1370 // https://jqueryvalidation.org/required-method/ 1371 required: function( value, element, param ) { 1372 1373 // Check if dependency is met 1374 if ( !this.depend( param, element ) ) { 1375 return "dependency-mismatch"; 1376 } 1377 if ( element.nodeName.toLowerCase() === "select" ) { 1378 1379 // Could be an array for select-multiple or a string, both are fine this way 1380 var val = $( element ).val(); 1381 return val && val.length > 0;
1382 } 1383 if ( this.checkable( element ) ) { 1384 return this.getLength( value, element ) > 0; 1385 } 1386 return value.length > 0; 1387 }, 1388 1389 // https://jqueryvalidation.org/email-method/ 1390 email: function( value, element ) { 1391 1392 // From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address 1393 // Retrieved 2014-01-14 1394 // If you have a problem with this implementation, report a bug against the above spec 1395 // Or use custom methods to implement your own email validation 1396 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 ); 1397 }, 1398 1399 // https://jqueryvalidation.org/url-method/ 1400 url: function( value, element ) { 1401 1402 // Copyright (c) 2010-2013 Diego Perini, MIT licensed 1403 // https://gist.github.com/dperini/729294 1404 // see also https://mathiasbynens.be/demo/url-regex 1405 // modified to allow protocol-relative URLs 1406 return this.optional( element ) || /^(?:(?:(?
1406: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-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value ); 1407 }, 1408 1409 // https://jqueryvalidation.org/date-method/ 1410 date: function( value, element ) { 1411 return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() ); 1412 }, 1413 1414 // https://jqueryvalidation.org/dateISO-method/ 1415 dateISO: function( value, element ) { 1416 return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value ); 1417 }, 1418 1419 // https://jqueryvalidation.org/number-method/ 1420 number: function( value, element ) { 1421 return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value ); 1422 }, 1423 1424 // https://jqueryvalidation.org/digits-method/ 1425 digits: function( value, element ) { 1426 return this.optional( element ) || /^\d+$/.test( value ); 1427 }, 1428 1429 // https://jqueryvalidation.org/minlength-method/ 1430 minlength: function( value, element, param ) { 1431 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1432 return this.optional( element ) || length >= param; 1433 }, 1434 1435 // https://jqueryvalidation.org/maxlength-method/ 1436 maxlength: function( value, element, param ) { 1437 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1438 return this.optional( element ) || length <= param; 1439 }, 1440 1441 // https://jqueryvalidation.org/rangelength-method/ 1442 rangelength: function( value, element, param ) { 1443 var length = $.isArray( value ) ? value.length : this.getLength( value, element ); 1444 return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] ); 1445 }, 1446 1447 // https://jqueryvalidation.org/min-method/ 1448 min: function( value, element, param ) { 1449 return this.optional( element ) || value >= param; 1450 }, 1451 1452 // https://jqueryvalidation.org/max-method/ 1453 max: function( value, element, param ) { 1454 return this.optional( element ) || value <= param; 1455 }, 1456 1457 // https://jqueryvalidation.org/range-method/ 1458 range: function( value, element, param ) { 1459 return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] ); 1460 }, 1461 1462 // https://jqueryvalidation.org/step-method/ 1463 step: function( value, element, param ) { 1464 var type = $( element ).attr( "type" ), 1465 errorMessage = "Step attribute on input type " + type + " is not supported.", 1466 supportedTypes = [ "text", "number", "range" ], 1467 re = new RegExp( "\\b" + type + "\\b" ), 1468 notSupported = type && !re.test( supportedTypes.join() ), 1469 decimalPlaces = function( num ) { 1470 var match = ( "" + num ).match( /(?:\.(\d+))?$/ ); 1471 if ( !match ) { 1472 return 0; 1473 } 1474 1475 // Number of digits right of decimal point. 1476 return match[ 1 ] ? match[ 1 ].length : 0; 1477 }, 1478 toInt = function( num ) { 1479 return Math.round( num * Math.pow( 10, decimals ) ); 1480 }, 1481 valid = true, 1482 decimals; 1483 1484 // Works only for text, number and range input types 1485 if ( notSupported ) { 1486 throw new Error( errorMessage ); 1487 } 1488 1489 decimals = decimalPlaces( param ); 1490 1491 // Value can't have too many decimals 1492 if ( decimalPlaces( value ) > decimals || toInt( value ) % toInt( param ) !== 0 ) { 1493 valid = false; 1494 } 1495 1496 return this.optional( element ) || valid; 1497 }, 1498 1499 // https://jqueryvalidation.org/equalTo-method/ 1500 equalTo: function( value, element, param ) { 1501 1502 // Bind to the blur event of the target in order to revalidate whenever the target field is updated 1503 var target = $( param ); 1504 if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) { 1505 target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() { 1506 $( element ).valid(); 1507 } ); 1508 } 1509 return value === target.val(); 1510 }, 1511 1512 // https://jqueryvalidation.org/remote-method/ 1513 remote: function( value, element, param, method ) { 1514 if ( this.optional( element ) ) { 1515 return "dependency-mismatch"; 1516 } 1517 1518 method = typeof method === "string" && method || "remote"; 1519 1520 var previous = this.previousValue( element, method ), 1521 validator, data, optionDataString; 1522 1523 if ( !this.settings.messages[ element.name ] ) { 1524 this.settings.messages[ element.name ] = {}; 1525 } 1526 previous.originalMessage = previous.originalMessage || this.settings.messages[ element.name ][ method ]; 1527 this.settings.messages[ element.name ][ method ] = previous.message; 1528 1529 param = typeof param === "string" && { url: param } || param; 1530 optionDataString = $.param( $.extend( { data: value }, param.data ) ); 1531 if ( previous.old === optionDataString ) { 1532 return previous.valid; 1533 } 1534 1535 previous.old = optionDataString; 1536 validator = this;
1537 this.startRequest( element ); 1538 data = {}; 1539 data[ element.name ] = value; 1540 $.ajax( $.extend( true, { 1541 mode: "abort", 1542 port: "validate" + element.name, 1543 dataType: "json", 1544 data: data, 1545 context: validator.currentForm, 1546 success: function( response ) { 1547 var valid = response === true || response === "true", 1548 errors, message, submitted; 1549 1550 validator.settings.messages[ element.name ][ method ] = previous.originalMessage; 1551 if ( valid ) { 1552 submitted = validator.formSubmitted; 1553 validator.resetInternals(); 1554 validator.toHide = validator.errorsFor( element ); 1555 validator.formSubmitted = submitted; 1556 validator.successList.push( element ); 1557 validator.invalid[ element.name ] = false; 1558 validator.showErrors(); 1559 } else { 1560 errors = {}; 1561 message = response || validator.defaultMessage( element, { method: method, parameters: value } ); 1562 errors[ element.name ] = previous.message = message; 1563 validator.invalid[ element.name ] = true; 1564 validator.showErrors( errors ); 1565 } 1566 previous.valid = valid; 1567 validator.stopRequest( element, valid ); 1568 } 1569 }, param ) ); 1570 return "pending"; 1571 } 1572 } 1573 1574} ); 1575 1576// Ajax mode: abort 1577// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); 1578// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 1579 1580var pendingRequests = {}, 1581 ajax; 1582 1583// Use a prefilter if available (1.5+) 1584if ( $.ajaxPrefilter ) { 1585 $.ajaxPrefilter( function( settings, _, xhr ) { 1586 var port = settings.port; 1587 if ( settings.mode === "abort" ) { 1588 if ( pendingRequests[ port ] ) { 1589 pendingRequests[ port ].abort(); 1590 } 1591 pendingRequests[ port ] = xhr; 1592 } 1593 } ); 1594} else { 1595 1596 // Proxy ajax 1597 ajax = $.ajax; 1598 $.ajax = function( settings ) { 1599 var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode, 1600 port = ( "port" in settings ? settings : $.ajaxSettings ).port; 1601 if ( mode === "abort" ) { 1602 if ( pendingRequests[ port ] ) { 1603 pendingRequests[ port ].abort(); 1604 } 1605 pendingRequests[ port ] = ajax.apply( this, arguments ); 1606 return pendingRequests[ port ]; 1607 } 1608 return ajax.apply( this, arguments ); 1609 }; 1610} 1611return $; 1612}));
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.