Skip to content

Resizable: Keep user defined handles on _setOption #1795

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions tests/unit/resizable/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,20 @@ QUnit.test( "zIndex, applied to all handles", function( assert ) {
} );

QUnit.test( "setOption handles", function( assert ) {
assert.expect( 11 );

var target = $( "<div></div>" ).resizable();

function checkHandles( expectedHandles ) {
assert.expect( 15 );

var target = $( "<div></div>" ).resizable(),
target2 = $( "<div>" +
"<div class='ui-resizable-handle ui-resizable-e'></div>" +
"<div class='ui-resizable-handle ui-resizable-w'></div>" +
"</div>" ).resizable( {
handles: {
"e": "ui-resizable-e",
"w": "ui-resizable-w"
}
} );

function checkHandles( target, expectedHandles ) {
expectedHandles = $.map( expectedHandles, function( value ) {
return ".ui-resizable-" + value;
} );
Expand All @@ -451,13 +460,16 @@ QUnit.test( "setOption handles", function( assert ) {
} );
}

checkHandles( [ "e", "s", "se" ] );
checkHandles( target, [ "e", "s", "se" ] );

target.resizable( "option", "handles", "n, w, nw" );
checkHandles( [ "n", "w", "nw" ] );
checkHandles( target, [ "n", "w", "nw" ] );

target.resizable( "option", "handles", "s, w" );
checkHandles( [ "s", "w" ] );
checkHandles( target, [ "s", "w" ] );

target2.resizable( "option", "handles", "e, s, w" );
checkHandles( target2, [ "e", "s", "w" ] );
} );

QUnit.test( "alsoResize + containment", function( assert ) {
Expand Down
8 changes: 6 additions & 2 deletions ui/widgets/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
} );

this._handles = $();
this._addedHandles = $();
if ( this.handles.constructor === String ) {

if ( this.handles === "all" ) {
Expand All @@ -269,7 +270,10 @@ $.widget( "ui.resizable", $.ui.mouse, {
axis.css( { zIndex: o.zIndex } );

this.handles[ handle ] = ".ui-resizable-" + handle;
this.element.append( axis );
if ( !this.element.children( this.handles[ handle ] ).length ) {
this.element.append( axis );
this._addedHandles = this._addedHandles.add( axis );
}
}

}
Expand Down Expand Up @@ -335,7 +339,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
},

_removeHandles: function() {
this._handles.remove();
this._addedHandles.remove();
},

_mouseCapture: function( event ) {
Expand Down