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