jQuery: The Write Less, Do More JavaScript Library

Ticket #2743: potpourri.diff

File potpourri.diff, 22.5 kB (added by flesler, 3 months ago)
  • ajax.js

     
    2020            if ( jQuery.isFunction( params ) ) { 
    2121                // We assume that it's the callback 
    2222                callback = params; 
    23                 params = null; 
     23                params = undefined; 
    2424 
    2525            // Otherwise, build a param string 
    2626            } else { 
     
    7474        }) 
    7575        .map(function(i, elem){ 
    7676            var val = jQuery(this).val(); 
    77             return val == null ? null : 
     77            return val == undefined ? undefined : 
    7878                val.constructor == Array ? 
    7979                    jQuery.map( val, function(val, i){ 
    8080                        return {name: elem.name, value: val}; 
     
    9898        // shift arguments if data argument was ommited 
    9999        if ( jQuery.isFunction( data ) ) { 
    100100            callback = data; 
    101             data = null; 
     101            data = undefined; 
    102102        } 
    103103         
    104104        return jQuery.ajax({ 
     
    111111    }, 
    112112 
    113113    getScript: function( url, callback ) { 
    114         return jQuery.get(url, null, callback, "script"); 
     114        return jQuery.get(url, undefined, callback, "script"); 
    115115    }, 
    116116 
    117117    getJSON: function( url, data, callback ) { 
     
    144144        contentType: "application/x-www-form-urlencoded", 
    145145        processData: true, 
    146146        async: true, 
    147         data: null, 
    148         username: null, 
    149         password: null, 
     147        data: undefined, 
     148        username: undefined, 
     149        password: undefined, 
    150150        accepts: { 
    151151            xml: "application/xml, text/xml", 
    152152            html: "text/html", 
     
    207207            }; 
    208208        } 
    209209 
    210         if ( s.dataType == "script" && s.cache == null ) 
     210        if ( s.dataType == "script" && s.cache == undefined ) 
    211211            s.cache = false; 
    212212 
    213213        if ( s.cache === false && s.type.toLowerCase() == "get" ) { 
     
    223223            s.url += (s.url.match(/\?/) ? "&" : "?") + s.data; 
    224224 
    225225            // IE likes to send both get and post data, prevent this 
    226             s.data = null; 
     226            s.data = undefined; 
    227227        } 
    228228 
    229229        // Watch for a new set of requests 
     
    311311                // clear poll interval 
    312312                if (ival) { 
    313313                    clearInterval(ival); 
    314                     ival = null; 
     314                    ival = undefined; 
    315315                } 
    316316                 
    317317                status = isTimeout == "timeout" && "timeout" || 
     
    351351 
    352352                // Stop memory leaks 
    353353                if ( s.async ) 
    354                     xml = null; 
     354                    xml = undefined; 
    355355            } 
    356356        }; 
    357357         
     
    377377        try { 
    378378            xml.send(s.data); 
    379379        } catch(e) { 
    380             jQuery.handleError(s, xml, null, e); 
     380            jQuery.handleError(s, xml, undefined, e); 
    381381        } 
    382382         
    383383        // firefox 1.5 doesn't fire statechange for sync requests 
     
    448448    }, 
    449449 
    450450    httpData: function( r, type ) { 
    451         var ct = r.getResponseHeader("content-type"); 
    452         var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0; 
    453         var data = xml ? r.responseXML : r.responseText; 
     451        var ct = r.getResponseHeader("content-type"), 
     452           xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, 
     453           data = xml ? r.responseXML : r.responseText; 
    454454 
    455455        if ( xml && data.documentElement.tagName == "parsererror" ) 
    456456            throw "parsererror"; 
  • core.js

     
    1010 */ 
    1111 
    1212// Map over jQuery in case of overwrite 
    13 if ( window.jQuery ) 
    14     var _jQuery = window.jQuery; 
     13var _jQuery = this.jQuery, 
    1514 
    16 var jQuery = window.jQuery = function( selector, context ) { 
    17     // The jQuery object is actually just the init constructor 'enhanced' 
    18     return new jQuery.prototype.init( selector, context ); 
    19 }; 
    20  
    2115// Map over the $ in case of overwrite 
    22 if ( window.$ ) 
    23     var _$ = window.$; 
     16    _$ = this.$, 
    2417     
    25 // Map the jQuery namespace to the '$' one 
    26 window.$ = jQuery; 
     18//- when munging variables, every undefined turns into one-letter name. 
     19//- faster lookups: http://snurl.com/25pcd 
     20    undefined; 
    2721 
     22var jQuery = this.jQuery = this.$ = function( selector, context ) { 
     23    // The jQuery object is actually just the init constructor 'enhanced' 
     24    return new jQuery.fn.init( selector, context ); 
     25}; 
     26     
    2827// A simple way to check for HTML strings or ID strings 
    2928// (both of which we optimize for) 
    30 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/; 
     29var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/, 
    3130 
    3231// Is it a simple selector 
    33 var isSimple = /^.[^:#\[\.]*$/; 
     32   isSimple = /^.[^:#\[\.]*$/; 
    3433 
    3534jQuery.fn = jQuery.prototype = { 
    3635    init: function( selector, context ) { 
     
    148147    // Determine the position of an element within  
    149148    // the matched set of elements 
    150149    index: function( elem ) { 
    151         var ret = -1; 
    152  
    153         // Locate the position of the desired element 
    154         this.each(function(i){ 
    155             if ( this == elem ) 
    156                 ret = i; 
    157         }); 
    158  
    159         return ret; 
     150        return jQuery.inArray( elem, this ); 
    160151    }, 
    161152 
    162153    attr: function( name, value, type ) { 
     
    193184    }, 
    194185 
    195186    text: function( text ) { 
    196         if ( typeof text != "object" && text != null ) 
     187        if ( typeof text != "object" && text != undefined ) 
    197188            return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); 
    198189 
    199190        var ret = ""; 
     
    306297        // this is primarily for IE but the data expando shouldn't be copied over in any browser 
    307298        var clone = ret.find("*").andSelf().each(function(){ 
    308299            if ( this[ expando ] != undefined ) 
    309                 this[ expando ] = null; 
     300                this[ expando ] = undefined; 
    310301        }); 
    311302         
    312303        // Copy the events from the original to the clone 
     
    359350    }, 
    360351 
    361352    is: function( selector ) { 
    362         return selector ? 
    363             jQuery.multiFilter( selector, this ).length > 0 : 
    364             false; 
     353        return !!selector && jQuery.multiFilter( selector, this ).length > 0 ; 
    365354    }, 
    366355 
    367356    hasClass: function( selector ) { 
     
    383372                     
    384373                    // Nothing was selected 
    385374                    if ( index < 0 ) 
    386                         return null; 
     375                        return undefined; 
    387376 
    388377                    // Loop through all the selected options 
    389378                    for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { 
     
    410399 
    411400            } 
    412401 
    413             return undefined; 
     402            return; 
    414403        } 
    415404 
    416405        return this.each(function(){ 
     
    443432        return value == undefined ? 
    444433            (this.length ? 
    445434                this[0].innerHTML : 
    446                 null) : 
     435                undefined) : 
    447436            this.empty().append( value ); 
    448437    }, 
    449438 
     
    473462        var parts = key.split("."); 
    474463        parts[1] = parts[1] ? "." + parts[1] : ""; 
    475464 
    476         if ( value == null ) { 
     465        if ( value == undefined ) { 
    477466            var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); 
    478467             
    479468            if ( data == undefined && this.length ) 
    480469                data = jQuery.data( this[0], key ); 
    481470 
    482             return data == null && parts[1] ? 
     471            return data == undefined && parts[1] ? 
    483472                this.data( parts[0] ) : 
    484473                data; 
    485474        } else 
     
    536525}; 
    537526 
    538527// Give the init function the jQuery prototype for later instantiation 
    539 jQuery.prototype.init.prototype = jQuery.prototype; 
     528jQuery.fn.init.prototype = jQuery.fn; 
    540529 
    541530function evalScript( i, elem ) { 
    542531    if ( elem.src ) 
     
    570559        target = {}; 
    571560 
    572561    // extend jQuery itself if only one argument is passed 
    573     if ( length == 1 ) { 
     562    if ( length - i == 0 ) { 
    574563        target = this; 
    575564        i = 0; 
    576565    } 
    577566 
    578567    for ( ; i < length; i++ ) 
    579568        // Only deal with non-null/undefined values 
    580         if ( (options = arguments[ i ]) != null ) 
     569        if ( (options = arguments[ i ]) != undefined ) 
    581570            // Extend the base object 
    582             for ( var name in options ) { 
     571            for ( var name in options ) {                
     572                var src = target[name], copy = options[name]; 
     573 
    583574                // Prevent never-ending loop 
    584                 if ( target === options[ name ] ) 
     575                if ( target === copy ) 
    585576                    continue; 
    586577 
    587578                // Recurse if we're merging object values 
    588                 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType ) 
    589                     target[ name ] = jQuery.extend( deep, target[ name ], options[ name ] ); 
     579                if ( deep && copy && typeof copy == "object" && src && !copy.nodeType ) 
     580                    target[ name ] = jQuery.extend( deep, src, copy ); 
    590581 
    591582                // Don't bring in undefined values 
    592                 else if ( options[ name ] != undefined ) 
    593                     target[ name ] = options[ name ]; 
     583                else if ( copy != undefined ) 
     584                    target[ name ] = copy; 
    594585 
    595586            } 
    596587 
     
    598589    return target; 
    599590}; 
    600591 
    601 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {}; 
     592var expando = "jQuery" + (+new Date), uuid = 0, windowData = {}, 
    602593 
    603594// exclude the following css properties to add px 
    604 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i; 
     595    exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, 
    605596// cache getComputedStyle 
    606 var getComputedStyle = document.defaultView && document.defaultView.getComputedStyle; 
     597   getComputedStyle = document.defaultView && document.defaultView.getComputedStyle; 
    607598 
    608599jQuery.extend({ 
    609600    noConflict: function( deep ) { 
     
    800791 
    801792    css: function( elem, name, force ) { 
    802793        if ( name == "width" || name == "height" ) { 
    803             var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 
     794            var val, props = { position: "absolute", visibility: "hidden", display:"block" }, 
     795                which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; 
    804796         
    805797            function getWH() { 
    806798                val = name == "width" ? elem.offsetWidth : elem.offsetHeight; 
     
    874866            // If the element isn't reporting its values properly in Safari 
    875867            // then some display: none elements are involved 
    876868            else { 
    877                 var swap = [], stack = []; 
     869                var swap = [], stack = [], a, i; 
    878870 
    879871                // Locate all of the parent display: none elements 
    880                 for ( var a = elem; a && color(a); a = a.parentNode ) 
     872                for ( a = elem; a && color(a); a = a.parentNode ) 
    881873                    stack.unshift(a); 
    882874 
    883875                // Go through and make them visible, but in reverse 
    884876                // (It would be better if we knew the exact display type that they had) 
    885                 for ( var i = 0; i < stack.length; i++ ) 
     877                for ( i = 0; i < stack.length; i++ ) 
    886878                    if ( color( stack[ i ] ) ) { 
    887879                        swap[ i ] = stack[ i ].style.display; 
    888880                        stack[ i ].style.display = "block"; 
     
    890882 
    891883                // Since we flip the display style, we have to handle that 
    892884                // one special, otherwise get the value 
    893                 ret = name == "display" && swap[ stack.length - 1 ] != null ? 
     885                ret = name == "display" && swap[ stack.length - 1 ] != undefined ? 
    894886                    "none" : 
    895887                    ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; 
    896888 
    897889                // Finally, revert the display styles back 
    898                 for ( var i = 0; i < swap.length; i++ ) 
    899                     if ( swap[ i ] != null ) 
     890                for ( i = 0; i < swap.length; i++ ) 
     891                    if ( swap[ i ] != undefined ) 
    900892                        stack[ i ].style.display = swap[ i ]; 
    901893            } 
    902894 
     
    946938                return; 
    947939 
    948940            if ( elem.constructor == Number ) 
    949                 elem = elem.toString(); 
     941                elem += ''; 
    950942             
    951943            // Convert html string into DOM nodes 
    952944            if ( typeof elem == "string" ) { 
     
    958950                }); 
    959951 
    960952                // Trim whitespace, otherwise indexOf won't work as expected 
    961                 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); 
     953                var tags = jQuery.trim( elem ).toLowerCase(), 
     954                    div = context.createElement("div"); 
    962955 
    963956                var wrap = 
    964957                    // option or optgroup 
     
    13531346                // Get or set width or height on the element 
    13541347                size == undefined ? 
    13551348                    // Get width or height on the element 
    1356                     (this.length ? jQuery.css( this[0], type ) : null) : 
     1349                    (this.length ? jQuery.css( this[0], type ) : undefined) : 
    13571350 
    13581351                    // Set the width or height on the element (default to pixels if value is unitless) 
    13591352                    this.css( type, size.constructor == String ? size : size + "px" ); 
  • event.js

     
    1313 
    1414        // For whatever reason, IE has trouble passing the window object 
    1515        // around, causing it to be cloned in the process 
    16         if ( jQuery.browser.msie && elem.setInterval != undefined ) 
     16        if ( jQuery.browser.msie && elem.setInterval ) 
    1717            elem = window; 
    1818 
    1919        // Make sure that the function being executed has a unique ID 
     
    5151        // event in IE. 
    5252        handle.elem = elem; 
    5353             
    54            // Handle multiple events seperated by a space 
    55            // jQuery(...).bind("mouseover mouseout", fn); 
    56            jQuery.each(types.split(/\s+/), function(index, type) { 
    57                // Namespaced event handlers 
    58                var parts = type.split("."); 
    59                type = parts[0]; 
    60                handler.type = parts[1]; 
     54        // Handle multiple events separated by a space 
     55        // jQuery(...).bind("mouseover mouseout", fn); 
     56        jQuery.each(types.split(/\s+/), function(index, type) { 
     57            // Namespaced event handlers 
     58            var parts = type.split("."); 
     59            type = parts[0]; 
     60            handler.type = parts[1]; 
    6161 
    62                // Get the current list of functions bound to this event 
    63                var handlers = events[type]; 
     62            // Get the current list of functions bound to this event 
     63            var handlers = events[type]; 
    6464 
    65                 // Init the event handler queue 
    66                 if (!handlers) { 
    67                     handlers = events[type] = {}; 
    68          
    69                     // Check for a special event handler 
    70                     // Only use addEventListener/attachEvent if the special 
    71                     // events handler returns false 
    72                     if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) { 
    73                         // Bind the global event handler to the element 
    74                         if (elem.addEventListener) 
    75                             elem.addEventListener(type, handle, false); 
    76                         else if (elem.attachEvent) 
    77                             elem.attachEvent("on" + type, handle); 
    78                     } 
     65            // Init the event handler queue 
     66            if (!handlers) { 
     67                handlers = events[type] = {}; 
     68     
     69                // Check for a special event handler 
     70                // Only use addEventListener/attachEvent if the special 
     71                // events handler returns false 
     72                if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) { 
     73                    // Bind the global event handler to the element 
     74                    if (elem.addEventListener) 
     75                        elem.addEventListener(type, handle, false); 
     76                    else if (elem.attachEvent) 
     77                        elem.attachEvent("on" + type, handle); 
    7978                } 
     79            } 
    8080 
    81                // Add the function to the element's handler list 
    82                handlers[handler.guid] = handler; 
     81            // Add the function to the element's handler list 
     82            handlers[handler.guid] = handler; 
    8383 
    84                // Keep track of which events have been used, for global triggering 
    85                jQuery.event.global[type] = true; 
    86            }); 
     84            // Keep track of which events have been used, for global triggering 
     85            jQuery.event.global[type] = true; 
     86        }); 
    8787         
    8888        // Nullify elem to prevent memory leaks in IE 
    89         elem = null; 
     89        elem = undefined; 
    9090    }, 
    9191 
    9292    guid: 1, 
     
    140140                                else if (elem.detachEvent) 
    141141                                    elem.detachEvent("on" + type, jQuery.data(elem, "handle")); 
    142142                            } 
    143                             ret = null; 
     143                            ret = undefined; 
    144144                            delete events[type]; 
    145145                        } 
    146146                    } 
     
    151151            for ( ret in events ) break; 
    152152            if ( !ret ) { 
    153153                var handle = jQuery.data( elem, "handle" ); 
    154                 if ( handle ) handle.elem = null; 
     154                if ( handle ) handle.elem = undefined; 
    155155                jQuery.removeData( elem, "events" ); 
    156156                jQuery.removeData( elem, "handle" ); 
    157157            } 
     
    179179            if ( elem.nodeType == 3 || elem.nodeType == 8 ) 
    180180                return undefined; 
    181181 
    182             var val, ret, fn = jQuery.isFunction( elem[ type ] || null ), 
     182            var val, ret, fn = jQuery.isFunction( elem[ type ] || undefined ), 
    183183                // Check to see if we need to provide a fake event, or not 
    184184                event = !data[0] || !data[0].preventDefault; 
    185185             
     
    208208            // Handle triggering of extra function 
    209209            if ( extra && jQuery.isFunction( extra ) ) { 
    210210                // call the extra function and tack the current return value on the end for possible inspection 
    211                 ret = extra.apply( elem, val == null ? data : data.concat( val ) ); 
     211                ret = extra.apply( elem, val == undefined ? data : data.concat( val ) ); 
    212212                // if anything is returned, give it precedence and have it overwrite the previous value 
    213213                if (ret !== undefined) 
    214214                    val = ret; 
     
    268268        // Clean up added properties in IE to prevent memory leak 
    269269        if (jQuery.browser.msie) 
    270270            event.target = event.preventDefault = event.stopPropagation = 
    271                 event.handler = event.data = null; 
     271                event.handler = event.data = undefined; 
    272272 
    273273        return val; 
    274274    }, 
     
    297297        }; 
    298298         
    299299        // Fix timeStamp 
    300         event.timeStamp = event.timeStamp || +new Date; 
     300        event.timeStamp = event.timeStamp || now(); 
    301301         
    302302        // Fix target property, if necessary 
    303303        if ( !event.target ) 
     
    312312            event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement; 
    313313 
    314314        // Calculate pageX/Y if missing and clientX/Y available 
    315         if ( event.pageX == null && event.clientX != null ) { 
     315        if ( event.pageX == undefined && event.clientX != undefined ) { 
    316316            var doc = document.documentElement, body = document.body; 
    317317            event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0); 
    318318            event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0); 
     
    362362                // If we actually just moused on to a sub-element, ignore it 
    363363                if ( withinElement(event, this) ) return true; 
    364364                // Execute the right handlers by setting the event type to mouseenter 
    365                 arguments[0].type = "mouseenter"; 
     365                event.type = "mouseenter"; 
    366366                return jQuery.event.handle.apply(this, arguments); 
    367367            } 
    368368        }, 
     
    384384                // If we actually just moused on to a sub-element, ignore it 
    385385                if ( withinElement(event, this) ) return true; 
    386386                // Execute the right handlers by setting the event type to mouseleave 
    387                 arguments[0].type = "mouseleave"; 
     387                event.type = "mouseleave"; 
    388388                return jQuery.event.handle.apply(this, arguments); 
    389389            } 
    390390        } 
     
    420420    }, 
    421421 
    422422    triggerHandler: function( type, data, fn ) { 
    423         if ( this[0] ) 
    424             return jQuery.event.trigger( type, data, this[0], false, fn ); 
    425         return undefined; 
     423        return this[0] && jQuery.event.trigger( type, data, this[0], false, fn ); 
    426424    }, 
    427425 
    428426    toggle: function() { 
     
    481479                }); 
    482480                 
    483481                // Reset the list of functions 
    484                 jQuery.readyList = null; 
     482                jQuery.readyList = undefined; 
    485483            } 
    486484         
    487485            // Trigger any bound ready events 
  • fx.js

     
    7676            if ( this.nodeType != 1) 
    7777                return false; 
    7878 
    79             var opt = jQuery.extend({}, optall); 
    80             var hidden = jQuery(this).is(":hidden"), self = this; 
     79            var opt = jQuery.extend({}, optall), 
     80                hidden = jQuery(this).is(":hidden"), 
     81                self = this; 
    8182             
    8283            for ( var p in prop ) { 
    8384                if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) 
     
    9293                } 
    9394            } 
    9495 
    95             if ( opt.overflow != null ) 
     96            if ( opt.overflow != undefined ) 
    9697                this.style.overflow = "hidden"; 
    9798 
    9899            opt.curAnim = jQuery.extend({}, prop); 
     
    180181}); 
    181182 
    182183var queue = function( elem, type, array ) { 
    183     if ( !elem ) 
    184         return undefined; 
    185  
    186     type = type || "fx"; 
    187  
    188     var q = jQuery.data( elem, type + "queue" ); 
    189  
    190     if ( !q || array ) 
    191         q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) ); 
    192  
     184    if ( elem ){ 
     185&nbs