Skip to content

Commit 9568866

Browse files
jeresigwycats
authored andcommitted
Mobile WebKit browsers don't support accessing the scroll position of the document/window.
1 parent dc886a8 commit 9568866

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

test/unit/offset.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module("offset");
22

3+
var supportsScroll = false;
4+
35
testoffset("absolute"/* in iframe */, function($, iframe) {
46
expect(4);
57

@@ -10,6 +12,12 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
1012
// if the offset method is using the scroll offset
1113
// of the parent window
1214
var forceScroll = jQuery('<div>', { width: 2000, height: 2000 }).appendTo('body');
15+
window.scrollTo(200, 200);
16+
17+
if ( document.documentElement.scrollTop || document.body.scrollTop ) {
18+
supportsScroll = true;
19+
}
20+
1321
window.scrollTo(1, 1);
1422

1523
// get offset
@@ -256,8 +264,13 @@ testoffset("fixed", function( jQuery ) {
256264
{ id: '#fixed-1', top: 1001, left: 1001 },
257265
{ id: '#fixed-2', top: 1021, left: 1021 }
258266
];
267+
259268
jQuery.each( tests, function() {
260-
if ( jQuery.offset.supportsFixedPosition ) {
269+
if ( !supportsScroll ) {
270+
ok( true, "Browser doesn't support scroll position." );
271+
ok( true, "Browser doesn't support scroll position." );
272+
273+
} else if ( jQuery.offset.supportsFixedPosition ) {
261274
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
262275
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
263276
} else {
@@ -335,12 +348,20 @@ testoffset("scroll", function( jQuery, win ) {
335348
// equals( jQuery('body').scrollLeft(), 0, "jQuery('body').scrollTop()" );
336349

337350
win.name = "test";
338-
339-
equals( jQuery(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
340-
equals( jQuery(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
341-
342-
equals( jQuery(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
343-
equals( jQuery(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
351+
352+
if ( !supportsScroll ) {
353+
ok( true, "Browser doesn't support scroll position." );
354+
ok( true, "Browser doesn't support scroll position." );
355+
356+
ok( true, "Browser doesn't support scroll position." );
357+
ok( true, "Browser doesn't support scroll position." );
358+
} else {
359+
equals( jQuery(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
360+
equals( jQuery(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
361+
362+
equals( jQuery(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
363+
equals( jQuery(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
364+
}
344365

345366
// test jQuery using parent window/document
346367
// jQuery reference here is in the iframe

0 commit comments

Comments
 (0)