X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fdimensions.js;h=297118457375a3103ff5d6b05d0e15ce7e434f8e;hb=b850ab2b8e65eadd25093c81bbc67a881daa0488;hp=e707f83387f3e6a5bd26dd77b42f28b369343d90;hpb=aea452f1624df811c8b0b2916bfb22213d153f9d;p=jquery.git diff --git a/src/dimensions.js b/src/dimensions.js index e707f83..2971184 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -1,28 +1,50 @@ // Create innerHeight, innerWidth, outerHeight and outerWidth methods jQuery.each([ "Height", "Width" ], function(i, name){ - var tl = name == "Height" ? "Top" : "Left", // top or left - br = name == "Height" ? "Bottom" : "Right"; // bottom or right - + var tl = i ? "Left" : "Top", // top or left + br = i ? "Right" : "Bottom"; // bottom or right + // innerHeight and innerWidth jQuery.fn["inner" + name] = function(){ - return this[ name.toLowerCase() ]() + - num(this, "padding" + tl) + + return this[ name.toLowerCase() ]() + + num(this, "padding" + tl) + num(this, "padding" + br); }; - + // outerHeight and outerWidth jQuery.fn["outer" + name] = function(margin) { - return this["inner" + name]() + + return this["inner" + name]() + num(this, "border" + tl + "Width") + num(this, "border" + br + "Width") + - (!!margin ? + (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" ); + }; -function num(elem, prop) { - elem = elem.jquery ? elem[0] : elem; - return elem && parseInt( jQuery.curCSS(elem, prop, true) ) || 0; -} \ No newline at end of file +}); \ No newline at end of file