aboutsummaryrefslogtreecommitdiffstats
path: root/src/dimensions.js
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2012-05-21 13:44:19 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-05-21 13:44:19 -0400
commite0151e5827d7091f311c82d9f951aaaa2688ba8c (patch)
treed165ce81413d61a4e04096e33e637c1b8f305e8c /src/dimensions.js
parent978acb9caf9ad5e645e1e5188a0120f05822cc81 (diff)
downloadjquery-e0151e5827d7091f311c82d9f951aaaa2688ba8c.tar.gz
jquery-e0151e5827d7091f311c82d9f951aaaa2688ba8c.zip
Fix #10877. Make outerWidth/Height a setter. Closes gh-783.
Diffstat (limited to 'src/dimensions.js')
-rw-r--r--src/dimensions.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/dimensions.js b/src/dimensions.js
index d4d7915ff..79d7c22bc 100644
--- a/src/dimensions.js
+++ b/src/dimensions.js
@@ -6,27 +6,27 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
scrollProp = "scroll" + name,
offsetProp = "offset" + name;
- // innerHeight and innerWidth
- jQuery.fn[ "inner" + name ] = function() {
- var elem = this[0];
- return elem ?
- elem.style ?
- parseFloat( jQuery.css( elem, type, "padding" ) ) :
- this[ type ]() :
- null;
- };
+ // height, width, innerHeight and innerWidth
+ jQuery.each( { padding: "inner" + name, content: type }, function( extra, funcName ) {
+ jQuery.fn[ funcName ] = function( value ) {
+ var args = [ type, extra ];
+ if ( arguments.length ) {
+ args.push( value );
+ }
+ return getDimension.apply( this, args );
+ };
+ });
// outerHeight and outerWidth
- jQuery.fn[ "outer" + name ] = function( margin ) {
- var elem = this[0];
- return elem ?
- elem.style ?
- parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
- this[ type ]() :
- null;
+ jQuery.fn[ "outer" + name ] = function( margin, value ) {
+ var args = [ type, ( margin === true || value === true ) ? "margin" : "border" ];
+ if ( arguments.length && typeof margin !== "boolean" ) {
+ args.push( margin );
+ }
+ return getDimension.apply( this, args );
};
- jQuery.fn[ type ] = function( value ) {
+ function getDimension( type, extra, value ) {
return jQuery.access( this, function( elem, type, value ) {
var doc, orig, ret;
@@ -58,15 +58,15 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
// Get width or height on the element
if ( value === undefined ) {
- orig = jQuery.css( elem, type, "content" );
+ orig = jQuery.css( elem, type, extra );
ret = parseFloat( orig );
return jQuery.isNumeric( ret ) ? ret : orig;
}
// Set the width or height on the element
- jQuery.style( elem, type, value );
- }, type, value, arguments.length, null );
- };
+ jQuery.style( elem, type, value, extra );
+ }, type, value, arguments.length > 2, null );
+ }
});
})( jQuery );