@@ -334,6 +334,10 @@ $.widget("ui.draggable", $.ui.mouse, {
334
334
}
335
335
} ,
336
336
337
+ _isRootNode : function ( element ) {
338
+ return ( / ( h t m l | b o d y ) / i ) . test ( element . tagName ) || element === this . document [ 0 ] ;
339
+ } ,
340
+
337
341
_getParentOffset : function ( ) {
338
342
339
343
//Get the offsetParent and cache its position
@@ -349,10 +353,7 @@ $.widget("ui.draggable", $.ui.mouse, {
349
353
po . top += this . scrollParent . scrollTop ( ) ;
350
354
}
351
355
352
- //This needs to be actually done for all browsers, since pageX/pageY includes this information
353
- //Ugly IE fix
354
- if ( ( this . offsetParent [ 0 ] === document . body ) ||
355
- ( this . offsetParent [ 0 ] . tagName && this . offsetParent [ 0 ] . tagName . toLowerCase ( ) === "html" && $ . ui . ie ) ) {
356
+ if ( this . _isRootNode ( this . offsetParent [ 0 ] ) ) {
356
357
po = { top : 0 , left : 0 } ;
357
358
}
358
359
@@ -364,17 +365,18 @@ $.widget("ui.draggable", $.ui.mouse, {
364
365
} ,
365
366
366
367
_getRelativeOffset : function ( ) {
367
-
368
- if ( this . cssPosition === "relative" ) {
369
- var p = this . element . position ( ) ;
370
- return {
371
- top : p . top - ( parseInt ( this . helper . css ( "top" ) , 10 ) || 0 ) + this . scrollParent . scrollTop ( ) ,
372
- left : p . left - ( parseInt ( this . helper . css ( "left" ) , 10 ) || 0 ) + this . scrollParent . scrollLeft ( )
373
- } ;
374
- } else {
368
+ if ( this . cssPosition !== "relative" ) {
375
369
return { top : 0 , left : 0 } ;
376
370
}
377
371
372
+ var p = this . element . position ( ) ,
373
+ scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ;
374
+
375
+ return {
376
+ top : p . top - ( parseInt ( this . helper . css ( "top" ) , 10 ) || 0 ) + ( ! scrollIsRootNode ? this . scrollParent . scrollTop ( ) : 0 ) ,
377
+ left : p . left - ( parseInt ( this . helper . css ( "left" ) , 10 ) || 0 ) + ( ! scrollIsRootNode ? this . scrollParent . scrollLeft ( ) : 0 )
378
+ } ;
379
+
378
380
} ,
379
381
380
382
_cacheMargins : function ( ) {
@@ -458,31 +460,20 @@ $.widget("ui.draggable", $.ui.mouse, {
458
460
}
459
461
460
462
var mod = d === "absolute" ? 1 : - 1 ,
461
- document = this . document [ 0 ] ,
462
- useOffsetParent = this . cssPosition === "absolute" && ( this . scrollParent [ 0 ] === document || ! $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ,
463
- scroll = useOffsetParent ? this . offsetParent : this . scrollParent ,
464
- // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop
465
- // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes
466
- // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855
467
- scrollIsRootNode = useOffsetParent && ( / ( h t m l | b o d y ) / i ) . test ( scroll [ 0 ] . nodeName ) ;
468
-
469
- //Cache the scroll
470
- if ( ! this . offset . scroll ) {
471
- this . offset . scroll = { top : scroll . scrollTop ( ) , left : scroll . scrollLeft ( ) } ;
472
- }
463
+ scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ;
473
464
474
465
return {
475
466
top : (
476
467
pos . top + // The absolute mouse position
477
468
this . offset . relative . top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
478
469
this . offset . parent . top * mod - // The offsetParent's offset without borders (offset + border)
479
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) * mod )
470
+ ( ( this . cssPosition === "fixed" ? - this . offset . scroll . top : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) * mod )
480
471
) ,
481
472
left : (
482
473
pos . left + // The absolute mouse position
483
474
this . offset . relative . left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
484
475
this . offset . parent . left * mod - // The offsetParent's offset without borders (offset + border)
485
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : this . offset . scroll . left ) * mod )
476
+ ( ( this . cssPosition === "fixed" ? - this . offset . scroll . left : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) ) * mod )
486
477
)
487
478
} ;
488
479
@@ -492,19 +483,16 @@ $.widget("ui.draggable", $.ui.mouse, {
492
483
493
484
var containment , co , top , left ,
494
485
o = this . options ,
495
- document = this . document [ 0 ] ,
496
- useOffsetParent = this . cssPosition === "absolute" && ( this . scrollParent [ 0 ] === document || ! $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ,
497
- scroll = useOffsetParent ? this . offsetParent : this . scrollParent ,
498
- // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop
499
- // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes
500
- // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855
501
- scrollIsRootNode = useOffsetParent && ( / ( h t m l | b o d y ) / i ) . test ( scroll [ 0 ] . nodeName ) ,
486
+ scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ,
502
487
pageX = event . pageX ,
503
488
pageY = event . pageY ;
504
489
505
- //Cache the scroll
506
- if ( ! this . offset . scroll ) {
507
- this . offset . scroll = { top : scroll . scrollTop ( ) , left : scroll . scrollLeft ( ) } ;
490
+ // Cache the scroll
491
+ if ( ! scrollIsRootNode || ! this . offset . scroll ) {
492
+ this . offset . scroll = {
493
+ top : this . scrollParent . scrollTop ( ) ,
494
+ left : this . scrollParent . scrollLeft ( )
495
+ } ;
508
496
}
509
497
510
498
/*
@@ -566,14 +554,14 @@ $.widget("ui.draggable", $.ui.mouse, {
566
554
this . offset . click . top - // Click offset (relative to the element)
567
555
this . offset . relative . top - // Only for relative positioned nodes: Relative offset from element to offset parent
568
556
this . offset . parent . top + // The offsetParent's offset without borders (offset + border)
569
- ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) )
557
+ ( this . cssPosition === "fixed" ? - this . offset . scroll . top : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) )
570
558
) ,
571
559
left : (
572
560
pageX - // The absolute mouse position
573
561
this . offset . click . left - // Click offset (relative to the element)
574
562
this . offset . relative . left - // Only for relative positioned nodes: Relative offset from element to offset parent
575
563
this . offset . parent . left + // The offsetParent's offset without borders (offset + border)
576
- ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) )
564
+ ( this . cssPosition === "fixed" ? - this . offset . scroll . left : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) )
577
565
)
578
566
} ;
579
567
0 commit comments