X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcore.js;h=c12b583dbdf822e27d45a84e02525eac6f35b210;hb=f1f5cd9f6a80b0de18cc0402f28b440f48b95f83;hp=7ff9d15cdfa2ca0b1852bf80b8a29537c96f6c6b;hpb=f094c803deba3c35c66f9dc0923db800fb088753;p=jquery.git diff --git a/src/core.js b/src/core.js index 7ff9d15..c12b583 100644 --- a/src/core.js +++ b/src/core.js @@ -166,29 +166,42 @@ jQuery.fn = jQuery.prototype = { }, attr: function( name, value, type ) { - var options = name; + var options = name, isFunction = jQuery.isFunction( value ); // Look for the case where we're accessing a style value - if ( typeof name === "string" ) - if ( value === undefined ) - return this[0] && jQuery[ type || "attr" ]( this[0], name ); + if ( typeof name === "string" ) { + if ( value === undefined ) { + return this.length ? + jQuery[ type || "attr" ]( this[0], name ) : + null; - else { + } else { options = {}; options[ name ] = value; } + } // Check to see if we're setting style values - return this.each(function(i){ + for ( var i = 0, l = this.length; i < l; i++ ) { + var elem = this[i]; + // Set all the styles - for ( name in options ) - jQuery.attr( - type ? - this.style : - this, - name, jQuery.prop( this, options[ name ], type, i, name ) - ); - }); + for ( var prop in options ) { + value = options[prop]; + + if ( isFunction ) { + value = value.call( elem, i ); + } + + if ( typeof value === "number" && type === "curCSS" && !exclude.test(prop) ) { + value = value + "px"; + } + + jQuery.attr( type ? elem.style : elem, prop, value ); + } + } + + return this; }, css: function( key, value ) { @@ -279,14 +292,9 @@ jQuery.fn = jQuery.prototype = { return this.prevObject || jQuery(null); }, - // For internal use only. - // Behaves like an Array's method, not like a jQuery method. - push: [].push, - sort: [].sort, - splice: [].splice, - find: function( selector ) { - var ret = this.pushStack( "", "find", selector ), length = 0; + var ret = this.pushStack( "", "find", selector ), length = 0, + splice = Array.prototype.splice; for ( var i = 0, l = this.length; i < l; i++ ) { length = ret.length; @@ -297,7 +305,7 @@ jQuery.fn = jQuery.prototype = { for ( var n = length; n < ret.length; n++ ) { for ( var r = 0; r < length; r++ ) { if ( ret[r] === ret[n] ) { - ret.splice(n--, 1); + splice.call(ret, n--, 1); break; } } @@ -649,7 +657,7 @@ jQuery.extend({ // 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 && jQuery.isXMLDoc( elem.ownerDocument ); + !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; }, // Evalulates a script in a global context @@ -705,17 +713,6 @@ jQuery.extend({ return object; }, - prop: function( elem, value, type, i, name ) { - // Handle executable functions - if ( jQuery.isFunction( value ) ) - value = value.call( elem, i ); - - // Handle passing in a number to a CSS property - return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ? - value + "px" : - value; - }, - className: { // internal only, use addClass("class") add: function( elem, classNames ) { @@ -979,7 +976,7 @@ jQuery.extend({ if (!elem || elem.nodeType == 3 || elem.nodeType == 8) return undefined; - var notxml = !jQuery.isXMLDoc( elem ), + var notxml = !elem.tagName || !jQuery.isXMLDoc( elem ), // Whether we are setting (or getting) set = value !== undefined;