Skip to content

Commit

Permalink
Draggable: Manage ui-draggable-handle correctly in nested instances
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvantoll committed Jul 15, 2014
1 parent 7594a31 commit 3ca32b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tests/unit/draggable/draggable_core.js
Expand Up @@ -291,4 +291,17 @@ test( "ui-draggable-handle assigned to appropriate element", function() {
ok( !element.find( "p" ).hasClass( "ui-draggable-handle" ), "removed in destroy()" );
});

test( "ui-draggable-handle managed correctly in nested draggables", function() {
expect( 4 );
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
child = parent.find( "div" ).draggable();

ok( parent.hasClass( "ui-draggable-handle" ), "parent has class name on init" );
ok( child.hasClass( "ui-draggable-handle" ), "child has class name on init" );

parent.draggable( "destroy" );
ok( !parent.hasClass( "ui-draggable-handle" ), "parent loses class name on destroy" );
ok( child.hasClass( "ui-draggable-handle" ), "child retains class name on destroy" );
});

})( jQuery );
10 changes: 4 additions & 6 deletions ui/draggable.js
Expand Up @@ -78,6 +78,7 @@ $.widget("ui.draggable", $.ui.mouse, {
_setOption: function( key, value ) {
this._super( key, value );
if ( key === "handle" ) {
this._removeHandleClassName();
this._setHandleClassName();
}
},
Expand Down Expand Up @@ -314,16 +315,13 @@ $.widget("ui.draggable", $.ui.mouse, {
},

_setHandleClassName: function() {
var handle = this.options.handle ?
this.handleElement = this.options.handle ?
this.element.find( this.options.handle ) : this.element;
this._removeHandleClassName();
handle.addClass( "ui-draggable-handle" );
this.handleElement.addClass( "ui-draggable-handle" );
},

_removeHandleClassName: function() {
this.element.find( ".ui-draggable-handle" )
.addBack()
.removeClass( "ui-draggable-handle" );
this.handleElement.removeClass( "ui-draggable-handle" );
},

_createHelper: function(event) {
Expand Down

0 comments on commit 3ca32b2

Please sign in to comment.