-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Draggable: Modified to account resizable handles size in document containment mode, used by ui.dialog. Fixed #9521 ui.Dialog: Resizable dialogs move/resize out of viewport boundary - which results in scrollbar in window #1086
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,6 +396,48 @@ $.widget("ui.draggable", $.ui.mouse, { | |
}; | ||
}, | ||
|
||
_isResizableHandlersAttached: function (){ | ||
var handle; | ||
this.resizableHandle = this.resizableHandle || {}; | ||
this.resizableHandle.attached = 0; | ||
this.resizableHandle.type = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property is unnecessary. It's only used to perform an unnecessary bitwise operation on a different unnecessary property. |
||
RIGHT: 2, //E | ||
BOTTOM: 4, //S | ||
LEFT: 8, //W | ||
TOP: 16, //N | ||
TOP_LEFT: 32, //NW | ||
TOP_RIGHT: 64, //NE | ||
BOTTOM_RIGHT: 128, //SE | ||
BOTTOM_LEFT: 256, //SW | ||
ALL: 510 | ||
}; | ||
|
||
this.resizableHandle.overflow = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is unnecessary. You're redefining the object right below this. |
||
this.resizableHandle.overflow = { | ||
width: 0, | ||
height: 0 | ||
}; | ||
|
||
if ( this.element.children( " .ui-resizable-e " )[ 0 ] ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this and the two other conditionals should be able to be condensed somehow. |
||
handle = $( this.element.children( " .ui-resizable-e " )[ 0 ] ); | ||
this.resizableHandle.attached = this.resizableHandle.attached | this.resizableHandle.type.RIGHT; | ||
this.resizableHandle.overflow.width = handle.outerWidth() + ( parseInt( handle.css( "right" ), 10 ) || 0 ) ; | ||
} | ||
|
||
if ( this.element.children( " .ui-resizable-s " )[ 0 ] ){ | ||
handle = $( this.element.children( " .ui-resizable-s " )[ 0 ] ); | ||
this.resizableHandle.attached = this.resizableHandle.attached | this.resizableHandle.type.BOTTOM; | ||
this.resizableHandle.overflow.height = handle.outerHeight() + ( parseInt( handle.css( "bottom" ), 10 ) || 0 ); | ||
} | ||
|
||
if ( this.element.children( " .ui-resizable-se " )[ 0 ] ) { | ||
handle = $( this.element.children( " .ui-resizable-se " )[ 0 ] ); | ||
this.resizableHandle.attached = this.resizableHandle.attached | this.resizableHandle.type.BOTTOM_RIGHT; | ||
this.resizableHandle.overflow.width = handle.outerWidth() + ( parseInt( handle.css( "right"), 10 ) || 0 ); | ||
this.resizableHandle.overflow.height = handle.outerHeight() + ( parseInt( handle.css( "bottom" ),10 ) || 0 ); | ||
} | ||
}, | ||
|
||
_setContainment: function() { | ||
|
||
var over, c, ce, | ||
|
@@ -407,6 +449,8 @@ $.widget("ui.draggable", $.ui.mouse, { | |
return; | ||
} | ||
|
||
this._isResizableHandlersAttached(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is named awkwardly. It's not returning a Boolean, but begins with is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess i can rename it to |
||
|
||
if ( o.containment === "window" ) { | ||
this.containment = [ | ||
$( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left, | ||
|
@@ -418,12 +462,21 @@ $.widget("ui.draggable", $.ui.mouse, { | |
} | ||
|
||
if ( o.containment === "document") { | ||
this.containment = [ | ||
0, | ||
0, | ||
$( document ).width() - this.helperProportions.width - this.margins.left, | ||
( $( document ).height() || document.body.parentNode.scrollHeight ) - this.helperProportions.height - this.margins.top | ||
]; | ||
if ( this.resizableHandle.attached ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This conditional is unnecessary. |
||
this.containment = [ | ||
0, | ||
0, | ||
$( document ).width() - this.helperProportions.width - this.margins.left - this.resizableHandle.overflow.width, | ||
( $( document ).height() || document.body.parentNode.scrollHeight ) - this.helperProportions.height - this.margins.top - this.resizableHandle.overflow.height | ||
]; | ||
} else { | ||
this.containment = [ | ||
0, | ||
0, | ||
$( document ).width() - this.helperProportions.width - this.margins.left, | ||
( $( document ).height() || document.body.parentNode.scrollHeight ) - this.helperProportions.height - this.margins.top | ||
]; | ||
} | ||
return; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property is unnecessary. You're only using it in one spot, and only to avoid subtracting zero from a number.