Update copyright year
[jquery.git] / src / dimensions.js
blob9e4d5729d8facc8673764d0054bd5bf03b15d801
1 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
2 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
3         jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
4                 // margin is only for outerHeight, outerWidth
5                 jQuery.fn[ funcName ] = function( margin, value ) {
6                         var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
7                                 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
9                         return jQuery.access( this, function( elem, type, value ) {
10                                 var doc;
12                                 if ( jQuery.isWindow( elem ) ) {
13                                         // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
14                                         // isn't a whole lot we can do. See pull request at this URL for discussion:
15                                         // https://github.com/jquery/jquery/pull/764
16                                         return elem.document.documentElement[ "client" + name ];
17                                 }
19                                 // Get document width or height
20                                 if ( elem.nodeType === 9 ) {
21                                         doc = elem.documentElement;
23                                         // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], whichever is greatest
24                                         // unfortunately, this causes bug #3838 in IE6/8 only, but there is currently no good, small way to fix it.
25                                         return Math.max(
26                                                 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
27                                                 elem.body[ "offset" + name ], doc[ "offset" + name ],
28                                                 doc[ "client" + name ]
29                                         );
30                                 }
32                                 return value === undefined ?
33                                         // Get width or height on the element, requesting but not forcing parseFloat
34                                         jQuery.css( elem, type, extra ) :
36                                         // Set width or height on the element
37                                         jQuery.style( elem, type, value, extra );
38                         }, type, chainable ? margin : undefined, chainable, null );
39                 };
40         });
41 });