Changeset 4040
- Timestamp:
- 12/06/07 15:36:17 (9 months ago)
- Location:
- trunk/plugins/validate
- Files:
-
- 6 modified
-
changelog.txt (modified) (1 diff)
-
demo-test/js/jquery.js (modified) (78 diffs)
-
demo-test/js/test.js (modified) (4 diffs)
-
demo-test/test.html (modified) (1 diff)
-
jquery.validate.js (modified) (7 diffs)
-
todo (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/validate/changelog.txt
r3948 r4040 9 9 * Added support for ajax-validation, see method "remote" 10 10 * Added highlight and unhighlight options, by default toggles errorClass on element, allows custom highlighting 11 * Added valid() plugin method for easy programmatic checking of forms and fields without the need to use the validator API 12 * Replaced regex for URL method, thanks to the contribution by Scott Gonzales, see http://www.scottsplayground.com/temp/iri/common.htm 11 13 * Fixed error container to hide when all elements are valid, not only on form submit 12 14 * Fixed String.format to jQuery.format (moving into jQuery namespace) 13 * Improved URL and email methods (now blacklisting illegal characters to make them much more versatile when dealing with unicode characters, like http://www.føtex.dk/15 * Improved email method to better handle unicode characters 14 16 * Fixed accept method to accept both upper and lowercase extensions 15 * Changed debug-mode console log to warn level 17 * Changed debug-mode console log from "error" to "warn" level 18 * Fixed validate() plugin method to create only one validator instance for a given form and always return that one instance (avoids binding events multiple times) 16 19 17 20 1.1.1 -
trunk/plugins/validate/demo-test/js/jquery.js
r3864 r4040 1 1 (function(){ 2 2 /* 3 * jQuery 1.2. 1- New Wave Javascript3 * jQuery 1.2.2-pre - New Wave Javascript 4 4 * 5 5 * Copyright (c) 2007 John Resig (jquery.com) … … 7 7 * and GPL (GPL-LICENSE.txt) licenses. 8 8 * 9 * $Date: 2007- 09-16 23:42:06 -0400 (Sun, 16 Sep2007) $10 * $Rev: 3353$9 * $Date: 2007-12-05 06:01:46 +0100 (Mit, 05 Dez 2007) $ 10 * $Rev: 4031 $ 11 11 */ 12 12 13 13 // Map over jQuery in case of overwrite 14 if ( typeof jQuery != "undefined")15 var _jQuery = jQuery;16 17 var jQuery = window.jQuery = function( selector, context) {14 if ( window.jQuery ) 15 var _jQuery = window.jQuery; 16 17 var jQuery = window.jQuery = function( selector, context ) { 18 18 // If the context is a namespace object, return a new object 19 19 return this instanceof jQuery ? 20 this.init( selector, context) :21 new jQuery( selector, context);20 this.init( selector, context ) : 21 new jQuery( selector, context ); 22 22 }; 23 23 24 24 // Map over the $ in case of overwrite 25 if ( typeof $ != "undefined")26 var _$ = $;25 if ( window.$ ) 26 var _$ = window.$; 27 27 28 28 // Map the jQuery namespace to the '$' one 29 29 window.$ = jQuery; 30 30 31 // A simple way to check for HTML strings or ID strings 32 // (both of which we optimize for) 31 33 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; 32 34 33 35 jQuery.fn = jQuery.prototype = { 34 init: function( selector, context) {36 init: function( selector, context ) { 35 37 // Make sure that a selection was provided 36 38 selector = selector || document; 37 39 40 // Handle $(DOMElement) 41 if ( selector.nodeType ) { 42 this[0] = selector; 43 this.length = 1; 44 return this; 45 38 46 // Handle HTML strings 39 if ( typeof selector == "string" ) { 40 var m = quickExpr.exec(selector); 41 if ( m && (m[1] || !context) ) { 47 } else if ( typeof selector == "string" ) { 48 // Are we dealing with HTML string or an ID? 49 var match = quickExpr.exec( selector ); 50 51 // Verify a match, and that no context was specified for #id 52 if ( match && (match[1] || !context) ) { 53 42 54 // HANDLE: $(html) -> $(array) 43 if ( m [1] )44 selector = jQuery.clean( [ m [1] ], context );55 if ( match[1] ) 56 selector = jQuery.clean( [ match[1] ], context ); 45 57 46 58 // HANDLE: $("#id") 47 59 else { 48 var tmp = document.getElementById( m[3] ); 49 if ( tmp ) 60 var elem = document.getElementById( match[3] ); 61 62 // Make sure an element was located 63 if ( elem ) 50 64 // Handle the case where IE and Opera return items 51 65 // by name instead of ID 52 if ( tmp.id != m[3] )66 if ( elem.id != match[3] ) 53 67 return jQuery().find( selector ); 68 69 // Otherwise, we inject the element directly into the jQuery object 54 70 else { 55 this[0] = tmp;71 this[0] = elem; 56 72 this.length = 1; 57 73 return this; 58 74 } 75 59 76 else 60 77 selector = []; 61 78 } 62 79 63 // HANDLE: $(expr) 80 // HANDLE: $(expr, [context]) 81 // (which is just equivalent to: $(content).find(expr) 64 82 } else 65 83 return new jQuery( context ).find( selector ); … … 67 85 // HANDLE: $(function) 68 86 // Shortcut for document ready 69 } else if ( jQuery.isFunction( selector) )70 return new jQuery( document)[ jQuery.fn.ready ? "ready" : "load" ]( selector );87 } else if ( jQuery.isFunction( selector ) ) 88 return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); 71 89 72 90 return this.setArray( … … 75 93 76 94 // HANDLE: $(arraylike) 77 // Watch for when an array-like object is passedas the selector95 // Watch for when an array-like object, contains DOM nodes, is passed in as the selector 78 96 (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || 79 97 … … 82 100 }, 83 101 84 jquery: "1.2.1", 85 102 // The current version of jQuery being used 103 jquery: "@VERSION", 104 105 // The number of elements contained in the matched element set 86 106 size: function() { 87 107 return this.length; 88 108 }, 89 109 110 // The number of elements contained in the matched element set 90 111 length: 0, 91 112 113 // Get the Nth element in the matched element set OR 114 // Get the whole matched element set as a clean array 92 115 get: function( num ) { 93 116 return num == undefined ? … … 97 120 98 121 // Return just the object 99 this[num]; 100 }, 101 102 pushStack: function( a ) { 103 var ret = jQuery(a); 122 this[ num ]; 123 }, 124 125 // Take an array of elements and push it onto the stack 126 // (returning the new matched element set) 127 pushStack: function( elems ) { 128 // Build a new jQuery matched element set 129 var ret = jQuery( elems ); 130 131 // Add the old object onto the stack (as a reference) 104 132 ret.prevObject = this; 133 134 // Return the newly-formed element set 105 135 return ret; 106 136 }, 107 137 108 setArray: function( a ) { 138 // Force the current matched set of elements to become 139 // the specified array of elements (destroying the stack in the process) 140 // You should use pushStack() in order to do this, but maintain the stack 141 setArray: function( elems ) { 142 // Resetting the length to 0, then using the native Array push 143 // is a super-fast way to populate an object with array-like properties 109 144 this.length = 0; 110 Array.prototype.push.apply( this, a ); 145 Array.prototype.push.apply( this, elems ); 146 111 147 return this; 112 148 }, 113 149 114 each: function( fn, args ) { 115 return jQuery.each( this, fn, args ); 116 }, 117 118 index: function( obj ) { 119 var pos = -1; 150 // Execute a callback for every element in the matched set. 151 // (You can seed the arguments with an array of args, but this is 152 // only used internally.) 153 each: function( callback, args ) { 154 return jQuery.each( this, callback, args ); 155 }, 156 157 // Determine the position of an element within 158 // the matched set of elements 159 index: function( elem ) { 160 var ret = -1; 161 162 // Locate the position of the desired element 120 163 this.each(function(i){ 121 if ( this == obj ) pos = i; 164 if ( this == elem ) 165 ret = i; 122 166 }); 123 return pos; 124 }, 125 126 attr: function( key, value, type ) { 127 var obj = key; 167 168 return ret; 169 }, 170 171 attr: function( name, value, type ) { 172 var options = name; 128 173 129 174 // Look for the case where we're accessing a style value 130 if ( key.constructor == String )175 if ( name.constructor == String ) 131 176 if ( value == undefined ) 132 return this.length && jQuery[ type || "attr" ]( this[0], key ) || undefined; 177 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined; 178 133 179 else { 134 o bj= {};135 o bj[ key] = value;180 options = {}; 181 options[ name ] = value; 136 182 } 137 183 138 184 // Check to see if we're setting style values 139 return this.each(function(i ndex){185 return this.each(function(i){ 140 186 // Set all the styles 141 for ( var prop in obj)187 for ( name in options ) 142 188 jQuery.attr( 143 type ? this.style : this, 144 prop, jQuery.prop(this, obj[prop], type, index, prop) 189 type ? 190 this.style : 191 this, 192 name, jQuery.prop( this, options[ name ], type, i, name ) 145 193 ); 146 194 }); … … 148 196 149 197 css: function( key, value ) { 198 // ignore negative width and height values 199 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) 200 value = undefined; 150 201 return this.attr( key, value, "curCSS" ); 151 202 }, 152 203 153 text: function(e) { 154 if ( typeof e != "object" && e != null ) 155 return this.empty().append( document.createTextNode( e ) ); 156 157 var t = ""; 158 jQuery.each( e || this, function(){ 204 text: function( text ) { 205 if ( typeof text != "object" && text != null ) 206 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); 207 208 var ret = ""; 209 210 jQuery.each( text || this, function(){ 159 211 jQuery.each( this.childNodes, function(){ 160 212 if ( this.nodeType != 8 ) 161 t += this.nodeType != 1 ? 162 this.nodeValue : jQuery.fn.text([ this ]); 213 ret += this.nodeType != 1 ? 214 this.nodeValue : 215 jQuery.fn.text( [ this ] ); 163 216 }); 164 217 }); 165 return t; 166 }, 167 168 wrapAll: function(html) { 218 219 return ret; 220 }, 221 222 wrapAll: function( html ) { 169 223 if ( this[0] ) 170 224 // The elements to wrap the target around 171 jQuery( html, this[0].ownerDocument)225 jQuery( html, this[0].ownerDocument ) 172 226 .clone() 173 .insertBefore( this[0])227 .insertBefore( this[0] ) 174 228 .map(function(){ 175 229 var elem = this; 230 176 231 while ( elem.firstChild ) 177 232 elem = elem.firstChild; 233 178 234 return elem; 179 235 }) … … 183 239 }, 184 240 185 wrapInner: function( html) {241 wrapInner: function( html ) { 186 242 return this.each(function(){ 187 jQuery( this).contents().wrapAll(html);243 jQuery( this ).contents().wrapAll( html ); 188 244 }); 189 245 }, 190 246 191 wrap: function( html) {247 wrap: function( html ) { 192 248 return this.each(function(){ 193 jQuery( this).wrapAll(html);249 jQuery( this ).wrapAll( html ); 194 250 }); 195 251 }, 196 252 197 253 append: function() { 198 return this.domManip(arguments, true, 1, function(a){199 this.appendChild( a);254 return this.domManip(arguments, true, false, function(elem){ 255 this.appendChild( elem ); 200 256 }); 201 257 }, 202 258 203 259 prepend: function() { 204 return this.domManip(arguments, true, -1, function(a){205 this.insertBefore( a, this.firstChild );260 return this.domManip(arguments, true, true, function(elem){ 261 this.insertBefore( elem, this.firstChild ); 206 262 }); 207 263 }, 208 264 209 265 before: function() { 210 return this.domManip(arguments, false, 1, function(a){211 this.parentNode.insertBefore( a, this );266 return this.domManip(arguments, false, false, function(elem){ 267 this.parentNode.insertBefore( elem, this ); 212 268 }); 213 269 }, 214 270 215 271 after: function() { 216 return this.domManip(arguments, false, -1, function(a){217 this.parentNode.insertBefore( a, this.nextSibling );272 return this.domManip(arguments, false, true, function(elem){ 273 this.parentNode.insertBefore( elem, this.nextSibling ); 218 274 }); 219 275 }, 220 276 221 277 end: function() { 222 return this.prevObject || jQuery([]); 223 }, 224 225 find: function(t) { 226 var data = jQuery.map(this, function(a){ return jQuery.find(t,a); }); 227 return this.pushStack( /[^+>] [^+>]/.test( t ) || t.indexOf("..") > -1 ? 228 jQuery.unique( data ) : data ); 229 }, 230 231 clone: function(events) { 278 return this.prevObject || jQuery( [] ); 279 }, 280 281 find: function( selector ) { 282 var elems = jQuery.map(this, function(elem){ 283 return jQuery.find( selector, elem ); 284 }); 285 286 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? 287 jQuery.unique( elems ) : 288 elems ); 289 }, 290 291 clone: function( events ) { 232 292 // Do the clone 233 293 var ret = this.map(function(){ 234 return this.outerHTML ? jQuery(this.outerHTML)[0] : this.cloneNode(true); 294 return this.outerHTML ? 295 jQuery( this.outerHTML )[0] : 296 this.cloneNode( true ); 235 297 }); 236 298 … … 244 306 245 307 // Copy the events from the original to the clone 246 if (events === true) 247 this.find("*").andSelf().each(function(i) { 248 var events = jQuery.data(this, "events"); 308 if ( events === true ) 309 this.find("*").andSelf().each(function(i){ 310 var events = jQuery.data( this, "events" ); 311 249 312 for ( var type in events ) 250 for ( var handler in events[ type] )251 jQuery.event.add( clone[i], type, events[type][handler], events[type][handler].data);313 for ( var handler in events[ type ] ) 314 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data ); 252 315 }); 253 316 … … 256 319 }, 257 320 258 filter: function( t) {321 filter: function( selector ) { 259 322 return this.pushStack( 260 jQuery.isFunction( t) &&261 jQuery.grep(this, function(el , index){262 return t.apply(el, [index]);323 jQuery.isFunction( selector ) && 324 jQuery.grep(this, function(elem, i){ 325 return selector.call( elem, i ); 263 326 }) || 264 327 265 jQuery.multiFilter( t,this) );266 }, 267 268 not: function( t) {328 jQuery.multiFilter( selector, this ) ); 329 }, 330 331 not: function( selector ) { 269 332 return this.pushStack( 270 t.constructor == String && 271 jQuery.multiFilter(t, this, true) || 272 273 jQuery.grep(this, function(a) { 274 return ( t.constructor == Array || t.jquery ) 275 ? jQuery.inArray( a, t ) < 0 276 : a != t; 277 }) 278 ); 279 }, 280 281 add: function(t) { 282 return this.pushStack( jQuery.merge( 333 selector.constructor == String && 334 jQuery.multiFilter( selector, this, true ) || 335 336 jQuery.grep(this, function(elem) { 337 return selector.constructor == Array || selector.jquery ? 338 jQuery.inArray( elem, selector ) < 0 : 339 elem != selector; 340 }) ); 341 }, 342 343 add: function( selector ) { 344 return !selector ? this : this.pushStack( jQuery.merge( 283 345 this.get(), 284 t.constructor == String ? 285 jQuery(t).get() : 286 t.length != undefined && (!t.nodeName || jQuery.nodeName(t, "form")) ? 287 t : [t] ) 288 ); 289 }, 290 291 is: function(expr) { 292 return expr ? jQuery.multiFilter(expr,this).length > 0 : false; 293 }, 294 295 hasClass: function(expr) { 296 return this.is("." + expr); 297 }, 298 299 val: function( val ) { 300 if ( val == undefined ) { 346 selector.constructor == String ? 347 jQuery( selector ).get() : 348 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ? 349 selector : [selector] ) ); 350 }, 351 352 is: function( selector ) { 353 return selector ? 354 jQuery.multiFilter( selector, this ).length > 0 : 355 false; 356 }, 357 358 hasClass: function( selector ) { 359 return this.is( "." + selector ); 360 }, 361 362 val: function( value ) { 363 if ( value == undefined ) { 364 301 365 if ( this.length ) { 302 366 var elem = this[0]; 303 367 304 368 // We need to handle select boxes special 305 if ( jQuery.nodeName( elem, "select") ) {369 if ( jQuery.nodeName( elem, "select" ) ) { 306 370 var index = elem.selectedIndex, 307 a= [],371 values = [], 308 372 options = elem.options, 309 373 one = elem.type == "select-one"; … … 315 379 // Loop through all the selected options 316 380 for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { 317 var option = options[i]; 381 var option = options[ i ]; 382 318 383 if ( option.selected ) { 319 384 // Get the specifc value for the option 320 va r val = jQuery.browser.msie && !option.attributes["value"].specified ? option.text : option.value;385 value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; 321 386 322 387 // We don't need an array for one selects 323 388 if ( one ) 324 return val ;389 return value; 325 390 326 391 // Multi-Selects return an array 327 a.push(val);392 values.push( value ); 328 393 } 329 394 } 330 395 331 return a;396 return values; 332 397 333 398 // Everything else, we just grab the value 334 399 } else 335 return this[0].value.replace(/\r/g, ""); 336 } 400 return (this[0].value || "").replace(/\r/g, ""); 401 402 } 403 337 404 } else 338 405 return this.each(function(){ 339 if ( val.constructor == Array && /radio|checkbox/.test(this.type) ) 340 this.checked = (jQuery.inArray(this.value, val) >= 0 || 341 jQuery.inArray(this.name, val) >= 0); 342 else if ( jQuery.nodeName(this, "select") ) { 343 var tmp = val.constructor == Array ? val : [val]; 344 345 jQuery("option", this).each(function(){ 346 this.selected = (jQuery.inArray(this.value, tmp) >= 0 || 347 jQuery.inArray(this.text, tmp) >= 0); 406 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) 407 this.checked = (jQuery.inArray(this.value, value) >= 0 || 408 jQuery.inArray(this.name, value) >= 0); 409 410 else if ( jQuery.nodeName( this, "select" ) ) { 411 var values = value.constructor == Array ? 412 value : 413 [ value ]; 414 415 jQuery( "option", this ).each(function(){ 416 this.selected = (jQuery.inArray( this.value, values ) >= 0 || 417 jQuery.inArray( this.text, values ) >= 0); 348 418 }); 349 419 350 if ( ! tmp.length )420 if ( !values.length ) 351 421 this.selectedIndex = -1; 422 352 423 } else 353 this.value = val ;424 this.value = value; 354 425 }); 355 426 }, 356 427 357 html: function( val ) { 358 return val == undefined ? 359 ( this.length ? this[0].innerHTML : null ) : 360 this.empty().append( val ); 361 }, 362 363 replaceWith: function( val ) { 364 return this.after( val ).remove(); 365 },
