Bug Tracker

Changeset 4040

Show
Ignore:
Timestamp:
12/06/07 15:36:17 (9 months ago)
Author:
joern.zaefferer
Message:

* Added valid() plugin method for easy programmatic checking of forms and fields without the need to use the validator API
* Replaced regex for URL method, thanks to the contribution by Scott Gonzales, see http://www.scottsplayground.com/temp/iri/common.htm
* 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)

Location:
trunk/plugins/validate
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/validate/changelog.txt

    r3948 r4040  
    99* Added support for ajax-validation, see method "remote" 
    1010* 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 
    1113* Fixed error container to hide when all elements are valid, not only on form submit 
    1214* 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 
    1416* 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) 
    1619 
    17201.1.1 
  • trunk/plugins/validate/demo-test/js/jquery.js

    r3864 r4040  
    11(function(){ 
    22/* 
    3  * jQuery 1.2.1 - New Wave Javascript 
     3 * jQuery 1.2.2-pre - New Wave Javascript 
    44 * 
    55 * Copyright (c) 2007 John Resig (jquery.com) 
     
    77 * and GPL (GPL-LICENSE.txt) licenses. 
    88 * 
    9  * $Date: 2007-09-16 23:42:06 -0400 (Sun, 16 Sep 2007) $ 
    10  * $Rev: 3353 $ 
     9 * $Date: 2007-12-05 06:01:46 +0100 (Mit, 05 Dez 2007) $ 
     10 * $Rev: 4031 $ 
    1111 */ 
    1212 
    1313// 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) { 
     14if ( window.jQuery ) 
     15    var _jQuery = window.jQuery; 
     16 
     17var jQuery = window.jQuery = function( selector, context ) { 
    1818    // If the context is a namespace object, return a new object 
    1919    return this instanceof jQuery ? 
    20         this.init(selector, context) : 
    21         new jQuery(selector, context); 
     20        this.init( selector, context ) : 
     21        new jQuery( selector, context ); 
    2222}; 
    2323 
    2424// Map over the $ in case of overwrite 
    25 if ( typeof $ != "undefined" ) 
    26     var _$ = $; 
     25if ( window.$ ) 
     26    var _$ = window.$; 
    2727     
    2828// Map the jQuery namespace to the '$' one 
    2929window.$ = jQuery; 
    3030 
     31// A simple way to check for HTML strings or ID strings 
     32// (both of which we optimize for) 
    3133var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; 
    3234 
    3335jQuery.fn = jQuery.prototype = { 
    34     init: function(selector, context) { 
     36    init: function( selector, context ) { 
    3537        // Make sure that a selection was provided 
    3638        selector = selector || document; 
    3739 
     40        // Handle $(DOMElement) 
     41        if ( selector.nodeType ) { 
     42            this[0] = selector; 
     43            this.length = 1; 
     44            return this; 
     45 
    3846        // 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 
    4254                // 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 ); 
    4557 
    4658                // HANDLE: $("#id") 
    4759                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 ) 
    5064                        // Handle the case where IE and Opera return items 
    5165                        // by name instead of ID 
    52                         if ( tmp.id != m[3] ) 
     66                        if ( elem.id != match[3] ) 
    5367                            return jQuery().find( selector ); 
     68 
     69                        // Otherwise, we inject the element directly into the jQuery object 
    5470                        else { 
    55                             this[0] = tmp; 
     71                            this[0] = elem; 
    5672                            this.length = 1; 
    5773                            return this; 
    5874                        } 
     75 
    5976                    else 
    6077                        selector = []; 
    6178                } 
    6279 
    63             // HANDLE: $(expr) 
     80            // HANDLE: $(expr, [context]) 
     81            // (which is just equivalent to: $(content).find(expr) 
    6482            } else 
    6583                return new jQuery( context ).find( selector ); 
     
    6785        // HANDLE: $(function) 
    6886        // 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 ); 
    7189 
    7290        return this.setArray( 
     
    7593 
    7694            // HANDLE: $(arraylike) 
    77             // Watch for when an array-like object is passed as the selector 
     95            // Watch for when an array-like object, contains DOM nodes, is passed in as the selector 
    7896            (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || 
    7997 
     
    82100    }, 
    83101     
    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 
    86106    size: function() { 
    87107        return this.length; 
    88108    }, 
    89109     
     110    // The number of elements contained in the matched element set 
    90111    length: 0, 
    91112 
     113    // Get the Nth element in the matched element set OR 
     114    // Get the whole matched element set as a clean array 
    92115    get: function( num ) { 
    93116        return num == undefined ? 
     
    97120 
    98121            // 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) 
    104132        ret.prevObject = this; 
     133 
     134        // Return the newly-formed element set 
    105135        return ret; 
    106136    }, 
    107137     
    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 
    109144        this.length = 0; 
    110         Array.prototype.push.apply( this, a ); 
     145        Array.prototype.push.apply( this, elems ); 
     146         
    111147        return this; 
    112148    }, 
    113149 
    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 
    120163        this.each(function(i){ 
    121             if ( this == obj ) pos = i; 
     164            if ( this == elem ) 
     165                ret = i; 
    122166        }); 
    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; 
    128173         
    129174        // Look for the case where we're accessing a style value 
    130         if ( key.constructor == String ) 
     175        if ( name.constructor == String ) 
    131176            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 
    133179            else { 
    134                 obj = {}; 
    135                 obj[ key ] = value; 
     180                options = {}; 
     181                options[ name ] = value; 
    136182            } 
    137183         
    138184        // Check to see if we're setting style values 
    139         return this.each(function(index){ 
     185        return this.each(function(i){ 
    140186            // Set all the styles 
    141             for ( var prop in obj ) 
     187            for ( name in options ) 
    142188                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 ) 
    145193                ); 
    146194        }); 
     
    148196 
    149197    css: function( key, value ) { 
     198        // ignore negative width and height values 
     199        if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) 
     200            value = undefined; 
    150201        return this.attr( key, value, "curCSS" ); 
    151202    }, 
    152203 
    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(){ 
    159211            jQuery.each( this.childNodes, function(){ 
    160212                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 ] ); 
    163216            }); 
    164217        }); 
    165         return t; 
    166     }, 
    167  
    168     wrapAll: function(html) { 
     218 
     219        return ret; 
     220    }, 
     221 
     222    wrapAll: function( html ) { 
    169223        if ( this[0] ) 
    170224            // The elements to wrap the target around 
    171             jQuery(html, this[0].ownerDocument) 
     225            jQuery( html, this[0].ownerDocument ) 
    172226                .clone() 
    173                 .insertBefore(this[0]) 
     227                .insertBefore( this[0] ) 
    174228                .map(function(){ 
    175229                    var elem = this; 
     230 
    176231                    while ( elem.firstChild ) 
    177232                        elem = elem.firstChild; 
     233 
    178234                    return elem; 
    179235                }) 
     
    183239    }, 
    184240 
    185     wrapInner: function(html) { 
     241    wrapInner: function( html ) { 
    186242        return this.each(function(){ 
    187             jQuery(this).contents().wrapAll(html); 
     243            jQuery( this ).contents().wrapAll( html ); 
    188244        }); 
    189245    }, 
    190246 
    191     wrap: function(html) { 
     247    wrap: function( html ) { 
    192248        return this.each(function(){ 
    193             jQuery(this).wrapAll(html); 
     249            jQuery( this ).wrapAll( html ); 
    194250        }); 
    195251    }, 
    196252 
    197253    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 ); 
    200256        }); 
    201257    }, 
    202258 
    203259    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 ); 
    206262        }); 
    207263    }, 
    208264     
    209265    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 ); 
    212268        }); 
    213269    }, 
    214270 
    215271    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 ); 
    218274        }); 
    219275    }, 
    220276 
    221277    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 ) { 
    232292        // Do the clone 
    233293        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 ); 
    235297        }); 
    236298 
     
    244306         
    245307        // 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 
    249312                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 ); 
    252315            }); 
    253316 
     
    256319    }, 
    257320 
    258     filter: function(t) { 
     321    filter: function( selector ) { 
    259322        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 ); 
    263326            }) || 
    264327 
    265             jQuery.multiFilter(t,this) ); 
    266     }, 
    267  
    268     not: function(t) { 
     328            jQuery.multiFilter( selector, this ) ); 
     329    }, 
     330 
     331    not: function( selector ) { 
    269332        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(  
    283345            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 
    301365            if ( this.length ) { 
    302366                var elem = this[0]; 
    303                  
     367 
    304368                // We need to handle select boxes special 
    305                 if ( jQuery.nodeName(elem, "select") ) { 
     369                if ( jQuery.nodeName( elem, "select" ) ) { 
    306370                    var index = elem.selectedIndex, 
    307                         a = [], 
     371                        values = [], 
    308372                        options = elem.options, 
    309373                        one = elem.type == "select-one"; 
     
    315379                    // Loop through all the selected options 
    316380                    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 
    318383                        if ( option.selected ) { 
    319384                            // Get the specifc value for the option 
    320                             var 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; 
    321386                             
    322387                            // We don't need an array for one selects 
    323388                            if ( one ) 
    324                                 return val; 
     389                                return value; 
    325390                             
    326391                            // Multi-Selects return an array 
    327                             a.push(val); 
     392                            values.push( value ); 
    328393                        } 
    329394                    } 
    330395                     
    331                     return a; 
     396                    return values; 
    332397                     
    333398                // Everything else, we just grab the value 
    334399                } else 
    335                     return this[0].value.replace(/\r/g, ""); 
    336             } 
     400                    return (this[0].value || "").replace(/\r/g, ""); 
     401 
     402            } 
     403 
    337404        } else 
    338405            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); 
    348418                    }); 
    349419 
    350                     if ( !tmp.length ) 
     420                    if ( !values.length ) 
    351421                        this.selectedIndex = -1; 
     422 
    352423                } else 
    353                     this.value = val; 
     424                    this.value = value; 
    354425            }); 
    355426    }, 
    356427     
    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     },