Skip to content

Positions: added conditional suppression of position rounding #419

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 7 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
34 changes: 17 additions & 17 deletions tests/unit/position/position_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,22 @@ 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('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);
31 changes: 29 additions & 2 deletions ui/jquery.ui.position.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $.ui = $.ui || {};
var horizontalPositions = /left|center|right/,
verticalPositions = /top|center|bottom/,
center = "center",
support = {},
_position = $.fn.position,
_offset = $.fn.offset;

Expand Down Expand Up @@ -122,8 +123,10 @@ $.fn.position = function( options ) {
}

// prevent fractions (see #5280)
position.left = Math.round( position.left );
position.top = Math.round( position.top );
if (!support.fractions) {
position.left = Math.round( position.left );
position.top = Math.round( position.top );
}

collisionPosition = {
left: position.left - marginLeft,
Expand Down Expand Up @@ -249,4 +252,28 @@ if ( !$.offset.setOffset ) {
};
}

// support fractions (older versions of jquery don't support fractions)
$(function () {
var body = document.body, offset,
div = $(body.appendChild( document.createElement( "div" ) ) );

$.extend( div[0].style, {
position: 'absolute',
left: '10.2432222px',
top: '10.432325px',
height: '30px',
width: '201px'
});

offset = div.offset();
div.offset(offset);
offset = div.offset();

// set display to none to avoid a layout bug in IE
// http://dev.jquery.com/ticket/4014
body.removeChild( div[0] ).style.display = "none";

support.fractions = offset.top + offset.left > 20.0;
});

}( jQuery ));