X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcore.js;h=5c37858a4803c5d86e7503fe6b9c11f0d27ebd77;hb=cd28922b78a91c530c509638294fe3fac9c361f3;hp=61a9bd9f6a406f352ba5310162ea82b121d9d8cf;hpb=49d0d5b7a3628947a14028d14ed042746cc6c3e4;p=jquery.git diff --git a/src/core.js b/src/core.js index 61a9bd9..5c37858 100644 --- a/src/core.js +++ b/src/core.js @@ -47,20 +47,16 @@ jQuery.fn = jQuery.prototype = { else { var elem = document.getElementById( match[3] ); - // Make sure an element was located - 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 - var ret = jQuery( elem ); - ret.context = document; - ret.selector = selector; - return ret; - } - selector = []; + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem && elem.id != match[3] ) + return jQuery().find( selector ); + + // Otherwise, we inject the element directly into the jQuery object + var ret = jQuery( elem || [] ); + ret.context = document; + ret.selector = selector; + return ret; } // HANDLE: $(expr, [context]) @@ -73,6 +69,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)); }, @@ -200,20 +202,22 @@ jQuery.fn = jQuery.prototype = { }, 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(); + + if ( this[0].parentNode ) + wrap.insertBefore( this[0] ); - while ( elem.firstChild ) - elem = elem.firstChild; + wrap.map(function(){ + var elem = this; - return elem; - }) - .append(this); + while ( elem.firstChild ) + elem = elem.firstChild; + + return elem; + }).append(this); + } return this; }, @@ -260,6 +264,8 @@ jQuery.fn = jQuery.prototype = { 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 ) { @@ -336,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; } @@ -609,8 +617,8 @@ jQuery.extend({ // check if an element is in a (or is an) XML document isXMLDoc: function( elem ) { - return elem.documentElement && !elem.body || - elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; + return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || + !!elem.ownerDocument && jQuery.isXMLDoc( elem.ownerDocument ); }, // Evalulates a script in a global context @@ -700,7 +708,7 @@ jQuery.extend({ // internal only, use hasClass("class") has: function( elem, className ) { - return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1; + return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1; } }, @@ -915,8 +923,8 @@ 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] ) ); + 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"))) ); @@ -951,7 +959,7 @@ jQuery.extend({ // 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 @@ -974,9 +982,11 @@ jQuery.extend({ var attributeNode = elem.getAttributeNode( "tabIndex" ); return attributeNode && attributeNode.specified ? attributeNode.value - : elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i) + : elem.nodeName.match(/(button|input|object|select|textarea)/i) ? 0 - : undefined; + : elem.nodeName.match(/^(a|area)$/i) && elem.href + ? 0 + : undefined; } return elem[ name ]; @@ -1138,9 +1148,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");},