mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
position now passes all tests! 0/
This commit is contained in:
parent
939b6989c7
commit
cf96d22532
@ -314,7 +314,7 @@ test( "collision: fit, with offset", function() {
|
|||||||
test( "collision: fit, window scrolled", function() {
|
test( "collision: fit, window scrolled", function() {
|
||||||
if ( scrollTopSupport() ) {
|
if ( scrollTopSupport() ) {
|
||||||
var win = $( window );
|
var win = $( window );
|
||||||
win.scrollTop( 300 ).scrollLeft( 200 );
|
$( window ).scrollTop( 300 ).scrollLeft( 200 );
|
||||||
collisionTest({
|
collisionTest({
|
||||||
collision: "fit",
|
collision: "fit",
|
||||||
at: "left-100 top-100"
|
at: "left-100 top-100"
|
||||||
@ -323,6 +323,7 @@ test( "collision: fit, window scrolled", function() {
|
|||||||
collision: "fit",
|
collision: "fit",
|
||||||
at: "right+100 bottom+100"
|
at: "right+100 bottom+100"
|
||||||
}, { top: 300 + win.height() - 10, left: 200 + win.width() - 10 }, "right bottom" );
|
}, { top: 300 + win.height() - 10, left: 200 + win.width() - 10 }, "right bottom" );
|
||||||
|
|
||||||
win.scrollTop( 0 ).scrollLeft( 0 );
|
win.scrollTop( 0 ).scrollLeft( 0 );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -384,7 +384,7 @@ test( "within: collision: fit, with offset", function() {
|
|||||||
}, { top: addTop + 0, left: addLeft + 0 }, "left top, negative offset" );
|
}, { top: addTop + 0, left: addLeft + 0 }, "left top, negative offset" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "within: collision: fit, window scrolled", function() {
|
test( "within: collision: fit, within scrolled", function() {
|
||||||
if ( scrollTopSupport() ) {
|
if ( scrollTopSupport() ) {
|
||||||
$("#within-container").css({"width": "1000px", "height": "800px", "top": "20px", "left": "20px", "position": "relative"});
|
$("#within-container").css({"width": "1000px", "height": "800px", "top": "20px", "left": "20px", "position": "relative"});
|
||||||
|
|
||||||
@ -396,15 +396,13 @@ test( "within: collision: fit, window scrolled", function() {
|
|||||||
collisionTest({
|
collisionTest({
|
||||||
collision: "fit",
|
collision: "fit",
|
||||||
at: "left-100 top-100"
|
at: "left-100 top-100"
|
||||||
}, { top: addTop + 300, left: addLeft + 150 }, "top left" );
|
}, { top: addTop, left: addLeft }, "top left" );
|
||||||
collisionTest2({
|
collisionTest2({
|
||||||
collision: "fit",
|
collision: "fit",
|
||||||
at: "right+100 bottom+100"
|
at: "right+100 bottom+100"
|
||||||
}, { top: addTop + 300 + win.height() + 10, left: addLeft + 150 + win.width() + 10 }, "right bottom" );
|
}, { top: addTop + win.height() - 10, left: addLeft + win.width() - 10 }, "right bottom" );
|
||||||
win.scrollTop( 0 ).scrollLeft( 0 );
|
win.scrollTop( 0 ).scrollLeft( 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "within: collision: flip, no offset", function() {
|
test( "within: collision: flip, no offset", function() {
|
||||||
|
33
ui/jquery.ui.position.js
vendored
33
ui/jquery.ui.position.js
vendored
@ -188,41 +188,45 @@ $.ui.position = {
|
|||||||
var within = data.within,
|
var within = data.within,
|
||||||
win = $( window ),
|
win = $( window ),
|
||||||
isWindow = $.isWindow( data.within[0] ),
|
isWindow = $.isWindow( data.within[0] ),
|
||||||
withinOffset = isWindow ? 0 : within.offset().left,
|
withinOffset = isWindow ? win.scrollLeft() : within.offset().left,
|
||||||
outerWidth = isWindow ? within.width() : within.outerWidth(),
|
outerWidth = isWindow ? win.width() : within.outerWidth(),
|
||||||
overLeft = - data.collisionPosition.left + withinOffset,
|
overLeft = withinOffset - data.collisionPosition.left,
|
||||||
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - withinOffset;
|
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - withinOffset,
|
||||||
|
newLeft;
|
||||||
|
|
||||||
// element is wider than window or too far left -> align with left edge
|
// element is wider than window or too far left -> align with left edge
|
||||||
if ( data.collisionWidth > outerWidth || overLeft > 0 ) {
|
if ( data.collisionWidth > outerWidth || overLeft > 0 ) {
|
||||||
position.left = position.left + overLeft;
|
newLeft = position.left + overLeft;
|
||||||
// too far right -> align with right edge
|
// too far right -> align with right edge
|
||||||
} else if ( overRight > 0 ) {
|
} else if ( overRight > 0 ) {
|
||||||
position.left = position.left - overRight;
|
newLeft = position.left - overRight;
|
||||||
// adjust based on position and margin
|
// adjust based on position and margin
|
||||||
} else {
|
} else {
|
||||||
position.left = Math.max( position.left - data.collisionPosition.left, position.left );
|
newLeft = Math.max( position.left - data.collisionPosition.left, position.left );
|
||||||
}
|
}
|
||||||
|
position.left = newLeft;
|
||||||
},
|
},
|
||||||
top: function( position, data ) {
|
top: function( position, data ) {
|
||||||
var within = data.within,
|
var within = data.within,
|
||||||
win = $( window ),
|
win = $( window ),
|
||||||
isWindow = $.isWindow( data.within[0] ),
|
isWindow = $.isWindow( data.within[0] ),
|
||||||
withinOffset = isWindow ? 0 : within.offset().top,
|
withinOffset = isWindow ? win.scrollTop() : within.offset().top,
|
||||||
outerHeight = isWindow ? within.height() : within.outerHeight(),
|
outerHeight = isWindow ? win.height() : within.outerHeight(),
|
||||||
overTop = - data.collisionPosition.top + withinOffset,
|
overTop = withinOffset - data.collisionPosition.top,
|
||||||
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - withinOffset;
|
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - withinOffset,
|
||||||
|
newTop;
|
||||||
|
|
||||||
// element is taller than window or too far up -> align with top edge
|
// element is taller than window or too far up -> align with top edge
|
||||||
if ( data.collisionHeight > outerHeight || overTop > 0 ) {
|
if ( data.collisionHeight > outerHeight || overTop > 0 ) {
|
||||||
position.top = position.top + overTop;
|
newTop = position.top + overTop;
|
||||||
// too far down -> align with bottom edge
|
// too far down -> align with bottom edge
|
||||||
} else if ( overBottom > 0 ) {
|
} else if ( overBottom > 0 ) {
|
||||||
position.top = position.top - overBottom;
|
newTop = position.top - overBottom;
|
||||||
// adjust based on position and margin
|
// adjust based on position and margin
|
||||||
} else {
|
} else {
|
||||||
position.top = Math.max( position.top - data.collisionPosition.top, position.top );
|
newTop = Math.max( position.top - data.collisionPosition.top, position.top );
|
||||||
}
|
}
|
||||||
|
position.top = newTop;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
flip: {
|
flip: {
|
||||||
@ -273,7 +277,6 @@ $.ui.position = {
|
|||||||
data.targetHeight :
|
data.targetHeight :
|
||||||
-data.targetHeight,
|
-data.targetHeight,
|
||||||
offset = -2 * data.offset[ 1 ];
|
offset = -2 * data.offset[ 1 ];
|
||||||
console.log(overBottom);
|
|
||||||
if ( overTop < 0 || overBottom > 0) {
|
if ( overTop < 0 || overBottom > 0) {
|
||||||
position.top += myOffset + atOffset + offset;
|
position.top += myOffset + atOffset + offset;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user