git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
jquery core: closes #2811, $.fn.add now calls $.unique internally, also it was failin...
[jquery.git]
/
src
/
core.js
diff --git
a/src/core.js
b/src/core.js
index
6accbc4
..
a6d4c5f
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-36,9
+36,9
@@
jQuery.fn = jQuery.prototype = {
this[0] = selector;
this.length = 1;
return this;
this[0] = selector;
this.length = 1;
return this;
-
+ }
// Handle HTML strings
// 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 );
// Are we dealing with HTML string or an ID?
var match = quickExpr.exec( selector );
@@
-54,32
+54,27
@@
jQuery.fn = jQuery.prototype = {
var elem = document.getElementById( match[3] );
// Make sure an element was located
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
// 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
}
// 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 ) )
// 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));
},
return this.setArray(jQuery.makeArray(selector));
},
@@
-145,12
+140,10
@@
jQuery.fn = jQuery.prototype = {
var ret = -1;
// Locate the position of the desired element
var ret = -1;
// Locate the position of the desired element
- this.each(function(i){
- if ( this == elem )
- ret = i;
- });
-
- return ret;
+ return jQuery.inArray(
+ // If it receives a jQuery object, the first element is used
+ elem && elem.jquery ? elem[0] : elem
+ , this );
},
attr: function( name, value, type ) {
},
attr: function( name, value, type ) {
@@
-344,12
+337,12
@@
jQuery.fn = jQuery.prototype = {
},
add: function( selector ) {
},
add: function( selector ) {
- return !selector ? this : this.pushStack( jQuery.merge(
+ return this.pushStack( jQuery.unique( jQuery.merge(
this.get(),
this.get(),
- selector.constructor == String ?
- jQuery( selector ).get() :
- selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
- selector : [selector] ) );
+ typeof selector == 'string' ?
+ jQuery( selector ) :
+ jQuery.makeArray( selector )
+ )));
},
is: function( selector ) {
},
is: function( selector ) {
@@
-1114,14
+1107,14
@@
jQuery.extend({
makeArray: function( array ) {
var ret = [];
makeArray: function( array ) {
var ret = [];
- if( array != undefined ){
+ if( array != null ){
var i = array.length;
//the window, strings and functions also have 'length'
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];
while( i )
ret[--i] = array[i];
- else
- ret[0] = array;
}
return ret;
}
return ret;
@@
-1129,7
+1122,8
@@
jQuery.extend({
inArray: function( elem, array ) {
for ( var i = 0, length = array.length; i < length; i++ )
inArray: function( elem, array ) {
for ( var i = 0, length = array.length; i < length; i++ )
- if ( array[ i ] == elem )
+ // Use === because on IE, window == document
+ if ( array[ i ] === elem )
return i;
return -1;
return i;
return -1;
@@
-1138,16
+1132,16
@@
jQuery.extend({
merge: function( first, second ) {
// We have to loop this way because IE & Opera overwrite the length
// expando of getElementsByTagName
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 ) {
// 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
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;
first.push( second[ i ] );
return first;
@@
-1194,15
+1188,11
@@
jQuery.extend({
for ( var i = 0, length = elems.length; i < length; i++ ) {
var value = callback( elems[ i ], i );
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 );
}
});
}
});