@@ -76,9 +76,19 @@ $.widget("ui.draggable", $.ui.mouse, {
76
76
77
77
_mouseCapture : function ( event ) {
78
78
79
- var o = this . options ;
80
-
81
- $ ( document . activeElement ) . blur ( ) ;
79
+ var document = this . document [ 0 ] ,
80
+ o = this . options ;
81
+
82
+ // support: IE9
83
+ // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
84
+ try {
85
+ // Support: IE9+
86
+ // If the <body> is blurred, IE will switch windows, see #9520
87
+ if ( document . activeElement && document . activeElement . nodeName . toLowerCase ( ) !== "body" ) {
88
+ // Blur any element that currently has focus, see #4261
89
+ $ ( document . activeElement ) . blur ( ) ;
90
+ }
91
+ } catch ( error ) { }
82
92
83
93
// among others, prevent a drag on a resizable-handle
84
94
if ( this . helper || o . disabled || $ ( event . target ) . closest ( ".ui-resizable-handle" ) . length > 0 ) {
@@ -452,7 +462,12 @@ $.widget("ui.draggable", $.ui.mouse, {
452
462
453
463
var mod = d === "absolute" ? 1 : - 1 ,
454
464
document = this . document [ 0 ] ,
455
- scroll = this . cssPosition === "absolute" && ! ( this . scrollParent [ 0 ] !== document && $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ? this . offsetParent : this . scrollParent ;
465
+ useOffsetParent = this . cssPosition === "absolute" && ( this . scrollParent [ 0 ] === document || ! $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ,
466
+ scroll = useOffsetParent ? this . offsetParent : this . scrollParent ,
467
+ // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop
468
+ // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes
469
+ // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855
470
+ scrollIsRootNode = useOffsetParent && ( / ( h t m l | b o d y ) / i ) . test ( scroll [ 0 ] . nodeName ) ;
456
471
457
472
//Cache the scroll
458
473
if ( ! this . offset . scroll ) {
@@ -464,13 +479,13 @@ $.widget("ui.draggable", $.ui.mouse, {
464
479
pos . top + // The absolute mouse position
465
480
this . offset . relative . top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
466
481
this . offset . parent . top * mod - // The offsetParent's offset without borders (offset + border)
467
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : this . offset . scroll . top ) * mod )
482
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) * mod )
468
483
) ,
469
484
left : (
470
485
pos . left + // The absolute mouse position
471
486
this . offset . relative . left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
472
487
this . offset . parent . left * mod - // The offsetParent's offset without borders (offset + border)
473
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : this . offset . scroll . left ) * mod )
488
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : this . offset . scroll . left ) * mod )
474
489
)
475
490
} ;
476
491
@@ -481,7 +496,12 @@ $.widget("ui.draggable", $.ui.mouse, {
481
496
var containment , co , top , left ,
482
497
o = this . options ,
483
498
document = this . document [ 0 ] ,
484
- scroll = this . cssPosition === "absolute" && ! ( this . scrollParent [ 0 ] !== document && $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ? this . offsetParent : this . scrollParent ,
499
+ useOffsetParent = this . cssPosition === "absolute" && ( this . scrollParent [ 0 ] === document || ! $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ,
500
+ scroll = useOffsetParent ? this . offsetParent : this . scrollParent ,
501
+ // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop
502
+ // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes
503
+ // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855
504
+ scrollIsRootNode = useOffsetParent && ( / ( h t m l | b o d y ) / i ) . test ( scroll [ 0 ] . nodeName ) ,
485
505
pageX = event . pageX ,
486
506
pageY = event . pageY ;
487
507
@@ -542,14 +562,14 @@ $.widget("ui.draggable", $.ui.mouse, {
542
562
this . offset . click . top - // Click offset (relative to the element)
543
563
this . offset . relative . top - // Only for relative positioned nodes: Relative offset from element to offset parent
544
564
this . offset . parent . top + // The offsetParent's offset without borders (offset + border)
545
- ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : this . offset . scroll . top )
565
+ ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) )
546
566
) ,
547
567
left : (
548
568
pageX - // The absolute mouse position
549
569
this . offset . click . left - // Click offset (relative to the element)
550
570
this . offset . relative . left - // Only for relative positioned nodes: Relative offset from element to offset parent
551
571
this . offset . parent . left + // The offsetParent's offset without borders (offset + border)
552
- ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : this . offset . scroll . left )
572
+ ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) )
553
573
)
554
574
} ;
555
575
0 commit comments