this[0] = selector;
this.length = 1;
return this;
-
+ }
// Handle HTML strings
- } else if ( typeof selector == "string" ) {
+ if ( typeof selector == "string" ) {
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
var elem = document.getElementById( match[3] );
// Make sure an element was located
- if ( elem )
+ if ( elem ){
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id != match[3] )
return jQuery().find( selector );
// Otherwise, we inject the element directly into the jQuery object
- else {
- this[0] = elem;
- this.length = 1;
- return this;
- }
-
- else
- selector = [];
+ return jQuery( elem );
+ }
+ selector = [];
}
// HANDLE: $(expr, [context])
// (which is just equivalent to: $(content).find(expr)
} else
- return new jQuery( context ).find( selector );
+ return jQuery( context ).find( selector );
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) )
- return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
+ return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
return this.setArray(jQuery.makeArray(selector));
},
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
- if ( value == null ) {
+ if ( value === undefined ) {
var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
- if ( data == undefined && this.length )
+ if ( data === undefined && this.length )
data = jQuery.data( this[0], key );
- return data == null && parts[1] ?
+ return data === undefined && parts[1] ?
this.data( parts[0] ) :
data;
} else
target[ name ] = jQuery.extend( deep, src, copy );
// Don't bring in undefined values
- else if ( copy != undefined )
+ else if ( copy !== undefined )
target[ name ] = copy;
}
jQuery.cache[ id ] = {};
// Prevent overriding the named cache with undefined values
- if ( data != undefined )
+ if ( data !== undefined )
jQuery.cache[ id ][ name ] = data;
// Return the named cache data, or the ID for the element
// args is for internal usage only
each: function( object, callback, args ) {
+ var name, i = 0, length = object.length;
+
if ( args ) {
- if ( object.length == undefined ) {
- for ( var name in object )
+ if ( length == undefined ) {
+ for ( name in object )
if ( callback.apply( object[ name ], args ) === false )
break;
} else
- for ( var i = 0, length = object.length; i < length; i++ )
- if ( callback.apply( object[ i ], args ) === false )
+ for ( ; i < length; )
+ if ( callback.apply( object[ i++ ], args ) === false )
break;
// A special, fast, case for the most common use of each
} else {
- if ( object.length == undefined ) {
- for ( var name in object )
+ if ( length == undefined ) {
+ for ( name in object )
if ( callback.call( object[ name ], name, object[ name ] ) === false )
break;
} else
- for ( var i = 0, length = object.length, value = object[0];
+ for ( var value = object[0];
i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
}
},
curCSS: function( elem, name, force ) {
- var ret;
+ var ret, style = elem.style;
// A helper method for determining if an element's values are broken
function color( elem ) {
// We need to handle opacity special in IE
if ( name == "opacity" && jQuery.browser.msie ) {
- ret = jQuery.attr( elem.style, "opacity" );
+ ret = jQuery.attr( style, "opacity" );
return ret == "" ?
"1" :
}
// Opera sometimes will give the wrong display answer, this fixes it, see #2037
if ( jQuery.browser.opera && name == "display" ) {
- var save = elem.style.outline;
- elem.style.outline = "0 solid black";
- elem.style.outline = save;
+ var save = style.outline;
+ style.outline = "0 solid black";
+ style.outline = save;
}
// Make sure we're using the right name for getting the float value
if ( name.match( /float/i ) )
name = styleFloat;
- if ( !force && elem.style && elem.style[ name ] )
- ret = elem.style[ name ];
+ if ( !force && style && style[ name ] )
+ ret = style[ name ];
else if ( getComputedStyle ) {
// but a number that has a weird ending, we need to convert it to pixels
if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
// Remember the original values
- var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
+ var left = style.left, rsLeft = elem.runtimeStyle.left;
// Put in the new values to get a computed value out
elem.runtimeStyle.left = elem.currentStyle.left;
- elem.style.left = ret || 0;
- ret = elem.style.pixelLeft + "px";
+ style.left = ret || 0;
+ ret = style.pixelLeft + "px";
// Revert the changed values
- elem.style.left = style;
- elem.runtimeStyle.left = runtimeStyle;
+ style.left = left;
+ elem.runtimeStyle.left = rsLeft;
}
}
makeArray: function( array ) {
var ret = [];
- if( array != undefined ){
+ if( array != null ){
var i = array.length;
//the window, strings and functions also have 'length'
- if( i != null && !array.split && array != window && !array.call )
+ if( i == null || array.split || array.setInterval || array.call )
+ ret[0] = array;
+ else
while( i )
ret[--i] = array[i];
- else
- ret[0] = array;
}
return ret;
merge: function( first, second ) {
// We have to loop this way because IE & Opera overwrite the length
// expando of getElementsByTagName
-
+ var i = 0;
// Also, we need to make sure that the correct elements are being returned
// (IE returns comment nodes in a '*' query)
if ( jQuery.browser.msie ) {
- for ( var i = 0; second[ i ]; i++ )
+ for ( ; second[ i ]; i++ )
if ( second[ i ].nodeType != 8 )
first.push( second[ i ] );
} else
- for ( var i = 0; second[ i ]; i++ )
+ for ( ; second[ i ]; i++ )
first.push( second[ i ] );
return first;
for ( var i = 0, length = elems.length; i < length; i++ ) {
var value = callback( elems[ i ], i );
- if ( value !== null && value != undefined ) {
- if ( value.constructor != Array )
- value = [ value ];
-
- ret = ret.concat( value );
- }
+ if ( value != null )
+ ret[ ret.length ] = value;
}
- return ret;
+ return ret.concat.apply( [], ret );
}
});