Skip to content

Commit

Permalink
Remove dndDraggingSource class immediately as well as after a timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
marceljuenemann committed Dec 26, 2016
1 parent 68e5f58 commit b58a6c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions angular-drag-and-drop-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,13 @@
});

// Clean up
element.removeClass("dndDragging");
$timeout(function() { element.removeClass("dndDraggingSource"); }, 0);
dndState.isDragging = false;
element.removeClass("dndDragging");
element.removeClass("dndDraggingSource");
event.stopPropagation();

// In IE9 it is possible that the timeout from dragstart triggers after the dragend handler.
$timeout(function() { element.removeClass("dndDraggingSource"); }, 0);
});

/**
Expand Down
13 changes: 12 additions & 1 deletion test/dndDraggableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,20 @@ describe('dndDraggable', function() {

dragstart.dragend(element);
expect(element.hasClass('dndDragging')).toBe(false);
expect(element.hasClass('dndDraggingSource')).toBe(true);
expect(element.hasClass('dndDraggingSource')).toBe(false);
}));

it('removes dndDraggingSource after a timeout', inject(function($timeout) {
// IE 9 might not flush the $timeout before invoking the dragend handler.
expect(element.hasClass('dndDragging')).toBe(true);
expect(element.hasClass('dndDraggingSource')).toBe(false);

dragstart.dragend(element);
expect(element.hasClass('dndDragging')).toBe(false);
expect(element.hasClass('dndDraggingSource')).toBe(false);

$timeout.flush(0);
expect(element.hasClass('dndDragging')).toBe(false);
expect(element.hasClass('dndDraggingSource')).toBe(false);
}));

Expand Down

0 comments on commit b58a6c2

Please sign in to comment.