blob: 2a2c0391df5ac34cc4800670191cee39709ff661 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001define( [
2 "./core",
3 "./core/access",
4 "./var/isWindow",
5 "./css"
6], function( jQuery, access, isWindow ) {
7
8"use strict";
9
10// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
11jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
12 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name },
13 function( defaultExtra, funcName ) {
14
15 // Margin is only for outerHeight, outerWidth
16 jQuery.fn[ funcName ] = function( margin, value ) {
17 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
18 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
19
20 return access( this, function( elem, type, value ) {
21 var doc;
22
23 if ( isWindow( elem ) ) {
24
25 // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
26 return funcName.indexOf( "outer" ) === 0 ?
27 elem[ "inner" + name ] :
28 elem.document.documentElement[ "client" + name ];
29 }
30
31 // Get document width or height
32 if ( elem.nodeType === 9 ) {
33 doc = elem.documentElement;
34
35 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
36 // whichever is greatest
37 return Math.max(
38 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
39 elem.body[ "offset" + name ], doc[ "offset" + name ],
40 doc[ "client" + name ]
41 );
42 }
43
44 return value === undefined ?
45
46 // Get width or height on the element, requesting but not forcing parseFloat
47 jQuery.css( elem, type, extra ) :
48
49 // Set width or height on the element
50 jQuery.style( elem, type, value, extra );
51 }, type, chainable ? margin : undefined, chainable );
52 };
53 } );
54} );
55
56return jQuery;
57} );