Skip to content

Commit 8eb35e8

Browse files
authored
Tests: fix supportsScroll feature test in offset
- iOS 12 and below do not support scrollTop/Left on the window or document. Before 82169df, window.supportsScroll was always undefined. There were 2 issues: (1) iOS <=12 do support scroll props on the body, so the support test wasn't helpful. (2) one test checked the wrong window and the value was always undefined, which meant those tests never ran in any browser. Closes jquerygh-5506
1 parent 82169df commit 8eb35e8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/unit/offset.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if ( !includesModule( "offset" ) ) {
44
return;
55
}
66

7-
var alwaysScrollable,
7+
var alwaysScrollable, supportsFixedPosition, supportsScroll,
88
forceScroll = supportjQuery( "<div></div>" ).css( { width: 2000, height: 2000 } ),
99
checkSupport = function( assert ) {
1010

@@ -14,13 +14,14 @@ var alwaysScrollable,
1414
var checkFixed = supportjQuery( "<div/>" )
1515
.css( { position: "fixed", top: "20px" } )
1616
.appendTo( "#qunit-fixture" );
17-
window.supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
17+
supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
1818
checkFixed.remove();
1919

2020
// Append forceScroll to the body instead of #qunit-fixture because the latter is hidden
2121
forceScroll.appendTo( "body" );
2222
window.scrollTo( 200, 200 );
23-
window.supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
23+
supportsScroll = !!document.documentElement.scrollTop;
24+
2425
forceScroll.detach();
2526

2627
// Support: iOS <=7
@@ -369,7 +370,7 @@ testIframe( "static", "offset/static.html", function( assert, $ ) {
369370
} );
370371
} );
371372

372-
testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
373+
testIframe( "fixed", "offset/fixed.html", function( assert, $ ) {
373374
assert.expect( 38 );
374375

375376
var tests, $noTopLeft;
@@ -392,15 +393,15 @@ testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
392393
];
393394

394395
jQuery.each( tests, function() {
395-
if ( !window.supportsScroll ) {
396+
if ( !supportsScroll ) {
396397
assert.ok( true, "Browser doesn't support scroll position." );
397398
assert.ok( true, "Browser doesn't support scroll position." );
398399
assert.ok( true, "Browser doesn't support scroll position." );
399400
assert.ok( true, "Browser doesn't support scroll position." );
400401
assert.ok( true, "Browser doesn't support scroll position." );
401402
assert.ok( true, "Browser doesn't support scroll position." );
402403

403-
} else if ( window.supportsFixedPosition ) {
404+
} else if ( supportsFixedPosition ) {
404405
assert.equal( jQuery.isPlainObject( $( this.id ).offset() ), true, "jQuery('" + this.id + "').offset() is plain object" );
405406
assert.equal( jQuery.isPlainObject( $( this.id ).position() ), true, "jQuery('" + this.id + "').position() is plain object" );
406407
assert.equal( $( this.id ).offset().top, this.offsetTop, "jQuery('" + this.id + "').offset().top" );
@@ -429,7 +430,7 @@ testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
429430
];
430431

431432
jQuery.each( tests, function() {
432-
if ( window.supportsFixedPosition ) {
433+
if ( supportsFixedPosition ) {
433434
$( this.id ).offset( { "top": this.top, "left": this.left } );
434435
assert.equal( $( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
435436
assert.equal( $( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
@@ -454,7 +455,7 @@ testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
454455

455456
// Bug 8316
456457
$noTopLeft = $( "#fixed-no-top-left" );
457-
if ( window.supportsFixedPosition ) {
458+
if ( supportsFixedPosition ) {
458459
assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
459460
assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
460461
} else {
@@ -503,7 +504,7 @@ testIframe( "scroll", "offset/scroll.html", function( assert, $, win ) {
503504

504505
win.name = "test";
505506

506-
if ( !window.supportsScroll ) {
507+
if ( !supportsScroll ) {
507508
assert.ok( true, "Browser doesn't support scroll position." );
508509
assert.ok( true, "Browser doesn't support scroll position." );
509510

0 commit comments

Comments
 (0)