Skip to content

fixes fractions handling in ui.position. #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/unit/position/position.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@ <h2 id="qunit-userAgent"></h2>
<div style="width: 50px; height: 10px;"></div>
</div>

<div id="fractions-parent" style="position: absolute; left: 10.7432222px; top: 10.532325px; height: 30px; width: 201px;">
<div id="fractions-element"></div>
</div>

</body>
</html>
44 changes: 27 additions & 17 deletions tests/unit/position/position_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,22 +417,32 @@ test( "collision: flip, with margin", function() {
}, { top: 0, left: 0 }, "right bottom" );
});

//test( "bug #5280: consistent results (avoid fractional values)", function() {
// var wrapper = $( "#bug-5280" ),
// elem = wrapper.children(),
// offset1 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset(),
// offset2 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset();
// same( offset1, offset2 );
//});
test( "fractions", function() {
$( "#fractions-element" ).position({
my: "left top",
at: "left top",
of: "#fractions-parent",
collision: "none"
});
same( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" );
});

test( "bug #5280: consistent results (avoid fractional values)", function() {
var wrapper = $( "#bug-5280" ),
elem = wrapper.children(),
offset1 = elem.position({
my: "center",
at: "center",
of: wrapper,
collision: "none"
}).offset(),
offset2 = elem.position({
my: "center",
at: "center",
of: wrapper,
collision: "none"
}).offset();
same( offset1, offset2 );
});

}( jQuery ) );
5 changes: 3 additions & 2 deletions ui/jquery.ui.position.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ $.fn.position = function( options ) {
position.left += myOffset[ 0 ];
position.top += myOffset[ 1 ];

// not required using latest jquery core (see #6000)
// prevent fractions (see #5280)
position.left = Math.round( position.left );
position.top = Math.round( position.top );
// position.left = Math.round( position.left );
// position.top = Math.round( position.top );

collisionPosition = {
left: position.left - marginLeft,
Expand Down