X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=inline;f=src%2Fcore.js;h=56fbbde1cceefc601785b22ec201894446b0dd76;hb=ace13387c8d7b5823a580db0f1b2aafac515b9f5;hp=55e62363fedcd2e566dbff12ffead3806730ed7f;hpb=4bbb70b4eb0bcd93c99c0bfcfcf4fc44504c4c41;p=jquery.git diff --git a/src/core.js b/src/core.js index 55e6236..56fbbde 100644 --- a/src/core.js +++ b/src/core.js @@ -71,7 +71,7 @@ jQuery.fn = jQuery.prototype = { return (context || rootjQuery).find( selector ); // HANDLE: $(expr, context) - // (which is just equivalent to: $(content).find(expr) + // (which is just equivalent to: $(context).find(expr) } else { return jQuery( context ).find( selector ); } @@ -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 ) { @@ -286,18 +299,26 @@ jQuery.fn = jQuery.prototype = { splice: [].splice, find: function( selector ) { - if ( this.length === 1 ) { - var ret = this.pushStack( "", "find", selector ); - jQuery.find( selector, this[0], ret ); - return ret; - } else { - var ret = this.pushStack( "", "find", selector ); - for ( var i = 0, l = this.length; i < l; i++ ) { - jQuery.find( selector, this[i], ret ); + var ret = this.pushStack( "", "find", selector ), length = 0; + + for ( var i = 0, l = this.length; i < l; i++ ) { + length = ret.length; + jQuery.find( selector, this[i], ret ); + + if ( i > 0 ) { + // Make sure that the results are unique + for ( var n = length; n < ret.length; n++ ) { + for ( var r = 0; r < length; r++ ) { + if ( ret[r] === ret[n] ) { + ret.splice(n--, 1); + break; + } + } + } } - //jQuery.find.uniqueSort( ret ); - return ret; } + + return ret; }, clone: function( events ) { @@ -312,14 +333,14 @@ jQuery.fn = jQuery.prototype = { // attributes in IE that are actually only stored // as properties will not be copied (such as the // the name attribute on an input). - var html = this.outerHTML; + var html = this.outerHTML, ownerDocument = this.ownerDocument; if ( !html ) { - var div = this.ownerDocument.createElement("div"); + var div = ownerDocument.createElement("div"); div.appendChild( this.cloneNode(true) ); html = div.innerHTML; } - return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0]; + return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")], ownerDocument)[0]; } else return this.cloneNode(true); }); @@ -641,7 +662,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 @@ -697,17 +718,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 ) { @@ -971,7 +981,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; @@ -994,7 +1004,7 @@ jQuery.extend({ if ( name in elem && notxml && !special ) { if ( set ){ // We can't allow the type property to be changed (since it causes problems in IE) - if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode ) + if ( name == "type" && elem.nodeName.match(/(button|input)/i) && elem.parentNode ) throw "type property can't be changed"; elem[ name ] = value; @@ -1279,8 +1289,3 @@ function cleanData( elems ) { } } } - -// Helper function used by the dimensions and offset modules -function num(elem, prop) { - return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0; -}