X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcore.js;h=cb9b528eca4d46b149bc0f947db4bc5acd691cb4;hb=3d8ceaf2f21f4782ff21746887e2bcf56025e704;hp=18ecf21f000d51b4630022441c2a35d5015e9ba5;hpb=03de2cb5e7945fac42bc612b290dbe460924cc51;p=jquery.git diff --git a/src/core.js b/src/core.js index 18ecf21..cb9b528 100644 --- a/src/core.js +++ b/src/core.js @@ -34,8 +34,10 @@ var jQuery = function( selector, context ) { // Keep a UserAgent string for use with jQuery.browser userAgent = navigator.userAgent.toLowerCase(), - // Save a reference to the core toString method - toString = Object.prototype.toString; + // Save a reference to some core methods + toString = Object.prototype.toString, + push = Array.prototype.push, + slice = Array.prototype.slice; // Expose jQuery to the global object window.jQuery = window.$ = jQuery; @@ -126,7 +128,9 @@ jQuery.fn = jQuery.prototype = { return this.length; }, - toArray: Array.prototype.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 @@ -137,7 +141,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 @@ -168,7 +172,7 @@ jQuery.fn = jQuery.prototype = { // Resetting the length to 0, then using the native Array push // is a super-fast way to populate an object with array-like properties this.length = 0; - Array.prototype.push.apply( this, elems ); + push.apply( this, elems ); return this; }, @@ -201,7 +205,7 @@ jQuery.fn = jQuery.prototype = { // For internal use only. // Behaves like an Array's method, not like a jQuery method. - push: [].push, + push: push, sort: [].sort, splice: [].splice }; @@ -249,10 +253,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 ); @@ -296,15 +305,15 @@ 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"; + return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML"; }, // Evalulates a script in a global context @@ -316,6 +325,7 @@ jQuery.extend({ script = document.createElement("script"); script.type = "text/javascript"; + if ( jQuery.support.scriptEval ) { script.appendChild( document.createTextNode( data ) ); } else {