From: jaubourg Date: Thu, 20 Jan 2011 16:52:10 +0000 (+0100) Subject: Merge branch 'master' of github.com:jquery/jquery X-Git-Url: http://git.asbjorn.it/?p=jquery.git;a=commitdiff_plain;h=f2b0c77dc84d3019db96de0c060207a5063f2055;hp=-c Merge branch 'master' of github.com:jquery/jquery --- f2b0c77dc84d3019db96de0c060207a5063f2055 diff --combined src/core.js index 69f4f5a,f35e33c..eb31b2a --- a/src/core.js +++ b/src/core.js @@@ -15,9 -15,8 +15,8 @@@ var jQuery = function( selector, contex // A central reference to the root jQuery(document) rootjQuery, - // A simple way to check for HTML strings or ID strings - // (both of which we optimize for) - quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/, + // A simple way to check for HTML strings + quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$/, // Check if a string has a non-whitespace character in it rnotwhite = /\S/, @@@ -93,76 -92,31 +92,31 @@@ jQuery.fn = jQuery.prototype = return this; } - // The body element only exists once, optimize finding it - if ( selector === "body" && !context && document.body ) { - this.context = document; - this[0] = document.body; - this.selector = "body"; - this.length = 1; - return this; - } - // Handle HTML strings if ( typeof selector === "string" ) { - // Are we dealing with HTML string or an ID? - match = quickExpr.exec( selector ); - - // Verify a match, and that no context was specified for #id - if ( match && (match[1] || !context) ) { + // Are we dealing with HTML string + if ( (match = quickExpr.exec( selector )) ) { + context = context instanceof jQuery ? context[0] : context; + doc = (context ? context.ownerDocument || context : document); - // HANDLE: $(html) -> $(array) - if ( match[1] ) { - context = context instanceof jQuery ? context[0] : context; - doc = (context ? context.ownerDocument || context : document); + // If a single string is passed in and it's a single tag + // just do a createElement and skip the rest + ret = rsingleTag.exec( selector ); - // If a single string is passed in and it's a single tag - // just do a createElement and skip the rest - ret = rsingleTag.exec( selector ); - - if ( ret ) { - if ( jQuery.isPlainObject( context ) ) { - selector = [ document.createElement( ret[1] ) ]; - jQuery.fn.attr.call( selector, context, true ); - - } else { - selector = [ doc.createElement( ret[1] ) ]; - } + if ( ret ) { + if ( jQuery.isPlainObject( context ) ) { + selector = [ document.createElement( ret[1] ) ]; + jQuery.fn.attr.call( selector, context, true ); } else { - ret = jQuery.buildFragment( [ match[1] ], [ doc ] ); - selector = (ret.cacheable ? jQuery(ret.fragment).clone()[0] : ret.fragment).childNodes; + selector = [ doc.createElement( ret[1] ) ]; } - return jQuery.merge( this, selector ); - - // HANDLE: $("#id") } else { - elem = document.getElementById( match[2] ); - - // Check parentNode to catch when Blackberry 4.6 returns - // nodes that are no longer in the document #6963 - if ( elem && elem.parentNode ) { - // Handle the case where IE and Opera return items - // by name instead of ID - if ( elem.id !== match[2] ) { - return rootjQuery.find( selector ); - } - - // Otherwise, we inject the element directly into the jQuery object - this.length = 1; - this[0] = elem; - } - - this.context = document; - this.selector = selector; - return this; + ret = jQuery.buildFragment( [ match[1] ], [ doc ] ); + selector = (ret.cacheable ? jQuery(ret.fragment).clone()[0] : ret.fragment).childNodes; } - // HANDLE: $("TAG") - } else if ( !context && !rnonword.test( selector ) ) { - this.selector = selector; - this.context = document; - selector = document.getElementsByTagName( selector ); return jQuery.merge( this, selector ); // HANDLE: $(expr, $(...)) @@@ -406,7 -360,7 +360,7 @@@ jQuery.extend( } // If there are functions bound, to execute - readyList.fire( document , [ jQuery ] ); + readyList.resolveWith( document , [ jQuery ] ); // Trigger any bound ready events if ( jQuery.fn.trigger ) { @@@ -844,7 -798,7 +798,7 @@@ } if ( _fired ) { - deferred.fire( _fired[ 0 ] , _fired[ 1 ] ); + deferred.resolveWith( _fired[ 0 ] , _fired[ 1 ] ); } } @@@ -852,7 -806,7 +806,7 @@@ }, // resolve with given context and args - fire: function( context , args ) { + resolveWith: function( context , args ) { if ( ! cancelled && ! fired && ! firing ) { firing = 1; @@@ -872,7 -826,7 +826,7 @@@ // resolve with this as context and given arguments resolve: function() { - deferred.fire( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments ); + deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments ); return this; }, @@@ -908,7 -862,7 +862,7 @@@ return this; }, fail: failDeferred.done, - fireReject: failDeferred.fire, + rejectWith: failDeferred.resolveWith, reject: failDeferred.resolve, isRejected: failDeferred.isResolved, // Get a promise for this deferred @@@ -961,10 -915,10 +915,10 @@@ args = arguments; resolveArray[ index ] = args.length > 1 ? slice.call( args , 0 ) : value; if( ! --length ) { - deferred.fire( promise, resolveArray ); + deferred.resolveWith( promise, resolveArray ); } }).fail( function() { - deferred.fireReject( promise, arguments ); + deferred.rejectWith( promise, arguments ); }); return !deferred.isRejected(); });