Skip to content

Commit

Permalink
Fix #12026. Let props in $(html, props) be any jQuery.fn method.
Browse files Browse the repository at this point in the history
Closes gh-839.
  • Loading branch information
dmethvin committed Jul 5, 2012
1 parent 1e02761 commit cdd5132
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 1 addition & 12 deletions src/attributes.js
Expand Up @@ -281,17 +281,6 @@ jQuery.extend({
} }
}, },


attrFn: {
val: true,
css: true,
html: true,
text: true,
data: true,
width: true,
height: true,
offset: true
},

attr: function( elem, name, value, pass ) { attr: function( elem, name, value, pass ) {
var ret, hooks, notxml, var ret, hooks, notxml,
nType = elem.nodeType; nType = elem.nodeType;
Expand All @@ -301,7 +290,7 @@ jQuery.extend({
return; return;
} }


if ( pass && name in jQuery.attrFn ) { if ( pass && jQuery.isFunction( jQuery.fn[ name ] ) ) {
return jQuery( elem )[ name ]( value ); return jQuery( elem )[ name ]( value );
} }


Expand Down
16 changes: 12 additions & 4 deletions test/unit/core.js
Expand Up @@ -35,20 +35,24 @@ test("jQuery()", function() {
"id": "test3" "id": "test3"
}; };


// The $(html, props) signature can stealth-call any $.fn method, check for a
// few here but beware of modular builds where these methods may be excluded.
if ( jQuery.fn.width ) { if ( jQuery.fn.width ) {
expected++; expected++;
attrObj["width"] = 10; attrObj["width"] = 10;
} }

if ( jQuery.fn.offset ) { if ( jQuery.fn.offset ) {
expected++; expected++;
attrObj["offset"] = { "top": 1, "left": 1 }; attrObj["offset"] = { "top": 1, "left": 1 };
} }

if ( jQuery.fn.css ) {
if ( jQuery.css ) {
expected += 2; expected += 2;
attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 }; attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
} }
if ( jQuery.fn.attr ) {
expected++;
attrObj.attr = { "desired": "very" };
}


expect( expected ); expect( expected );


Expand Down Expand Up @@ -107,11 +111,15 @@ test("jQuery()", function() {
equal( elem[0].style.top, "1px", "jQuery() quick setter offset"); equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
} }


if ( jQuery.css ) { if ( jQuery.fn.css ) {
equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
} }


if ( jQuery.fn.attr ) {
equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
}

equal( elem[0].childNodes.length, 1, "jQuery quick setter text"); equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
equal( elem[0].className, "test2", "jQuery() quick setter class"); equal( elem[0].className, "test2", "jQuery() quick setter class");
Expand Down

6 comments on commit cdd5132

@timmywil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we all sigh together.

@dmethvin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minus 36, timmy, MINUS 36!

@timmywil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha

@scottgonzalez
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who needs chaining when you have objects?

@dmethvin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottgonzalez, or vice-versa!

Oh geez, that reminds me....

@dmethvin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saved another 12 with that event.js whack, so minus 48.

Please sign in to comment.