X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fcore.js;h=23b96442e961a929e01fd6f69a1a7eeb46817406;hb=957cd6fb2a2b7b8cfe9ac6b3f2b3cc2bc8163449;hp=88c04373d8d819561f20e43d32854066298a80d2;hpb=b953c1d50a2c9a169b7fc47e78c2b8b0acb8a93d;p=jquery.git diff --git a/src/core.js b/src/core.js index 88c0437..23b9644 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,14 @@ 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; + } // Handle $(DOMElement) if ( selector.nodeType ) { @@ -70,12 +69,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 +129,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 +142,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 @@ -251,10 +254,15 @@ jQuery.extend = jQuery.fn.extend = function() { if ( deep && copy && typeof copy === "object" && !copy.nodeType ) { var clone; - if( src ) clone = src; - else if( jQuery.isArray(copy) ) clone = [ ]; - else if( jQuery.isObject(copy) ) clone = { }; - else clone = copy; + if ( src ) { + clone = src; + } else if ( jQuery.isArray(copy) ) { + clone = []; + } else if ( jQuery.isObject(copy) ) { + clone = {}; + } else { + clone = copy; + } // Never move original objects, clone them target[ name ] = jQuery.extend( deep, clone, copy ); @@ -298,15 +306,17 @@ jQuery.extend({ }, isEmptyObject: function( obj ) { - for(var name in obj) + for ( var name in obj ) { return false; + } return true; }, // check if an element is in a (or is an) XML document isXMLDoc: function( elem ) { - return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || - !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + return ((elem ? elem.ownerDocument || elem : 0).documentElement || 0).nodeName !== "HTML"; }, // Evalulates a script in a global context @@ -318,6 +328,7 @@ jQuery.extend({ script = document.createElement("script"); script.type = "text/javascript"; + if ( jQuery.support.scriptEval ) { script.appendChild( document.createTextNode( data ) ); } else {