Fixed boxModel support - is now computed with feature detection, rather than sniffing.
[jquery.git] / src / core.js
index ad94ce1..78f2bcd 100644 (file)
@@ -73,6 +73,12 @@ jQuery.fn = jQuery.prototype = {
                } else if ( jQuery.isFunction( selector ) )
                        return jQuery( document ).ready( selector );
 
+               // Make sure that old selector state is passed along
+               if ( selector.selector && selector.context ) {
+                       this.selector = selector.selector;
+                       this.context = selector.context;
+               }
+
                return this.setArray(jQuery.makeArray(selector));
        },
 
@@ -260,14 +266,23 @@ jQuery.fn = jQuery.prototype = {
                return this.prevObject || jQuery( [] );
        },
 
+       push: [].push,
+
        find: function( selector ) {
-               var elems = jQuery.map(this, function(elem){
-                       return jQuery.find( selector, elem );
-               });
+               if ( this.length === 1 && !/,/.test(selector) ) {
+                       var ret = this.pushStack( [], "find", selector );
+                       ret.length = 0;
+                       jQuery.find( selector, this[0], ret );
+                       return ret;
+               } else {
+                       var elems = jQuery.map(this, function(elem){
+                               return jQuery.find( selector, elem );
+                       });
 
-               return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
-                       jQuery.unique( elems ) :
-                       elems, "find", selector );
+                       return this.pushStack( /[^+>] [^+>]/.test( selector ) ?
+                               jQuery.unique( elems ) :
+                               elems, "find", selector );
+               }
        },
 
        clone: function( events ) {
@@ -327,10 +342,12 @@ jQuery.fn = jQuery.prototype = {
        },
 
        closest: function( selector ) {
+               var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null;
+
                return this.map(function(){
                        var cur = this;
                        while ( cur && cur.ownerDocument ) {
-                               if ( jQuery(cur).is(selector) )
+                               if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) )
                                        return cur;
                                cur = cur.parentNode;
                        }
@@ -907,7 +924,7 @@ jQuery.extend({
                if ( fragment ) {
                        for ( var i = 0; ret[i]; i++ ) {
                                if ( jQuery.nodeName( ret[i], "script" ) ) {
-                                       scripts.push( ret[i].parentNode.removeChild( ret[i] ) );
+                                       scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
                                } else {
                                        if ( ret[i].nodeType === 1 )
                                                ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
@@ -959,11 +976,15 @@ jQuery.extend({
                                if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
                                        return elem.getAttributeNode( name ).nodeValue;
 
-                               // elem.tabindex doesn't always return the correct value
+                               // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
                                // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
-                               if ( name == jQuery.props.tabindex ) {
-                                       var attributeNode = elem.getAttributeNode(jQuery.props.tabindex);
-                                       return attributeNode && attributeNode.specified && attributeNode.value || undefined;
+                               if ( name == "tabIndex" ) {
+                                       var attributeNode = elem.getAttributeNode( "tabIndex" );
+                                       return attributeNode && attributeNode.specified
+                                               ? attributeNode.value
+                                               : elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i)
+                                                       ? 0
+                                                       : undefined;
                                }
 
                                return elem[ name ];
@@ -1125,9 +1146,6 @@ jQuery.browser = {
        mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
 };
 
-// Check to see if the W3C box model is being used
-jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
-
 jQuery.each({
        parent: function(elem){return elem.parentNode;},
        parents: function(elem){return jQuery.dir(elem,"parentNode");},