From: Dave Methvin Date: Thu, 5 Jul 2012 21:21:58 +0000 (-0400) Subject: Fix #12026. Let props in $(html, props) be any jQuery.fn method. X-Git-Tag: 1.8b2~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cdd5132dcc02d4a3ff8df390677ffb8ff4b5a477;p=jquery.git Fix #12026. Let props in $(html, props) be any jQuery.fn method. Closes gh-839. --- diff --git a/src/attributes.js b/src/attributes.js index 858002c0f..d7ad3156a 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -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 ) { var ret, hooks, notxml, nType = elem.nodeType; @@ -301,7 +290,7 @@ jQuery.extend({ return; } - if ( pass && name in jQuery.attrFn ) { + if ( pass && jQuery.isFunction( jQuery.fn[ name ] ) ) { return jQuery( elem )[ name ]( value ); } diff --git a/test/unit/core.js b/test/unit/core.js index 58305b688..44920edcf 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -35,20 +35,24 @@ test("jQuery()", function() { "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 ) { expected++; attrObj["width"] = 10; } - if ( jQuery.fn.offset ) { expected++; attrObj["offset"] = { "top": 1, "left": 1 }; } - - if ( jQuery.css ) { + if ( jQuery.fn.css ) { expected += 2; attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 }; } + if ( jQuery.fn.attr ) { + expected++; + attrObj.attr = { "desired": "very" }; + } expect( expected ); @@ -107,11 +111,15 @@ test("jQuery()", function() { 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.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].firstChild.nodeValue, "test", "jQuery quick setter text"); equal( elem[0].className, "test2", "jQuery() quick setter class");