git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
1c8c388
)
Simplified the structure of the .css() and .attr() methods (reducing the number of...
author
John Resig
<jeresig@gmail.com>
Sat, 28 Feb 2009 20:23:48 +0000
(20:23 +0000)
committer
John Resig
<jeresig@gmail.com>
Sat, 28 Feb 2009 20:23:48 +0000
(20:23 +0000)
src/core.js
patch
|
blob
|
history
test/unit/core.js
patch
|
blob
|
history
diff --git
a/src/core.js
b/src/core.js
index
56fd098
..
c12b583
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-166,29
+166,42
@@
jQuery.fn = jQuery.prototype = {
},
attr: function( name, value, type ) {
},
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
// 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;
}
options = {};
options[ name ] = value;
}
+ }
// Check to see if we're setting style values
// 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
// 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 ) {
},
css: function( key, value ) {
@@
-644,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" ||
// 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
},
// Evalulates a script in a global context
@@
-700,17
+713,6
@@
jQuery.extend({
return object;
},
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 ) {
className: {
// internal only, use addClass("class")
add: function( elem, classNames ) {
@@
-974,7
+976,7
@@
jQuery.extend({
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
return undefined;
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;
// Whether we are setting (or getting)
set = value !== undefined;
diff --git
a/test/unit/core.js
b/test/unit/core.js
index
9d91c4f
..
a4e82eb
100644
(file)
--- a/
test/unit/core.js
+++ b/
test/unit/core.js
@@
-1688,13
+1688,6
@@
test("jQuery.each(Object,Function)", function() {
equals( total, 3, "Looping over an object, with break" );
});
equals( total, 3, "Looping over an object, with break" );
});
-test("jQuery.prop", function() {
- expect(2);
- var handle = function() { return this.id };
- equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" );
- equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" );
-});
-
test("jQuery.className", function() {
expect(6);
var x = jQuery("<p>Hi</p>")[0];
test("jQuery.className", function() {
expect(6);
var x = jQuery("<p>Hi</p>")[0];