X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fdimensions.js;h=297118457375a3103ff5d6b05d0e15ce7e434f8e;hb=a1ca9427eca113e6747e99a86b2283e3a6f63502;hp=bcef47fdfe3da1fd9e1a27feee35a068e2045874;hpb=5a92ec263d8289d2b6d21bcbfe02910c47a6ea4a;p=jquery.git diff --git a/src/dimensions.js b/src/dimensions.js index bcef47f..2971184 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -19,5 +19,32 @@ jQuery.each([ "Height", "Width" ], function(i, name){ (margin ? num(this, "margin" + tl) + num(this, "margin" + br) : 0); }; + + var type = name.toLowerCase(); + + jQuery.fn[ type ] = function( size ) { + // Get window width or height + return this[0] == window ? + // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode + document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || + document.body[ "client" + name ] : + + // Get document width or height + this[0] == document ? + // Either scroll[Width/Height] or offset[Width/Height], whichever is greater + Math.max( + document.documentElement["client" + name], + document.body["scroll" + name], document.documentElement["scroll" + name], + document.body["offset" + name], document.documentElement["offset" + name] + ) : + + // Get or set width or height on the element + size === undefined ? + // Get width or height on the element + (this.length ? jQuery.css( this[0], type ) : null) : + + // Set the width or height on the element (default to pixels if value is unitless) + this.css( type, typeof size === "string" ? size : size + "px" ); + }; }); \ No newline at end of file