Tagging the 1.5rc1 release.
[jquery.git] / src / dimensions.js
1 (function( jQuery ) {
2
3 // Create innerHeight, innerWidth, outerHeight and outerWidth methods
4 jQuery.each([ "Height", "Width" ], function( i, name ) {
5
6         var type = name.toLowerCase();
7
8         // innerHeight and innerWidth
9         jQuery.fn["inner" + name] = function() {
10                 return this[0] ?
11                         parseFloat( jQuery.css( this[0], type, "padding" ) ) :
12                         null;
13         };
14
15         // outerHeight and outerWidth
16         jQuery.fn["outer" + name] = function( margin ) {
17                 return this[0] ?
18                         parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
19                         null;
20         };
21
22         jQuery.fn[ type ] = function( size ) {
23                 // Get window width or height
24                 var elem = this[0];
25                 if ( !elem ) {
26                         return size == null ? null : this;
27                 }
28
29                 if ( jQuery.isFunction( size ) ) {
30                         return this.each(function( i ) {
31                                 var self = jQuery( this );
32                                 self[ type ]( size.call( this, i, self[ type ]() ) );
33                         });
34                 }
35
36                 if ( jQuery.isWindow( elem ) ) {
37                         // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
38                         // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
39                         var docElemProp = elem.document.documentElement[ "client" + name ];
40                         return elem.document.compatMode === "CSS1Compat" && docElemProp ||
41                                 elem.document.body[ "client" + name ] || docElemProp;
42
43                 // Get document width or height
44                 } else if ( elem.nodeType === 9 ) {
45                         // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
46                         return Math.max(
47                                 elem.documentElement["client" + name],
48                                 elem.body["scroll" + name], elem.documentElement["scroll" + name],
49                                 elem.body["offset" + name], elem.documentElement["offset" + name]
50                         );
51
52                 // Get or set width or height on the element
53                 } else if ( size === undefined ) {
54                         var orig = jQuery.css( elem, type ),
55                                 ret = parseFloat( orig );
56
57                         return jQuery.isNaN( ret ) ? orig : ret;
58
59                 // Set the width or height on the element (default to pixels if value is unitless)
60                 } else {
61                         return this.css( type, typeof size === "string" ? size : size + "px" );
62                 }
63         };
64
65 });
66
67 })( jQuery );