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