Added the new jQuery.support object and removed all uses of jQuery.browser from withi...
[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
7         // innerHeight and innerWidth
8         jQuery.fn["inner" + name] = function(){
9                 return this[ name.toLowerCase() ]() +
10                         num(this, "padding" + tl) +
11                         num(this, "padding" + br);
12         };
13
14         // outerHeight and outerWidth
15         jQuery.fn["outer" + name] = function(margin) {
16                 return this["inner" + name]() +
17                         num(this, "border" + tl + "Width") +
18                         num(this, "border" + br + "Width") +
19                         (margin ?
20                                 num(this, "margin" + tl) + num(this, "margin" + br) : 0);
21         };
22         
23         var type = name.toLowerCase();
24
25         jQuery.fn[ type ] = function( size ) {
26                 // Get window width or height
27                 return this[0] == window ?
28                         // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
29                         document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] ||
30                         document.body[ "client" + name ] :
31
32                         // Get document width or height
33                         this[0] == document ?
34                                 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
35                                 Math.max(
36                                         document.documentElement["client" + name],
37                                         document.body["scroll" + name], document.documentElement["scroll" + name],
38                                         document.body["offset" + name], document.documentElement["offset" + name]
39                                 ) :
40
41                                 // Get or set width or height on the element
42                                 size === undefined ?
43                                         // Get width or height on the element
44                                         (this.length ? jQuery.css( this[0], type ) : null) :
45
46                                         // Set the width or height on the element (default to pixels if value is unitless)
47                                         this.css( type, typeof size === "string" ? size : size + "px" );
48         };
49
50 });