Event: Make trigger(focus/blur/click) work with native handlers
[jquery.git] / src / dimensions.js
blob42e445362bb5295722d7efae196e933a2f38a32f
1 import jQuery from "./core.js";
2 import access from "./core/access.js";
3 import isWindow from "./var/isWindow.js";
5 import "./css.js";
7 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
8 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
9         jQuery.each( {
10                 padding: "inner" + name,
11                 content: type,
12                 "": "outer" + name
13         }, function( defaultExtra, funcName ) {
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" );
20                         return access( this, function( elem, type, value ) {
21                                 var doc;
23                                 if ( isWindow( elem ) ) {
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                                 }
31                                 // Get document width or height
32                                 if ( elem.nodeType === 9 ) {
33                                         doc = elem.documentElement;
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                                 }
44                                 return value === undefined ?
46                                         // Get width or height on the element, requesting but not forcing parseFloat
47                                         jQuery.css( elem, type, extra ) :
49                                         // Set width or height on the element
50                                         jQuery.style( elem, type, value, extra );
51                         }, type, chainable ? margin : undefined, chainable );
52                 };
53         } );
54 } );
56 export default jQuery;