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 fx & event: replaced the use of .apply(), where .call() could had been used.
[jquery.git]
/
src
/
core.js
diff --git
a/src/core.js
b/src/core.js
index
6accbc4
..
a86ef8d
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-24,7
+24,10
@@
var jQuery = window.jQuery = window.$ = function( selector, context ) {
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,
// Is it a simple selector
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,
// Is it a simple selector
- isSimple = /^.[^:#\[\.]*$/;
+ isSimple = /^.[^:#\[\.]*$/,
+
+// Will speed up references to undefined, and allows munging its name.
+ undefined;
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
@@
-36,9
+39,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
+57,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
+143,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
+340,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
+1110,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
+1125,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
+1135,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;
@@
-1180,7
+1177,7
@@
jQuery.extend({
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ )
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ )
- if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
+ if ( !inv != !callback( elems[ i ], i ) )
ret.push( elems[ i ] );
return ret;
ret.push( elems[ i ] );
return ret;
@@
-1194,15
+1191,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 );
}
});
}
});