Skip to content

Commit 40c0088

Browse files
author
David Murdoch
committed
Fix visual test in IE6 and move the new helper functions for getting scrollbar properties to $.position
1 parent cde7cc0 commit 40c0088

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

tests/unit/position/position_core_within.js

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,6 @@ function scrollTopSupport() {
44
$( window ).scrollTop( 1 );
55
return $( window ).scrollTop() === 1;
66
}
7-
function getScrollbarWidth() {
8-
var div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
9-
innerDiv = div.children()[0],
10-
w1, w2;
11-
$( "body" ).append( div );
12-
w1 = innerDiv.offsetWidth;
13-
div.css( "overflow", "scroll" );
14-
15-
w2 = innerDiv.offsetWidth;
16-
17-
if ( w1 === w2 ) {
18-
w2 = div[0].clientWidth;
19-
}
20-
21-
div.remove();
22-
23-
return w1 - w2;
24-
}
25-
function getScrollInfo ( within ) {
26-
var that = within[0],
27-
scrollHeight = within.height() < that.scrollHeight,
28-
scrollWidth = within.width() < that.scrollWidth,
29-
scrollbarWidth = getScrollbarWidth();
30-
return { height : scrollHeight ? scrollbarWidth : 0, width : scrollWidth ? scrollbarWidth : 0 };
31-
};
327

338
module( "position - within", {
349
setup: function(){
@@ -301,7 +276,7 @@ test( "collision: fit, no offset", function() {
301276

302277
collisionTest({
303278
collision: "fit"
304-
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
279+
}, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
305280

306281
collisionTest2({
307282
collision: "fit"
@@ -315,7 +290,7 @@ test( "collision: fit, with offset", function() {
315290
collisionTest({
316291
collision: "fit",
317292
at: "right+2 bottom+3"
318-
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom");
293+
}, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom");
319294

320295
collisionTest2({
321296
collision: "fit",
@@ -340,7 +315,7 @@ test( "collision: fit, within scrolled", function() {
340315
collisionTest2({
341316
collision: "fit",
342317
at: "right+100 bottom+100"
343-
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
318+
}, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
344319
within.scrollTop( 0 ).scrollLeft( 0 );
345320
}
346321
});
@@ -414,7 +389,7 @@ test( "collision: fit, with margin", function() {
414389

415390
collisionTest({
416391
collision: "fit"
417-
}, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
392+
}, { top: addTop + within.height() - 20 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 20 - $.position.getScrollInfo( within ).width }, "right bottom" );
418393

419394
collisionTest2({
420395
collision: "fit"
@@ -427,7 +402,7 @@ test( "collision: fit, with margin", function() {
427402

428403
collisionTest({
429404
collision: "fit"
430-
}, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
405+
}, { top: addTop + within.height() - 20 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 20 - $.position.getScrollInfo( within ).width }, "right bottom" );
431406

432407
collisionTest2({
433408
collision: "fit"
@@ -440,7 +415,7 @@ test( "collision: fit, with margin", function() {
440415

441416
collisionTest({
442417
collision: "fit"
443-
}, { top: addTop + within.height() - 25 - getScrollInfo( within ).height, left: addLeft + within.width() - 25 - getScrollInfo( within ).width }, "right bottom" );
418+
}, { top: addTop + within.height() - 25 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 25 - $.position.getScrollInfo( within ).width }, "right bottom" );
444419

445420
collisionTest2({
446421
collision: "fit"

tests/visual/position/position_within.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@
2222
/* force scroll bar*/
2323
min-height:800px;
2424
min-width:800px;
25+
26+
/* IE6 needs this */
27+
text-align:center;
2528
}
2629
.demo-description {
2730
text-align:center;
2831
padding:1.5em;
2932
}
3033
.demo-container {
3134
background:#aaa;
32-
width:80%;
35+
width:80%;
3336
height:80%;
37+
38+
text-align:left;
3439
margin:0 auto;
3540
position:relative;
3641
padding:10px;
@@ -40,6 +45,8 @@
4045
overflow:hidden;
4146
position:relative;
4247
height:100%;
48+
/* IE6 needs this */
49+
width:100%;
4350
}
4451
#parent {
4552
width: 60%;

ui/jquery.ui.position.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ var rhorizontal = /left|center|right/,
1717
rposition = /^\w+/,
1818
rpercent = /%$/,
1919
center = "center",
20-
_position = $.fn.position,
21-
getScrollbarWidth = function() {
20+
_position = $.fn.position;
21+
22+
$.position = {
23+
scrollbarWidth : function() {
2224
var div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
2325
innerDiv = div.children()[0],
2426
w1, w2;
@@ -36,13 +38,14 @@ var rhorizontal = /left|center|right/,
3638

3739
return w1 - w2;
3840
},
39-
getScrollInfo = function( within ) {
41+
getScrollInfo : function( within ) {
4042
var that = within[0],
4143
scrollHeight = within.height() < that.scrollHeight,
4244
scrollWidth = within.width() < that.scrollWidth,
43-
scrollbarWidth = getScrollbarWidth();
45+
scrollbarWidth = $.position.scrollbarWidth();
4446
return { height : scrollHeight ? scrollbarWidth : 0, width : scrollWidth ? scrollbarWidth : 0 };
45-
};
47+
}
48+
};
4649

4750
$.fn.position = function( options ) {
4851
if ( !options || !options.of ) {
@@ -145,7 +148,7 @@ $.fn.position = function( options ) {
145148
elemHeight = elem.outerHeight(),
146149
marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0,
147150
marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0,
148-
scrollInfo = getScrollInfo( within ),
151+
scrollInfo = $.position.getScrollInfo( within ),
149152
collisionWidth = elemWidth + marginLeft +
150153
( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ) + scrollInfo.width,
151154
collisionHeight = elemHeight + marginTop +

0 commit comments

Comments
 (0)