From 698f340e185976ee9f45f96b2ebaf597b58d2209 Mon Sep 17 00:00:00 2001 From: Konstantin Dinev Date: Fri, 24 Feb 2017 17:36:19 +0200 Subject: [PATCH 1/2] Resizable: Keep user defined handles on _setOption --- tests/unit/resizable/options.js | 28 ++++++++++++++++++++-------- ui/widgets/resizable.js | 8 ++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/unit/resizable/options.js b/tests/unit/resizable/options.js index f8968259312..4080bac0e73 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 ); - - var target = $( "
" ).resizable(); - - function checkHandles( expectedHandles ) { + assert.expect( 15 ); + + var target = $( "
" ).resizable(), + target2 = $( "
" + + "
" + + "
" + + "
" ).resizable( { + handles: { + "e": "ui-resizable-e", + "w": "ui-resizable-w" + } + } ); + + 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 f20bc791d0e..b5264ee5321 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 ) { From e47dbbc7565712fe08c05b79f04ffdde86988000 Mon Sep 17 00:00:00 2001 From: Konstantin Dinev Date: Tue, 28 Feb 2017 18:21:46 +0200 Subject: [PATCH 2/2] Resizable: Updating destroy to keep user handles --- tests/unit/resizable/options.js | 10 +++++++++- ui/widgets/resizable.js | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/unit/resizable/options.js b/tests/unit/resizable/options.js index 4080bac0e73..81206abf8e8 100644 --- a/tests/unit/resizable/options.js +++ b/tests/unit/resizable/options.js @@ -434,8 +434,10 @@ QUnit.test( "zIndex, applied to all handles", function( assert ) { } ); QUnit.test( "setOption handles", function( assert ) { - assert.expect( 15 ); + assert.expect( 19 ); + // https://bugs.jqueryui.com/ticket/3423 + // https://bugs.jqueryui.com/ticket/15084 var target = $( "
" ).resizable(), target2 = $( "
" + "
" + @@ -470,6 +472,12 @@ QUnit.test( "setOption handles", function( assert ) { target2.resizable( "option", "handles", "e, s, w" ); checkHandles( target2, [ "e", "s", "w" ] ); + + target.resizable( "destroy" ); + checkHandles( target, [ ] ); + + target2.resizable( "destroy" ); + checkHandles( target2, [ "e", "w" ] ); } ); QUnit.test( "alsoResize + containment", function( assert ) { diff --git a/ui/widgets/resizable.js b/ui/widgets/resizable.js index b5264ee5321..36dd1251403 100644 --- a/ui/widgets/resizable.js +++ b/ui/widgets/resizable.js @@ -187,15 +187,14 @@ $.widget( "ui.resizable", $.ui.mouse, { _destroy: function() { this._mouseDestroy(); + this._addedHandles.remove(); var wrapper, _destroy = function( exp ) { $( exp ) .removeData( "resizable" ) .removeData( "ui-resizable" ) - .off( ".resizable" ) - .find( ".ui-resizable-handle" ) - .remove(); + .off( ".resizable" ); }; // TODO: Unwrap at same DOM position