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