Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(114)

Side by Side Diff: Calendar.ASP.NET.MVC5/Scripts/jquery.validate.js

Issue 194980043: Issue 6: Create an ASP.Net MVC Sample Base URL: https://google-api-dotnet-client.samples.googlecode.com/hg/
Patch Set: Addressed peleyal's comments Created 9 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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( eve nt ) {
44 if ( validator.settings.submitHandler ) {
45 validator.submitButton = event.target;
46 }
47 // allow suppressing validation by adding a canc el class to the submit button
48 if ( $( event.target ).hasClass( "cancel" ) ) {
49 validator.cancelSubmit = true;
50 }
51
52 // allow suppressing validation by adding the ht ml5 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", v alidator.submitButton.name )
71 .val( $( validat or.submitButton ).val() )
72 .appendTo( valid ator.currentForm );
73 }
74 result = validator.settings.subm itHandler.call( validator, validator.currentForm, event );
75 if ( validator.submitButton ) {
76 // and clean up afterwar ds; 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 su bmit 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, filte red;
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.normalizeRu le( 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 ] = $.ex tend( 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[ meth od ];
159 delete existingRules[ method ];
160 if ( method === "required" ) {
161 $( element ).removeAttr( "aria-r equired" );
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 });
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" ), f unction() {
236 return n;
237 });
238 });
239 return source;
240 };
241
242 $.extend( $.validator, {
243
244 defaults: {
245 messages: {},
246 groups: {},
247 rules: {},
248 errorClass: "error",
249 validClass: "valid",
250 errorElement: "label",
251 focusCleanup: false,
252 focusInvalid: true,
253 errorContainer: $( [] ),
254 errorLabelContainer: $( [] ),
255 onsubmit: true,
256 ignore: ":hidden",
257 ignoreTitle: false,
258 onfocusin: function( element ) {
259 this.lastActive = element;
260
261 // Hide error label and remove error class on focus if e nabled
262 if ( this.settings.focusCleanup ) {
263 if ( this.settings.unhighlight ) {
264 this.settings.unhighlight.call( this, el ement, this.settings.errorClass, this.settings.validClass );
265 }
266 this.hideThese( this.errorsFor( element ) );
267 }
268 },
269 onfocusout: function( element ) {
270 if ( !this.checkable( element ) && ( element.name in thi s.submitted || !this.optional( element ) ) ) {
271 this.element( element );
272 }
273 },
274 onkeyup: function( element, event ) {
275 if ( event.which === 9 && this.elementValue( element ) = == "" ) {
276 return;
277 } else if ( element.name in this.submitted || element == = this.lastElement ) {
278 this.element( element );
279 }
280 },
281 onclick: function( element ) {
282 // click on selects, radiobuttons and checkboxes
283 if ( element.name in this.submitted ) {
284 this.element( element );
285
286 // or option elements, check parent select in that case
287 } else if ( element.parentNode.name in this.submitted ) {
288 this.element( element.parentNode );
289 }
290 },
291 highlight: function( element, errorClass, validClass ) {
292 if ( element.type === "radio" ) {
293 this.findByName( element.name ).addClass( errorC lass ).removeClass( validClass );
294 } else {
295 $( element ).addClass( errorClass ).removeClass( validClass );
296 }
297 },
298 unhighlight: function( element, errorClass, validClass ) {
299 if ( element.type === "radio" ) {
300 this.findByName( element.name ).removeClass( err orClass ).addClass( validClass );
301 } else {
302 $( element ).removeClass( errorClass ).addClass( validClass );
303 }
304 }
305 },
306
307 // http://jqueryvalidation.org/jQuery.validator.setDefaults/
308 setDefaults: function( settings ) {
309 $.extend( $.validator.defaults, settings );
310 },
311
312 messages: {
313 required: "This field is required.",
314 remote: "Please fix this field.",
315 email: "Please enter a valid email address.",
316 url: "Please enter a valid URL.",
317 date: "Please enter a valid date.",
318 dateISO: "Please enter a valid date ( ISO ).",
319 number: "Please enter a valid number.",
320 digits: "Please enter only digits.",
321 creditcard: "Please enter a valid credit card number.",
322 equalTo: "Please enter the same value again.",
323 maxlength: $.validator.format( "Please enter no more than {0} ch aracters." ),
324 minlength: $.validator.format( "Please enter at least {0} charac ters." ),
325 rangelength: $.validator.format( "Please enter a value between { 0} and {1} characters long." ),
326 range: $.validator.format( "Please enter a value between {0} and {1}." ),
327 max: $.validator.format( "Please enter a value less than or equa l to {0}." ),
328 min: $.validator.format( "Please enter a value greater than or e qual to {0}." )
329 },
330
331 autoCreateRanges: false,
332
333 prototype: {
334
335 init: function() {
336 this.labelContainer = $( this.settings.errorLabelContain er );
337 this.errorContext = this.labelContainer.length && this.l abelContainer || $( this.currentForm );
338 this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
339 this.submitted = {};
340 this.valueCache = {};
341 this.pendingRequest = 0;
342 this.pending = {};
343 this.invalid = {};
344 this.reset();
345
346 var groups = ( this.groups = {} ),
347 rules;
348 $.each( this.settings.groups, function( key, value ) {
349 if ( typeof value === "string" ) {
350 value = value.split( /\s/ );
351 }
352 $.each( value, function( index, name ) {
353 groups[ name ] = key;
354 });
355 });
356 rules = this.settings.rules;
357 $.each( rules, function( key, value ) {
358 rules[ key ] = $.validator.normalizeRule( value );
359 });
360
361 function delegate( event ) {
362 var validator = $.data( this[ 0 ].form, "validat or" ),
363 eventType = "on" + event.type.replace( / ^validate/, "" ),
364 settings = validator.settings;
365 if ( settings[ eventType ] && !this.is( settings .ignore ) ) {
366 settings[ eventType ].call( validator, t his[ 0 ], event );
367 }
368 }
369 $( this.currentForm )
370 .validateDelegate( ":text, [type='password'], [t ype='file'], select, textarea, " +
371 "[type='number'], [type='search'] ,[type ='tel'], [type='url'], " +
372 "[type='email'], [type='datetime'], [typ e='date'], [type='month'], " +
373 "[type='week'], [type='time'], [type='da tetime-local'], " +
374 "[type='range'], [type='color'], [type=' radio'], [type='checkbox']",
375 "focusin focusout keyup", delegate)
376 // Support: Chrome, oldIE
377 // "select" is provided as event.target when cli cking a option
378 .validateDelegate("select, option, [type='radio' ], [type='checkbox']", "click", delegate);
379
380 if ( this.settings.invalidHandler ) {
381 $( this.currentForm ).bind( "invalid-form.valida te", this.settings.invalidHandler );
382 }
383
384 // Add aria-required to any Static/Data/Class required f ields before first validation
385 // Screen readers require this attribute to be present b efore the initial submission http://www.w3.org/TR/WCAG-TECHS/ARIA2.html
386 $( this.currentForm ).find( "[required], [data-rule-requ ired], .required" ).attr( "aria-required", "true" );
387 },
388
389 // http://jqueryvalidation.org/Validator.form/
390 form: function() {
391 this.checkForm();
392 $.extend( this.submitted, this.errorMap );
393 this.invalid = $.extend({}, this.errorMap );
394 if ( !this.valid() ) {
395 $( this.currentForm ).triggerHandler( "invalid-f orm", [ this ]);
396 }
397 this.showErrors();
398 return this.valid();
399 },
400
401 checkForm: function() {
402 this.prepareForm();
403 for ( var i = 0, elements = ( this.currentElements = thi s.elements() ); elements[ i ]; i++ ) {
404 this.check( elements[ i ] );
405 }
406 return this.valid();
407 },
408
409 // http://jqueryvalidation.org/Validator.element/
410 element: function( element ) {
411 var cleanElement = this.clean( element ),
412 checkElement = this.validationTargetFor( cleanEl ement ),
413 result = true;
414
415 this.lastElement = checkElement;
416
417 if ( checkElement === undefined ) {
418 delete this.invalid[ cleanElement.name ];
419 } else {
420 this.prepareElement( checkElement );
421 this.currentElements = $( checkElement );
422
423 result = this.check( checkElement ) !== false;
424 if ( result ) {
425 delete this.invalid[ checkElement.name ] ;
426 } else {
427 this.invalid[ checkElement.name ] = true ;
428 }
429 }
430 // Add aria-invalid status for screen readers
431 $( element ).attr( "aria-invalid", !result );
432
433 if ( !this.numberOfInvalids() ) {
434 // Hide error containers on last error
435 this.toHide = this.toHide.add( this.containers ) ;
436 }
437 this.showErrors();
438 return result;
439 },
440
441 // http://jqueryvalidation.org/Validator.showErrors/
442 showErrors: function( errors ) {
443 if ( errors ) {
444 // add items to error list and map
445 $.extend( this.errorMap, errors );
446 this.errorList = [];
447 for ( var name in errors ) {
448 this.errorList.push({
449 message: errors[ name ],
450 element: this.findByName( name ) [ 0 ]
451 });
452 }
453 // remove items from success list
454 this.successList = $.grep( this.successList, fun ction( element ) {
455 return !( element.name in errors );
456 });
457 }
458 if ( this.settings.showErrors ) {
459 this.settings.showErrors.call( this, this.errorM ap, this.errorList );
460 } else {
461 this.defaultShowErrors();
462 }
463 },
464
465 // http://jqueryvalidation.org/Validator.resetForm/
466 resetForm: function() {
467 if ( $.fn.resetForm ) {
468 $( this.currentForm ).resetForm();
469 }
470 this.submitted = {};
471 this.lastElement = null;
472 this.prepareForm();
473 this.hideErrors();
474 this.elements()
475 .removeClass( this.settings.errorClass )
476 .removeData( "previousValue" )
477 .removeAttr( "aria-invalid" );
478 },
479
480 numberOfInvalids: function() {
481 return this.objectLength( this.invalid );
482 },
483
484 objectLength: function( obj ) {
485 /* jshint unused: false */
486 var count = 0,
487 i;
488 for ( i in obj ) {
489 count++;
490 }
491 return count;
492 },
493
494 hideErrors: function() {
495 this.hideThese( this.toHide );
496 },
497
498 hideThese: function( errors ) {
499 errors.not( this.containers ).text( "" );
500 this.addWrapper( errors ).hide();
501 },
502
503 valid: function() {
504 return this.size() === 0;
505 },
506
507 size: function() {
508 return this.errorList.length;
509 },
510
511 focusInvalid: function() {
512 if ( this.settings.focusInvalid ) {
513 try {
514 $( this.findLastActive() || this.errorLi st.length && this.errorList[ 0 ].element || [])
515 .filter( ":visible" )
516 .focus()
517 // manually trigger focusin event; witho ut it, focusin handler isn't called, findLastActive won't have anything to find
518 .trigger( "focusin" );
519 } catch ( e ) {
520 // ignore IE throwing errors when focusi ng hidden elements
521 }
522 }
523 },
524
525 findLastActive: function() {
526 var lastActive = this.lastActive;
527 return lastActive && $.grep( this.errorList, function( n ) {
528 return n.element.name === lastActive.name;
529 }).length === 1 && lastActive;
530 },
531
532 elements: function() {
533 var validator = this,
534 rulesCache = {};
535
536 // select all valid inputs inside the form (no submit or reset buttons)
537 return $( this.currentForm )
538 .find( "input, select, textarea" )
539 .not( ":submit, :reset, :image, [disabled], [readonly]" )
540 .not( this.settings.ignore )
541 .filter( function() {
542 if ( !this.name && validator.settings.debug && w indow.console ) {
543 console.error( "%o has no name assigned" , this );
544 }
545
546 // select only the first element for each name, and only those with rules specified
547 if ( this.name in rulesCache || !validator.objec tLength( $( this ).rules() ) ) {
548 return false;
549 }
550
551 rulesCache[ this.name ] = true;
552 return true;
553 });
554 },
555
556 clean: function( selector ) {
557 return $( selector )[ 0 ];
558 },
559
560 errors: function() {
561 var errorClass = this.settings.errorClass.split( " " ).j oin( "." );
562 return $( this.settings.errorElement + "." + errorClass, this.errorContext );
563 },
564
565 reset: function() {
566 this.successList = [];
567 this.errorList = [];
568 this.errorMap = {};
569 this.toShow = $( [] );
570 this.toHide = $( [] );
571 this.currentElements = $( [] );
572 },
573
574 prepareForm: function() {
575 this.reset();
576 this.toHide = this.errors().add( this.containers );
577 },
578
579 prepareElement: function( element ) {
580 this.reset();
581 this.toHide = this.errorsFor( element );
582 },
583
584 elementValue: function( element ) {
585 var val,
586 $element = $( element ),
587 type = element.type;
588
589 if ( type === "radio" || type === "checkbox" ) {
590 return $( "input[name='" + element.name + "']:ch ecked" ).val();
591 } else if ( type === "number" && typeof element.validity !== "undefined" ) {
592 return element.validity.badInput ? false : $elem ent.val();
593 }
594
595 val = $element.val();
596 if ( typeof val === "string" ) {
597 return val.replace(/\r/g, "" );
598 }
599 return val;
600 },
601
602 check: function( element ) {
603 element = this.validationTargetFor( this.clean( element ) );
604
605 var rules = $( element ).rules(),
606 rulesCount = $.map( rules, function( n, i ) {
607 return i;
608 }).length,
609 dependencyMismatch = false,
610 val = this.elementValue( element ),
611 result, method, rule;
612
613 for ( method in rules ) {
614 rule = { method: method, parameters: rules[ meth od ] };
615 try {
616
617 result = $.validator.methods[ method ].c all( this, val, element, rule.parameters );
618
619 // if a method indicates that the field is optional and therefore valid,
620 // don't mark it as valid when there are no other rules
621 if ( result === "dependency-mismatch" && rulesCount === 1 ) {
622 dependencyMismatch = true;
623 continue;
624 }
625 dependencyMismatch = false;
626
627 if ( result === "pending" ) {
628 this.toHide = this.toHide.not( t his.errorsFor( element ) );
629 return;
630 }
631
632 if ( !result ) {
633 this.formatAndAdd( element, rule );
634 return false;
635 }
636 } catch ( e ) {
637 if ( this.settings.debug && window.conso le ) {
638 console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' metho d.", e );
639 }
640 throw e;
641 }
642 }
643 if ( dependencyMismatch ) {
644 return;
645 }
646 if ( this.objectLength( rules ) ) {
647 this.successList.push( element );
648 }
649 return true;
650 },
651
652 // return the custom message for the given element and validatio n method
653 // specified in the element's HTML5 data attribute
654 // return the generic message if present and no method specific message is present
655 customDataMessage: function( element, method ) {
656 return $( element ).data( "msg" + method.charAt( 0 ).toU pperCase() +
657 method.substring( 1 ).toLowerCase() ) || $( elem ent ).data( "msg" );
658 },
659
660 // return the custom message for the given element name and vali dation method
661 customMessage: function( name, method ) {
662 var m = this.settings.messages[ name ];
663 return m && ( m.constructor === String ? m : m[ method ] );
664 },
665
666 // return the first defined argument, allowing empty strings
667 findDefined: function() {
668 for ( var i = 0; i < arguments.length; i++) {
669 if ( arguments[ i ] !== undefined ) {
670 return arguments[ i ];
671 }
672 }
673 return undefined;
674 },
675
676 defaultMessage: function( element, method ) {
677 return this.findDefined(
678 this.customMessage( element.name, method ),
679 this.customDataMessage( element, method ),
680 // title is never undefined, so handle empty str ing as undefined
681 !this.settings.ignoreTitle && element.title || u ndefined,
682 $.validator.messages[ method ],
683 "<strong>Warning: No message defined for " + ele ment.name + "</strong>"
684 );
685 },
686
687 formatAndAdd: function( element, rule ) {
688 var message = this.defaultMessage( element, rule.method ),
689 theregex = /\$?\{(\d+)\}/g;
690 if ( typeof message === "function" ) {
691 message = message.call( this, rule.parameters, e lement );
692 } else if ( theregex.test( message ) ) {
693 message = $.validator.format( message.replace( t heregex, "{$1}" ), rule.parameters );
694 }
695 this.errorList.push({
696 message: message,
697 element: element,
698 method: rule.method
699 });
700
701 this.errorMap[ element.name ] = message;
702 this.submitted[ element.name ] = message;
703 },
704
705 addWrapper: function( toToggle ) {
706 if ( this.settings.wrapper ) {
707 toToggle = toToggle.add( toToggle.parent( this.s ettings.wrapper ) );
708 }
709 return toToggle;
710 },
711
712 defaultShowErrors: function() {
713 var i, elements, error;
714 for ( i = 0; this.errorList[ i ]; i++ ) {
715 error = this.errorList[ i ];
716 if ( this.settings.highlight ) {
717 this.settings.highlight.call( this, erro r.element, this.settings.errorClass, this.settings.validClass );
718 }
719 this.showLabel( error.element, error.message );
720 }
721 if ( this.errorList.length ) {
722 this.toShow = this.toShow.add( this.containers ) ;
723 }
724 if ( this.settings.success ) {
725 for ( i = 0; this.successList[ i ]; i++ ) {
726 this.showLabel( this.successList[ i ] );
727 }
728 }
729 if ( this.settings.unhighlight ) {
730 for ( i = 0, elements = this.validElements(); el ements[ i ]; i++ ) {
731 this.settings.unhighlight.call( this, el ements[ i ], this.settings.errorClass, this.settings.validClass );
732 }
733 }
734 this.toHide = this.toHide.not( this.toShow );
735 this.hideErrors();
736 this.addWrapper( this.toShow ).show();
737 },
738
739 validElements: function() {
740 return this.currentElements.not( this.invalidElements() );
741 },
742
743 invalidElements: function() {
744 return $( this.errorList ).map(function() {
745 return this.element;
746 });
747 },
748
749 showLabel: function( element, message ) {
750 var place, group, errorID,
751 error = this.errorsFor( element ),
752 elementID = this.idOrName( element ),
753 describedBy = $( element ).attr( "aria-described by" );
754 if ( error.length ) {
755 // refresh error/success class
756 error.removeClass( this.settings.validClass ).ad dClass( this.settings.errorClass );
757 // replace message on existing label
758 error.html( message );
759 } else {
760 // create error element
761 error = $( "<" + this.settings.errorElement + "> " )
762 .attr( "id", elementID + "-error" )
763 .addClass( this.settings.errorClass )
764 .html( message || "" );
765
766 // Maintain reference to the element to be place d into the DOM
767 place = error;
768 if ( this.settings.wrapper ) {
769 // make sure the element is visible, eve n in IE
770 // actually showing the wrapped element is handled elsewhere
771 place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent();
772 }
773 if ( this.labelContainer.length ) {
774 this.labelContainer.append( place );
775 } else if ( this.settings.errorPlacement ) {
776 this.settings.errorPlacement( place, $( element ) );
777 } else {
778 place.insertAfter( element );
779 }
780
781 // Link error back to the element
782 if ( error.is( "label" ) ) {
783 // If the error is a label, then associa te using 'for'
784 error.attr( "for", elementID );
785 } else if ( error.parents( "label[for='" + eleme ntID + "']" ).length === 0 ) {
786 // If the element is not a child of an a ssociated label, then it's necessary
787 // to explicitly apply aria-describedby
788
789 errorID = error.attr( "id" ).replace( /( :|\.|\[|\])/g, "\\$1");
790 // Respect existing non-error aria-descr ibedby
791 if ( !describedBy ) {
792 describedBy = errorID;
793 } else if ( !describedBy.match( new RegE xp( "\\b" + errorID + "\\b" ) ) ) {
794 // Add to end of list if not alr eady present
795 describedBy += " " + errorID;
796 }
797 $( element ).attr( "aria-describedby", d escribedBy );
798
799 // If this element is grouped, then assi gn to all elements in the same group
800 group = this.groups[ element.name ];
801 if ( group ) {
802 $.each( this.groups, function( n ame, testgroup ) {
803 if ( testgroup === group ) {
804 $( "[name='" + n ame + "']", this.currentForm )
805 .attr( " aria-describedby", error.attr( "id" ) );
806 }
807 });
808 }
809 }
810 }
811 if ( !message && this.settings.success ) {
812 error.text( "" );
813 if ( typeof this.settings.success === "string" ) {
814 error.addClass( this.settings.success );
815 } else {
816 this.settings.success( error, element );
817 }
818 }
819 this.toShow = this.toShow.add( error );
820 },
821
822 errorsFor: function( element ) {
823 var name = this.idOrName( element ),
824 describer = $( element ).attr( "aria-describedby " ),
825 selector = "label[for='" + name + "'], label[for ='" + name + "'] *";
826
827 // aria-describedby should directly reference the error element
828 if ( describer ) {
829 selector = selector + ", #" + describer.replace( /\s+/g, ", #" );
830 }
831 return this
832 .errors()
833 .filter( selector );
834 },
835
836 idOrName: function( element ) {
837 return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name );
838 },
839
840 validationTargetFor: function( element ) {
841
842 // If radio/checkbox, validate first element in group in stead
843 if ( this.checkable( element ) ) {
844 element = this.findByName( element.name );
845 }
846
847 // Always apply ignore filter
848 return $( element ).not( this.settings.ignore )[ 0 ];
849 },
850
851 checkable: function( element ) {
852 return ( /radio|checkbox/i ).test( element.type );
853 },
854
855 findByName: function( name ) {
856 return $( this.currentForm ).find( "[name='" + name + "' ]" );
857 },
858
859 getLength: function( value, element ) {
860 switch ( element.nodeName.toLowerCase() ) {
861 case "select":
862 return $( "option:selected", element ).length;
863 case "input":
864 if ( this.checkable( element ) ) {
865 return this.findByName( element.name ).f ilter( ":checked" ).length;
866 }
867 }
868 return value.length;
869 },
870
871 depend: function( param, element ) {
872 return this.dependTypes[typeof param] ? this.dependTypes [typeof param]( param, element ) : true;
873 },
874
875 dependTypes: {
876 "boolean": function( param ) {
877 return param;
878 },
879 "string": function( param, element ) {
880 return !!$( param, element.form ).length;
881 },
882 "function": function( param, element ) {
883 return param( element );
884 }
885 },
886
887 optional: function( element ) {
888 var val = this.elementValue( element );
889 return !$.validator.methods.required.call( this, val, el ement ) && "dependency-mismatch";
890 },
891
892 startRequest: function( element ) {
893 if ( !this.pending[ element.name ] ) {
894 this.pendingRequest++;
895 this.pending[ element.name ] = true;
896 }
897 },
898
899 stopRequest: function( element, valid ) {
900 this.pendingRequest--;
901 // sometimes synchronization fails, make sure pendingReq uest is never < 0
902 if ( this.pendingRequest < 0 ) {
903 this.pendingRequest = 0;
904 }
905 delete this.pending[ element.name ];
906 if ( valid && this.pendingRequest === 0 && this.formSubm itted && this.form() ) {
907 $( this.currentForm ).submit();
908 this.formSubmitted = false;
909 } else if (!valid && this.pendingRequest === 0 && this.f ormSubmitted ) {
910 $( this.currentForm ).triggerHandler( "invalid-f orm", [ this ]);
911 this.formSubmitted = false;
912 }
913 },
914
915 previousValue: function( element ) {
916 return $.data( element, "previousValue" ) || $.data( ele ment, "previousValue", {
917 old: null,
918 valid: true,
919 message: this.defaultMessage( element, "remote" )
920 });
921 }
922
923 },
924
925 classRuleSettings: {
926 required: { required: true },
927 email: { email: true },
928 url: { url: true },
929 date: { date: true },
930 dateISO: { dateISO: true },
931 number: { number: true },
932 digits: { digits: true },
933 creditcard: { creditcard: true }
934 },
935
936 addClassRules: function( className, rules ) {
937 if ( className.constructor === String ) {
938 this.classRuleSettings[ className ] = rules;
939 } else {
940 $.extend( this.classRuleSettings, className );
941 }
942 },
943
944 classRules: function( element ) {
945 var rules = {},
946 classes = $( element ).attr( "class" );
947
948 if ( classes ) {
949 $.each( classes.split( " " ), function() {
950 if ( this in $.validator.classRuleSettings ) {
951 $.extend( rules, $.validator.classRuleSe ttings[ this ]);
952 }
953 });
954 }
955 return rules;
956 },
957
958 attributeRules: function( element ) {
959 var rules = {},
960 $element = $( element ),
961 type = element.getAttribute( "type" ),
962 method, value;
963
964 for ( method in $.validator.methods ) {
965
966 // support for <input required> in both html5 and older browsers
967 if ( method === "required" ) {
968 value = element.getAttribute( method );
969 // Some browsers return an empty string for the required attribute
970 // and non-HTML5 browsers might have required="" markup
971 if ( value === "" ) {
972 value = true;
973 }
974 // force non-HTML5 browsers to return bool
975 value = !!value;
976 } else {
977 value = $element.attr( method );
978 }
979
980 // convert the value to a number for number inputs, and for text for backwards compability
981 // allows type="date" and others to be compared as strin gs
982 if ( /min|max/.test( method ) && ( type === null || /num ber|range|text/.test( type ) ) ) {
983 value = Number( value );
984 }
985
986 if ( value || value === 0 ) {
987 rules[ method ] = value;
988 } else if ( type === method && type !== "range" ) {
989 // exception: the jquery validate 'range' method
990 // does not test for the html5 'range' type
991 rules[ method ] = true;
992 }
993 }
994
995 // maxlength may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs
996 if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxle ngth ) ) {
997 delete rules.maxlength;
998 }
999
1000 return rules;
1001 },
1002
1003 dataRules: function( element ) {
1004 var method, value,
1005 rules = {}, $element = $( element );
1006 for ( method in $.validator.methods ) {
1007 value = $element.data( "rule" + method.charAt( 0 ).toUpp erCase() + method.substring( 1 ).toLowerCase() );
1008 if ( value !== undefined ) {
1009 rules[ method ] = value;
1010 }
1011 }
1012 return rules;
1013 },
1014
1015 staticRules: function( element ) {
1016 var rules = {},
1017 validator = $.data( element.form, "validator" );
1018
1019 if ( validator.settings.rules ) {
1020 rules = $.validator.normalizeRule( validator.settings.ru les[ element.name ] ) || {};
1021 }
1022 return rules;
1023 },
1024
1025 normalizeRules: function( rules, element ) {
1026 // handle dependency check
1027 $.each( rules, function( prop, val ) {
1028 // ignore rule when param is explicitly false, eg. requi red:false
1029 if ( val === false ) {
1030 delete rules[ prop ];
1031 return;
1032 }
1033 if ( val.param || val.depends ) {
1034 var keepRule = true;
1035 switch ( typeof val.depends ) {
1036 case "string":
1037 keepRule = !!$( val.depends, element.for m ).length;
1038 break;
1039 case "function":
1040 keepRule = val.depends.call( element, el ement );
1041 break;
1042 }
1043 if ( keepRule ) {
1044 rules[ prop ] = val.param !== undefined ? val.param : true;
1045 } else {
1046 delete rules[ prop ];
1047 }
1048 }
1049 });
1050
1051 // evaluate parameters
1052 $.each( rules, function( rule, parameter ) {
1053 rules[ rule ] = $.isFunction( parameter ) ? parameter( e lement ) : parameter;
1054 });
1055
1056 // clean number parameters
1057 $.each([ "minlength", "maxlength" ], function() {
1058 if ( rules[ this ] ) {
1059 rules[ this ] = Number( rules[ this ] );
1060 }
1061 });
1062 $.each([ "rangelength", "range" ], function() {
1063 var parts;
1064 if ( rules[ this ] ) {
1065 if ( $.isArray( rules[ this ] ) ) {
1066 rules[ this ] = [ Number( rules[ this ][ 0 ]), Number( rules[ this ][ 1 ] ) ];
1067 } else if ( typeof rules[ this ] === "string" ) {
1068 parts = rules[ this ].replace(/[\[\]]/g, "" ).split( /[\s,]+/ );
1069 rules[ this ] = [ Number( parts[ 0 ]), N umber( parts[ 1 ] ) ];
1070 }
1071 }
1072 });
1073
1074 if ( $.validator.autoCreateRanges ) {
1075 // auto-create ranges
1076 if ( rules.min != null && rules.max != null ) {
1077 rules.range = [ rules.min, rules.max ];
1078 delete rules.min;
1079 delete rules.max;
1080 }
1081 if ( rules.minlength != null && rules.maxlength != null ) {
1082 rules.rangelength = [ rules.minlength, rules.max length ];
1083 delete rules.minlength;
1084 delete rules.maxlength;
1085 }
1086 }
1087
1088 return rules;
1089 },
1090
1091 // Converts a simple string to a {string: true} rule, e.g., "required" t o {required:true}
1092 normalizeRule: function( data ) {
1093 if ( typeof data === "string" ) {
1094 var transformed = {};
1095 $.each( data.split( /\s/ ), function() {
1096 transformed[ this ] = true;
1097 });
1098 data = transformed;
1099 }
1100 return data;
1101 },
1102
1103 // http://jqueryvalidation.org/jQuery.validator.addMethod/
1104 addMethod: function( name, method, message ) {
1105 $.validator.methods[ name ] = method;
1106 $.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ];
1107 if ( method.length < 3 ) {
1108 $.validator.addClassRules( name, $.validator.normalizeRu le( name ) );
1109 }
1110 },
1111
1112 methods: {
1113
1114 // http://jqueryvalidation.org/required-method/
1115 required: function( value, element, param ) {
1116 // check if dependency is met
1117 if ( !this.depend( param, element ) ) {
1118 return "dependency-mismatch";
1119 }
1120 if ( element.nodeName.toLowerCase() === "select" ) {
1121 // could be an array for select-multiple or a st ring, both are fine this way
1122 var val = $( element ).val();
1123 return val && val.length > 0;
1124 }
1125 if ( this.checkable( element ) ) {
1126 return this.getLength( value, element ) > 0;
1127 }
1128 return $.trim( value ).length > 0;
1129 },
1130
1131 // http://jqueryvalidation.org/email-method/
1132 email: function( value, element ) {
1133 // From http://www.whatwg.org/specs/web-apps/current-wor k/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29
1134 // Retrieved 2014-01-14
1135 // If you have a problem with this implementation, repor t a bug against the above spec
1136 // Or use custom methods to implement your own email val idation
1137 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 );
1138 },
1139
1140 // http://jqueryvalidation.org/url-method/
1141 url: function( value, element ) {
1142 // contributed by Scott Gonzalez: http://projects.scotts playground.com/iri/
1143 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\uF90 0-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\. )+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF90 0-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFF EF])*([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-\uD7F F\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8 FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|( %[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test( value );
1144 },
1145
1146 // http://jqueryvalidation.org/date-method/
1147 date: function( value, element ) {
1148 return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
1149 },
1150
1151 // http://jqueryvalidation.org/dateISO-method/
1152 dateISO: function( value, element ) {
1153 return this.optional( element ) || /^\d{4}[\/\-](0?[1-9] |1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
1154 },
1155
1156 // http://jqueryvalidation.org/number-method/
1157 number: function( value, element ) {
1158 return this.optional( element ) || /^-?(?:\d+|\d{1,3}(?: ,\d{3})+)?(?:\.\d+)?$/.test( value );
1159 },
1160
1161 // http://jqueryvalidation.org/digits-method/
1162 digits: function( value, element ) {
1163 return this.optional( element ) || /^\d+$/.test( value ) ;
1164 },
1165
1166 // http://jqueryvalidation.org/creditcard-method/
1167 // based on http://en.wikipedia.org/wiki/Luhn/
1168 creditcard: function( value, element ) {
1169 if ( this.optional( element ) ) {
1170 return "dependency-mismatch";
1171 }
1172 // accept only spaces, digits and dashes
1173 if ( /[^0-9 \-]+/.test( value ) ) {
1174 return false;
1175 }
1176 var nCheck = 0,
1177 nDigit = 0,
1178 bEven = false,
1179 n, cDigit;
1180
1181 value = value.replace( /\D/g, "" );
1182
1183 // Basing min and max length on
1184 // http://developer.ean.com/general_info/Valid_Credit_Ca rd_Types
1185 if ( value.length < 13 || value.length > 19 ) {
1186 return false;
1187 }
1188
1189 for ( n = value.length - 1; n >= 0; n--) {
1190 cDigit = value.charAt( n );
1191 nDigit = parseInt( cDigit, 10 );
1192 if ( bEven ) {
1193 if ( ( nDigit *= 2 ) > 9 ) {
1194 nDigit -= 9;
1195 }
1196 }
1197 nCheck += nDigit;
1198 bEven = !bEven;
1199 }
1200
1201 return ( nCheck % 10 ) === 0;
1202 },
1203
1204 // http://jqueryvalidation.org/minlength-method/
1205 minlength: function( value, element, param ) {
1206 var length = $.isArray( value ) ? value.length : this.ge tLength( value, element );
1207 return this.optional( element ) || length >= param;
1208 },
1209
1210 // http://jqueryvalidation.org/maxlength-method/
1211 maxlength: function( value, element, param ) {
1212 var length = $.isArray( value ) ? value.length : this.ge tLength( value, element );
1213 return this.optional( element ) || length <= param;
1214 },
1215
1216 // http://jqueryvalidation.org/rangelength-method/
1217 rangelength: function( value, element, param ) {
1218 var length = $.isArray( value ) ? value.length : this.ge tLength( value, element );
1219 return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
1220 },
1221
1222 // http://jqueryvalidation.org/min-method/
1223 min: function( value, element, param ) {
1224 return this.optional( element ) || value >= param;
1225 },
1226
1227 // http://jqueryvalidation.org/max-method/
1228 max: function( value, element, param ) {
1229 return this.optional( element ) || value <= param;
1230 },
1231
1232 // http://jqueryvalidation.org/range-method/
1233 range: function( value, element, param ) {
1234 return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] );
1235 },
1236
1237 // http://jqueryvalidation.org/equalTo-method/
1238 equalTo: function( value, element, param ) {
1239 // bind to the blur event of the target in order to reva lidate whenever the target field is updated
1240 // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
1241 var target = $( param );
1242 if ( this.settings.onfocusout ) {
1243 target.unbind( ".validate-equalTo" ).bind( "blur .validate-equalTo", function() {
1244 $( element ).valid();
1245 });
1246 }
1247 return value === target.val();
1248 },
1249
1250 // http://jqueryvalidation.org/remote-method/
1251 remote: function( value, element, param ) {
1252 if ( this.optional( element ) ) {
1253 return "dependency-mismatch";
1254 }
1255
1256 var previous = this.previousValue( element ),
1257 validator, data;
1258
1259 if (!this.settings.messages[ element.name ] ) {
1260 this.settings.messages[ element.name ] = {};
1261 }
1262 previous.originalMessage = this.settings.messages[ eleme nt.name ].remote;
1263 this.settings.messages[ element.name ].remote = previous .message;
1264
1265 param = typeof param === "string" && { url: param } || p aram;
1266
1267 if ( previous.old === value ) {
1268 return previous.valid;
1269 }
1270
1271 previous.old = value;
1272 validator = this;
1273 this.startRequest( element );
1274 data = {};
1275 data[ element.name ] = value;
1276 $.ajax( $.extend( true, {
1277 url: param,
1278 mode: "abort",
1279 port: "validate" + element.name,
1280 dataType: "json",
1281 data: data,
1282 context: validator.currentForm,
1283 success: function( response ) {
1284 var valid = response === true || respons e === "true",
1285 errors, message, submitted;
1286
1287 validator.settings.messages[ element.nam e ].remote = previous.originalMessage;
1288 if ( valid ) {
1289 submitted = validator.formSubmit ted;
1290 validator.prepareElement( elemen t );
1291 validator.formSubmitted = submit ted;
1292 validator.successList.push( elem ent );
1293 delete validator.invalid[ elemen t.name ];
1294 validator.showErrors();
1295 } else {
1296 errors = {};
1297 message = response || validator. defaultMessage( element, "remote" );
1298 errors[ element.name ] = previou s.message = $.isFunction( message ) ? message( value ) : message;
1299 validator.invalid[ element.name ] = true;
1300 validator.showErrors( errors );
1301 }
1302 previous.valid = valid;
1303 validator.stopRequest( element, valid );
1304 }
1305 }, param ) );
1306 return "pending";
1307 }
1308
1309 }
1310
1311 });
1312
1313 $.format = function deprecated() {
1314 throw "$.format has been deprecated. Please use $.validator.format inste ad.";
1315 };
1316
1317 // ajax mode: abort
1318 // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1319 // if mode:"abort" is used, the previous request on that port (port can be undef ined) is aborted via XMLHttpRequest.abort()
1320
1321 var pendingRequests = {},
1322 ajax;
1323 // Use a prefilter if available (1.5+)
1324 if ( $.ajaxPrefilter ) {
1325 $.ajaxPrefilter(function( settings, _, xhr ) {
1326 var port = settings.port;
1327 if ( settings.mode === "abort" ) {
1328 if ( pendingRequests[port] ) {
1329 pendingRequests[port].abort();
1330 }
1331 pendingRequests[port] = xhr;
1332 }
1333 });
1334 } else {
1335 // Proxy ajax
1336 ajax = $.ajax;
1337 $.ajax = function( settings ) {
1338 var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mo de,
1339 port = ( "port" in settings ? settings : $.ajaxSettings ).port;
1340 if ( mode === "abort" ) {
1341 if ( pendingRequests[port] ) {
1342 pendingRequests[port].abort();
1343 }
1344 pendingRequests[port] = ajax.apply(this, arguments);
1345 return pendingRequests[port];
1346 }
1347 return ajax.apply(this, arguments);
1348 };
1349 }
1350
1351 // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
1352 // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
1353
1354 $.extend($.fn, {
1355 validateDelegate: function( delegate, type, handler ) {
1356 return this.bind(type, function( event ) {
1357 var target = $(event.target);
1358 if ( target.is(delegate) ) {
1359 return handler.apply(target, arguments);
1360 }
1361 });
1362 }
1363 });
1364
1365 }));
OLDNEW
« no previous file with comments | « Calendar.ASP.NET.MVC5/Scripts/jquery-2.1.3.min.map ('k') | Calendar.ASP.NET.MVC5/Scripts/jquery.validate-vsdoc.js » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b