@@ -14,6 +14,7 @@ $.ui = $.ui || {};
14
14
var horizontalPositions = / l e f t | c e n t e r | r i g h t / ,
15
15
verticalPositions = / t o p | c e n t e r | b o t t o m / ,
16
16
center = "center" ,
17
+ support = { } ,
17
18
_position = $ . fn . position ,
18
19
_offset = $ . fn . offset ;
19
20
@@ -121,9 +122,11 @@ $.fn.position = function( options ) {
121
122
position . top -= elemHeight / 2 ;
122
123
}
123
124
124
- // prevent fractions (see #5280)
125
- position . left = Math . round ( position . left ) ;
126
- position . top = Math . round ( position . top ) ;
125
+ // prevent fractions if jQuery version doesn't support them (see #5280)
126
+ if ( ! support . fractions ) {
127
+ position . left = Math . round ( position . left ) ;
128
+ position . top = Math . round ( position . top ) ;
129
+ }
127
130
128
131
collisionPosition = {
129
132
left : position . left - marginLeft ,
@@ -249,4 +252,47 @@ if ( !$.offset.setOffset ) {
249
252
} ;
250
253
}
251
254
255
+ // fraction support test (older versions of jQuery don't support fractions)
256
+ ( function ( ) {
257
+ var body = document . getElementsByTagName ( "body" ) [ 0 ] ,
258
+ div = document . createElement ( "div" ) ,
259
+ testElement , testElementParent , testElementStyle , offset , offsetTotal ;
260
+
261
+ //Create a "fake body" for testing based on method used in jQuery.support
262
+ testElement = document . createElement ( body ? "div" : "body" ) ;
263
+ testElementStyle = {
264
+ visibility : "hidden" ,
265
+ width : 0 ,
266
+ height : 0 ,
267
+ border : 0 ,
268
+ margin : 0 ,
269
+ background : "none"
270
+ } ;
271
+ if ( body ) {
272
+ jQuery . extend ( testElementStyle , {
273
+ position : "absolute" ,
274
+ left : "-1000px" ,
275
+ top : "-1000px"
276
+ } ) ;
277
+ }
278
+ for ( var i in testElementStyle ) {
279
+ testElement . style [ i ] = testElementStyle [ i ] ;
280
+ }
281
+ testElement . appendChild ( div ) ;
282
+ testElementParent = body || document . documentElement ;
283
+ testElementParent . insertBefore ( testElement , testElementParent . firstChild ) ;
284
+
285
+ div . style . cssText = "position: absolute; left: 10.7432222px; top: 10.432325px; height: 30px; width: 201px;" ;
286
+
287
+ offset = $ ( div ) . offset ( function ( _ , offset ) {
288
+ return offset ;
289
+ } ) . offset ( ) ;
290
+
291
+ testElement . innerHTML = "" ;
292
+ testElementParent . removeChild ( testElement ) ;
293
+
294
+ offsetTotal = offset . top + offset . left + ( body ? 2000 : 0 ) ;
295
+ support . fractions = offsetTotal > 21 && offsetTotal < 22 ;
296
+ } ) ( ) ;
297
+
252
298
} ( jQuery ) ) ;
0 commit comments