} 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));
},
},
wrapAll: function( html ) {
- if ( this[0] )
+ if ( this[0] ) {
// The elements to wrap the target around
- jQuery( html, this[0].ownerDocument )
- .clone()
- .insertBefore( this[0] )
- .map(function(){
- var elem = this;
+ var wrap = jQuery( html, this[0].ownerDocument ).clone();
- while ( elem.firstChild )
- elem = elem.firstChild;
+ if ( this[0].parentNode )
+ wrap.insertBefore( this[0] );
- return elem;
- })
- .append(this);
+ wrap.map(function(){
+ var elem = this;
+
+ while ( elem.firstChild )
+ elem = elem.firstChild;
+
+ return elem;
+ }).append(this);
+ }
return this;
},
return this.prevObject || jQuery( [] );
},
+ // For internal use only.
+ // Behaves like an Array's .push method, not like a jQuery method.
+ push: [].push,
+
find: function( selector ) {
- if ( this.length === 1 ) {
- return this.pushStack( jQuery.find( selector, this[0] ), "find", selector );
+ 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 );
},
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;
}
if ( fragment ) {
for ( var i = 0; ret[i]; i++ ) {
- if ( jQuery.nodeName( ret[i], "script" ) ) {
- scripts.push( ret[i].parentNode.removeChild( ret[i] ) );
+ if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
+ 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"))) );
// Safari mis-reports the default selected property of a hidden option
// Accessing the parent's selectedIndex property fixes it
- if ( name == "selected" )
+ if ( name == "selected" && elem.parentNode )
elem.parentNode.selectedIndex;
// If applicable, access the attribute via the DOM 0 way
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 ];
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");},