@@ -156,9 +156,7 @@ $.widget("ui.draggable", $.ui.mouse, {
156
156
( o . cursorAt && this . _adjustOffsetFromHelper ( o . cursorAt ) ) ;
157
157
158
158
//Set a containment if given in the options
159
- if ( o . containment ) {
160
- this . _setContainment ( ) ;
161
- }
159
+ this . _setContainment ( ) ;
162
160
163
161
//Trigger event + callbacks
164
162
if ( this . _trigger ( "start" , event ) === false ) {
@@ -383,40 +381,56 @@ $.widget("ui.draggable", $.ui.mouse, {
383
381
var over , c , ce ,
384
382
o = this . options ;
385
383
386
- if ( o . containment === "parent" ) {
387
- o . containment = this . helper [ 0 ] . parentNode ;
384
+ if ( ! o . containment ) {
385
+ this . containment = null ;
386
+ return ;
388
387
}
389
- if ( o . containment === "document" || o . containment === "window" ) {
388
+
389
+ if ( o . containment === "window" ) {
390
390
this . containment = [
391
- o . containment === "document" ? 0 : $ ( window ) . scrollLeft ( ) - this . offset . relative . left - this . offset . parent . left ,
392
- o . containment === "document" ? 0 : $ ( window ) . scrollTop ( ) - this . offset . relative . top - this . offset . parent . top ,
393
- ( o . containment === "document" ? 0 : $ ( window ) . scrollLeft ( ) ) + $ ( o . containment === "document" ? document : window ) . width ( ) - this . helperProportions . width - this . margins . left ,
394
- ( o . containment === "document" ? 0 : $ ( window ) . scrollTop ( ) ) + ( $ ( o . containment === "document" ? document : window ) . height ( ) || document . body . parentNode . scrollHeight ) - this . helperProportions . height - this . margins . top
391
+ $ ( window ) . scrollLeft ( ) - this . offset . relative . left - this . offset . parent . left ,
392
+ $ ( window ) . scrollTop ( ) - this . offset . relative . top - this . offset . parent . top ,
393
+ $ ( window ) . scrollLeft ( ) + $ ( window ) . width ( ) - this . helperProportions . width - this . margins . left ,
394
+ $ ( window ) . scrollTop ( ) + ( $ ( window ) . height ( ) || document . body . parentNode . scrollHeight ) - this . helperProportions . height - this . margins . top
395
395
] ;
396
+ return ;
396
397
}
397
398
398
- if ( ! ( / ^ ( d o c u m e n t | w i n d o w | p a r e n t ) $ / ) . test ( o . containment ) && o . containment . constructor !== Array ) {
399
- c = $ ( o . containment ) ;
400
- ce = c [ 0 ] ;
401
-
402
- if ( ! ce ) {
403
- return ;
404
- }
405
-
406
- over = ( $ ( ce ) . css ( "overflow" ) !== "hidden" ) ;
407
-
399
+ if ( o . containment === "document" ) {
408
400
this . containment = [
409
- ( parseInt ( $ ( ce ) . css ( "borderLeftWidth" ) , 10 ) || 0 ) + ( parseInt ( $ ( ce ) . css ( "paddingLeft" ) , 10 ) || 0 ) ,
410
- ( parseInt ( $ ( ce ) . css ( "borderTopWidth" ) , 10 ) || 0 ) + ( parseInt ( $ ( ce ) . css ( "paddingTop" ) , 10 ) || 0 ) ,
411
- ( over ? Math . max ( ce . scrollWidth , ce . offsetWidth ) : ce . offsetWidth ) - ( parseInt ( $ ( ce ) . css ( "borderRightWidth" ) , 10 ) || 0 ) - ( parseInt ( $ ( ce ) . css ( "paddingRight" ) , 10 ) || 0 ) - this . helperProportions . width - this . margins . left - this . margins . right ,
412
- ( over ? Math . max ( ce . scrollHeight , ce . offsetHeight ) : ce . offsetHeight ) - ( parseInt ( $ ( ce ) . css ( "borderBottomWidth" ) , 10 ) || 0 ) - ( parseInt ( $ ( ce ) . css ( "paddingBottom" ) , 10 ) || 0 ) - this . helperProportions . height - this . margins . top - this . margins . bottom
401
+ 0 ,
402
+ 0 ,
403
+ $ ( document ) . width ( ) - this . helperProportions . width - this . margins . left ,
404
+ ( $ ( document ) . height ( ) || document . body . parentNode . scrollHeight ) - this . helperProportions . height - this . margins . top
413
405
] ;
414
- this . relative_container = c ;
406
+ return ;
407
+ }
415
408
416
- } else if ( o . containment . constructor === Array ) {
409
+ if ( o . containment . constructor === Array ) {
417
410
this . containment = o . containment ;
411
+ return ;
412
+ }
413
+
414
+ if ( o . containment === "parent" ) {
415
+ o . containment = this . helper [ 0 ] . parentNode ;
418
416
}
419
417
418
+ c = $ ( o . containment ) ;
419
+ ce = c [ 0 ] ;
420
+
421
+ if ( ! ce ) {
422
+ return ;
423
+ }
424
+
425
+ over = c . css ( "overflow" ) !== "hidden" ;
426
+
427
+ this . containment = [
428
+ ( parseInt ( c . css ( "borderLeftWidth" ) , 10 ) || 0 ) + ( parseInt ( c . css ( "paddingLeft" ) , 10 ) || 0 ) ,
429
+ ( parseInt ( c . css ( "borderTopWidth" ) , 10 ) || 0 ) + ( parseInt ( c . css ( "paddingTop" ) , 10 ) || 0 ) ,
430
+ ( over ? Math . max ( ce . scrollWidth , ce . offsetWidth ) : ce . offsetWidth ) - ( parseInt ( c . css ( "borderRightWidth" ) , 10 ) || 0 ) - ( parseInt ( c . css ( "paddingRight" ) , 10 ) || 0 ) - this . helperProportions . width - this . margins . left - this . margins . right ,
431
+ ( over ? Math . max ( ce . scrollHeight , ce . offsetHeight ) : ce . offsetHeight ) - ( parseInt ( c . css ( "borderBottomWidth" ) , 10 ) || 0 ) - ( parseInt ( c . css ( "paddingBottom" ) , 10 ) || 0 ) - this . helperProportions . height - this . margins . top - this . margins . bottom
432
+ ] ;
433
+ this . relative_container = c ;
420
434
} ,
421
435
422
436
_convertPositionTo : function ( d , pos ) {
@@ -469,18 +483,21 @@ $.widget("ui.draggable", $.ui.mouse, {
469
483
* Constrain the position to a mix of grid, containment.
470
484
*/
471
485
472
- if ( this . originalPosition ) { //If we are not dragging yet, we won't check for options
473
- if ( this . containment ) {
474
- if ( this . relative_container ) {
475
- co = this . relative_container . offset ( ) ;
476
- containment = [ this . containment [ 0 ] + co . left ,
477
- this . containment [ 1 ] + co . top ,
478
- this . containment [ 2 ] + co . left ,
479
- this . containment [ 3 ] + co . top ] ;
480
- }
481
- else {
482
- containment = this . containment ;
483
- }
486
+ // If we are not dragging yet, we won't check for options
487
+ if ( this . originalPosition ) {
488
+ if ( this . containment ) {
489
+ if ( this . relative_container ) {
490
+ co = this . relative_container . offset ( ) ;
491
+ containment = [
492
+ this . containment [ 0 ] + co . left ,
493
+ this . containment [ 1 ] + co . top ,
494
+ this . containment [ 2 ] + co . left ,
495
+ this . containment [ 3 ] + co . top
496
+ ] ;
497
+ }
498
+ else {
499
+ containment = this . containment ;
500
+ }
484
501
485
502
if ( event . pageX - this . offset . click . left < containment [ 0 ] ) {
486
503
pageX = containment [ 0 ] + this . offset . click . left ;
0 commit comments