jquery dimensions: removed redundant code
[jquery.git] / src / dimensions.js
1 // Create innerHeight, innerWidth, outerHeight and outerWidth methods
2 jQuery.each([ "Height", "Width" ], function(i, name){
3
4         var tl = i ? "Left"  : "Top",  // top or left
5                 br = i ? "Right" : "Bottom", // bottom or right
6                 type = name.toLowerCase();
7
8         // innerHeight and innerWidth
9         jQuery.fn["inner" + name] = function(){
10                 return this[0] ?
11                         jQuery.css( this[0], type, false, "padding" ) :
12                         null;
13         };
14
15         // outerHeight and outerWidth
16         jQuery.fn["outer" + name] = function(margin) {
17                 return this[0] ?
18                         jQuery.css( this[0], type, false, margin ? "margin" : "border" ) :
19                         null;
20         };
21         
22         jQuery.fn[ type ] = function( size ) {
23                 // Get window width or height
24                 return this[0] == window ?
25                         // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
26                         document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] ||
27                         document.body[ "client" + name ] :
28
29                         // Get document width or height
30                         this[0] == document ?
31                                 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
32                                 Math.max(
33                                         document.documentElement["client" + name],
34                                         document.body["scroll" + name], document.documentElement["scroll" + name],
35                                         document.body["offset" + name], document.documentElement["offset" + name]
36                                 ) :
37
38                                 // Get or set width or height on the element
39                                 size === undefined ?
40                                         // Get width or height on the element
41                                         (this.length ? jQuery.css( this[0], type ) : null) :
42
43                                         // Set the width or height on the element (default to pixels if value is unitless)
44                                         this.css( type, typeof size === "string" ? size : size + "px" );
45         };
46
47 });