From 278d1e1108e6c12d35be9edce2a9efcab1946229 Mon Sep 17 00:00:00 2001 From: Konstantin Dinev Date: Fri, 24 Feb 2017 17:36:19 +0200 Subject: [PATCH] Resizable: Keep user defined handles on _setOption Fixes #15084 Closes gh-1795 --- tests/unit/resizable/options.js | 24 ++++++++++++++++++------ ui/widgets/resizable.js | 8 ++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/unit/resizable/options.js b/tests/unit/resizable/options.js index f89682593..4080bac0e 100644 --- a/tests/unit/resizable/options.js +++ b/tests/unit/resizable/options.js @@ -434,11 +434,20 @@ QUnit.test( "zIndex, applied to all handles", function( assert ) { } ); QUnit.test( "setOption handles", function( assert ) { - assert.expect( 11 ); + assert.expect( 15 ); - var target = $( "
" ).resizable(); + var target = $( "
" ).resizable(), + target2 = $( "
" + + "
" + + "
" + + "
" ).resizable( { + handles: { + "e": "ui-resizable-e", + "w": "ui-resizable-w" + } + } ); - function checkHandles( expectedHandles ) { + function checkHandles( target, expectedHandles ) { expectedHandles = $.map( expectedHandles, function( value ) { return ".ui-resizable-" + value; } ); @@ -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 ) { diff --git a/ui/widgets/resizable.js b/ui/widgets/resizable.js index f20bc791d..b5264ee53 100644 --- a/ui/widgets/resizable.js +++ b/ui/widgets/resizable.js @@ -250,6 +250,7 @@ $.widget( "ui.resizable", $.ui.mouse, { } ); this._handles = $(); + this._addedHandles = $(); if ( this.handles.constructor === String ) { if ( this.handles === "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 ); + } } } @@ -335,7 +339,7 @@ $.widget( "ui.resizable", $.ui.mouse, { }, _removeHandles: function() { - this._handles.remove(); + this._addedHandles.remove(); }, _mouseCapture: function( event ) {