Renamed src/transports to src/ajax (in case we need prefilters in the future and...
[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                         return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
39                                 elem.document.body[ "client" + name ];
40
41                 // Get document width or height
42                 } else if ( elem.nodeType === 9 ) {
43                         // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
44                         return Math.max(
45                                 elem.documentElement["client" + name],
46                                 elem.body["scroll" + name], elem.documentElement["scroll" + name],
47                                 elem.body["offset" + name], elem.documentElement["offset" + name]
48                         );
49
50                 // Get or set width or height on the element
51                 } else if ( size === undefined ) {
52                         var orig = jQuery.css( elem, type ),
53                                 ret = parseFloat( orig );
54
55                         return jQuery.isNaN( ret ) ? orig : ret;
56
57                 // Set the width or height on the element (default to pixels if value is unitless)
58                 } else {
59                         return this.css( type, typeof size === "string" ? size : size + "px" );
60                 }
61         };
62
63 });
64
65 })( jQuery );