Skip to content

Commit 3ca32b2

Browse files
committed
Draggable: Manage ui-draggable-handle correctly in nested instances
1 parent 7594a31 commit 3ca32b2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

tests/unit/draggable/draggable_core.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,17 @@ test( "ui-draggable-handle assigned to appropriate element", function() {
291291
ok( !element.find( "p" ).hasClass( "ui-draggable-handle" ), "removed in destroy()" );
292292
});
293293

294+
test( "ui-draggable-handle managed correctly in nested draggables", function() {
295+
expect( 4 );
296+
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
297+
child = parent.find( "div" ).draggable();
298+
299+
ok( parent.hasClass( "ui-draggable-handle" ), "parent has class name on init" );
300+
ok( child.hasClass( "ui-draggable-handle" ), "child has class name on init" );
301+
302+
parent.draggable( "destroy" );
303+
ok( !parent.hasClass( "ui-draggable-handle" ), "parent loses class name on destroy" );
304+
ok( child.hasClass( "ui-draggable-handle" ), "child retains class name on destroy" );
305+
});
306+
294307
})( jQuery );

ui/draggable.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ $.widget("ui.draggable", $.ui.mouse, {
7878
_setOption: function( key, value ) {
7979
this._super( key, value );
8080
if ( key === "handle" ) {
81+
this._removeHandleClassName();
8182
this._setHandleClassName();
8283
}
8384
},
@@ -314,16 +315,13 @@ $.widget("ui.draggable", $.ui.mouse, {
314315
},
315316

316317
_setHandleClassName: function() {
317-
var handle = this.options.handle ?
318+
this.handleElement = this.options.handle ?
318319
this.element.find( this.options.handle ) : this.element;
319-
this._removeHandleClassName();
320-
handle.addClass( "ui-draggable-handle" );
320+
this.handleElement.addClass( "ui-draggable-handle" );
321321
},
322322

323323
_removeHandleClassName: function() {
324-
this.element.find( ".ui-draggable-handle" )
325-
.addBack()
326-
.removeClass( "ui-draggable-handle" );
324+
this.handleElement.removeClass( "ui-draggable-handle" );
327325
},
328326

329327
_createHelper: function(event) {

0 commit comments

Comments
 (0)