Skip to content

Commit cde7cc0

Browse files
author
David Murdoch
committed
updated tests to account for scrollbar width/height
1 parent c11ac9c commit cde7cc0

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

tests/unit/position/position_core_within.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ 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+
};
732

833
module( "position - within", {
934
setup: function(){
@@ -276,7 +301,7 @@ test( "collision: fit, no offset", function() {
276301

277302
collisionTest({
278303
collision: "fit"
279-
}, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom" );
304+
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
280305

281306
collisionTest2({
282307
collision: "fit"
@@ -290,7 +315,7 @@ test( "collision: fit, with offset", function() {
290315
collisionTest({
291316
collision: "fit",
292317
at: "right+2 bottom+3"
293-
}, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom");
318+
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom");
294319

295320
collisionTest2({
296321
collision: "fit",
@@ -315,7 +340,7 @@ test( "collision: fit, within scrolled", function() {
315340
collisionTest2({
316341
collision: "fit",
317342
at: "right+100 bottom+100"
318-
}, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom" );
343+
}, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
319344
within.scrollTop( 0 ).scrollLeft( 0 );
320345
}
321346
});
@@ -389,7 +414,7 @@ test( "collision: fit, with margin", function() {
389414

390415
collisionTest({
391416
collision: "fit"
392-
}, { top: addTop + within.height() - 20, left: addLeft + within.width() - 20 }, "right bottom" );
417+
}, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
393418

394419
collisionTest2({
395420
collision: "fit"
@@ -402,7 +427,7 @@ test( "collision: fit, with margin", function() {
402427

403428
collisionTest({
404429
collision: "fit"
405-
}, { top: addTop + within.height() - 20, left: addLeft + within.width() - 20 }, "right bottom" );
430+
}, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
406431

407432
collisionTest2({
408433
collision: "fit"
@@ -415,7 +440,7 @@ test( "collision: fit, with margin", function() {
415440

416441
collisionTest({
417442
collision: "fit"
418-
}, { top: addTop + within.height() - 25, left: addLeft + within.width() - 25 }, "right bottom" );
443+
}, { top: addTop + within.height() - 25 - getScrollInfo( within ).height, left: addLeft + within.width() - 25 - getScrollInfo( within ).width }, "right bottom" );
419444

420445
collisionTest2({
421446
collision: "fit"

ui/jquery.ui.position.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ $.fn.position = function( options ) {
139139
basePosition.left += atOffset[ 0 ];
140140
basePosition.top += atOffset[ 1 ];
141141

142-
return this.each(function() { console.log(getScrollInfo( within ));
142+
return this.each(function() {
143143
var elem = $( this ),
144144
elemWidth = elem.outerWidth(),
145145
elemHeight = elem.outerHeight(),

0 commit comments

Comments
 (0)