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