Skip to content

Commit 1ebced1

Browse files
committed
Add support for calling outer/inner Width/Height on the window and document. Fixes #9434.
1 parent 96a44a8 commit 1ebced1

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

‎src/dimensions.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
88
// innerHeight and innerWidth
99
jQuery.fn[ "inner" + name ] = function() {
1010
var elem = this[0];
11-
return elem && elem.style ?
11+
return elem ?
12+
elem.style ?
1213
parseFloat( jQuery.css( elem, type, "padding" ) ) :
14+
this[ type ]() :
1315
null;
1416
};
1517

1618
// outerHeight and outerWidth
1719
jQuery.fn[ "outer" + name ] = function( margin ) {
1820
var elem = this[0];
19-
return elem && elem.style ?
21+
return elem ?
22+
elem.style ?
2023
parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
24+
this[ type ]() :
2125
null;
2226
};
2327

‎test/unit/dimensions.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ test("height() with function args", function() {
109109
test("innerWidth()", function() {
110110
expect(8);
111111

112-
equals(jQuery(window).innerWidth(), null, "Test on window without margin option");
113-
equals(jQuery(window).innerWidth(true), null, "Test on window with margin option");
112+
var winWidth = jQuery( window ).width(),
113+
docWidth = jQuery( document ).width();
114114

115-
equals(jQuery(document).innerWidth(), null, "Test on document without margin option");
116-
equals(jQuery(document).innerWidth(true), null, "Test on document with margin option");
115+
equals(jQuery(window).innerWidth(), winWidth, "Test on window without margin option");
116+
equals(jQuery(window).innerWidth(true), winWidth, "Test on window with margin option");
117+
118+
equals(jQuery(document).innerWidth(), docWidth, "Test on document without margin option");
119+
equals(jQuery(document).innerWidth(true), docWidth, "Test on document with margin option");
117120

118121
var $div = jQuery("#nothiddendiv");
119122
// set styles
@@ -144,11 +147,14 @@ test("innerWidth()", function() {
144147
test("innerHeight()", function() {
145148
expect(8);
146149

147-
equals(jQuery(window).innerHeight(), null, "Test on window without margin option");
148-
equals(jQuery(window).innerHeight(true), null, "Test on window with margin option");
150+
var winHeight = jQuery( window ).height(),
151+
docHeight = jQuery( document ).height();
152+
153+
equals(jQuery(window).innerHeight(), winHeight, "Test on window without margin option");
154+
equals(jQuery(window).innerHeight(true), winHeight, "Test on window with margin option");
149155

150-
equals(jQuery(document).innerHeight(), null, "Test on document without margin option");
151-
equals(jQuery(document).innerHeight(true), null, "Test on document with margin option");
156+
equals(jQuery(document).innerHeight(), docHeight, "Test on document without margin option");
157+
equals(jQuery(document).innerHeight(true), docHeight, "Test on document with margin option");
152158

153159
var $div = jQuery("#nothiddendiv");
154160
// set styles
@@ -179,10 +185,13 @@ test("innerHeight()", function() {
179185
test("outerWidth()", function() {
180186
expect(11);
181187

182-
equal( jQuery( window ).outerWidth(), null, "Test on window without margin option" );
183-
equal( jQuery( window ).outerWidth( true ), null, "Test on window with margin option" );
184-
equal( jQuery( document ).outerWidth(), null, "Test on document without margin option" );
185-
equal( jQuery( document ).outerWidth( true ), null, "Test on document with margin option" );
188+
var winWidth = jQuery( window ).width(),
189+
docWidth = jQuery( document ).width();
190+
191+
equal( jQuery( window ).outerWidth(), winWidth, "Test on window without margin option" );
192+
equal( jQuery( window ).outerWidth( true ), winWidth, "Test on window with margin option" );
193+
equal( jQuery( document ).outerWidth(), docWidth, "Test on document without margin option" );
194+
equal( jQuery( document ).outerWidth( true ), docWidth, "Test on document with margin option" );
186195

187196
var $div = jQuery("#nothiddendiv");
188197
$div.css("width", 30);
@@ -239,10 +248,14 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944
239248
test("outerHeight()", function() {
240249
expect(11);
241250

242-
equal( jQuery( window ).outerHeight(), null, "Test on window without margin option" );
243-
equal( jQuery( window ).outerHeight( true ), null, "Test on window with margin option" );
244-
equal( jQuery( document ).outerHeight(), null, "Test on document without margin option" );
245-
equal( jQuery( document ).outerHeight( true ), null, "Test on document with margin option" );
251+
var winHeight = jQuery( window ).height(),
252+
docHeight = jQuery( document ).height();
253+
254+
255+
equal( jQuery( window ).outerHeight(), winHeight, "Test on window without margin option" );
256+
equal( jQuery( window ).outerHeight( true ), winHeight, "Test on window with margin option" );
257+
equal( jQuery( document ).outerHeight(), docHeight, "Test on document without margin option" );
258+
equal( jQuery( document ).outerHeight( true ), docHeight, "Test on document with margin option" );
246259

247260
var $div = jQuery("#nothiddendiv");
248261
$div.css("height", 30);

0 commit comments

Comments
 (0)