X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcore.js;h=5ccf15875ce9f20ee16c80b5d17da37a42636bde;hb=b7d4e0e46cb2cad6f400173cd09ce44d1b8ad04e;hp=b105c4c5b9d920a8d35c5cf3e1c8a3e3a313c157;hpb=b964e56946c9111d7e53fa1eafb14cab3cd642f2;p=jquery.git diff --git a/src/core.js b/src/core.js index b105c4c..5ccf158 100644 --- a/src/core.js +++ b/src/core.js @@ -20,7 +20,7 @@ var jQuery = function( selector, context ) { // A simple way to check for HTML strings or ID strings // (both of which we optimize for) - quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/, + quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/, // Is it a simple selector isSimple = /^.[^:#\[\.,]*$/, @@ -39,15 +39,19 @@ var jQuery = function( selector, context ) { push = Array.prototype.push, slice = Array.prototype.slice; -// Expose jQuery to the global object -window.jQuery = window.$ = jQuery; - jQuery.fn = jQuery.prototype = { init: function( selector, context ) { var match, elem, ret; // Handle $(""), $(null), or $(undefined) - if ( !selector ) return this; + if ( !selector ) { + return this; + } + + // $("body"): Shortcut for quickly finding the body element + if ( selector === "body" && !context && document.body ) { + selector = document.body; + } // Handle $(DOMElement) if ( selector.nodeType ) { @@ -70,12 +74,14 @@ jQuery.fn = jQuery.prototype = { // HANDLE: $("#id") } else { - elem = document.getElementById( match[3] ); + elem = document.getElementById( match[2] ); if ( elem ) { // Handle the case where IE and Opera return items // by name instead of ID - if ( elem.id !== match[3] ) return rootjQuery.find( selector ); + if ( elem.id !== match[2] ) { + return rootjQuery.find( selector ); + } // Otherwise, we inject the element directly into the jQuery object this.length++; @@ -128,7 +134,9 @@ jQuery.fn = jQuery.prototype = { return this.length; }, - toArray: slice, + toArray: function(){ + return slice.call( this, 0 ); + }, // Get the Nth element in the matched element set OR // Get the whole matched element set as a clean array @@ -139,7 +147,7 @@ jQuery.fn = jQuery.prototype = { this.toArray() : // Return just the object - ( num < 0 ? this.toArray(num)[ 0 ] : this[ num ] ); + ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] ); }, // Take an array of elements and push it onto the stack @@ -311,7 +319,10 @@ jQuery.extend({ // check if an element is in a (or is an) XML document isXMLDoc: function( elem ) { - return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML"; + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; + return documentElement ? documentElement.nodeName !== "HTML" : false; }, // Evalulates a script in a global context