Skip to content

Commit 6ea4a06

Browse files
committed
fix(*): clone draggable and append to body before animating in order to work with absolutely positioned droppables
Closes #159 and #160
1 parent df1a58f commit 6ea4a06

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/angular-dragdrop.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
3434
this.draggableScope = null;
3535
this.droppableScope = null;
3636

37+
angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";.angular-dragdrop-hide{display: none !important;}</style>');
38+
3739
this.callEventCallback = function (scope, callbackName, event, ui) {
3840
if (!callbackName) return;
3941

@@ -75,6 +77,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
7577
$droppableDraggable = null,
7678
droppableScope = this.droppableScope,
7779
draggableScope = this.draggableScope,
80+
$helper = null,
7881
promises = [];
7982

8083
dragModel = $draggable.ngattr('ng-model');
@@ -115,11 +118,17 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
115118

116119
$q.all(promises).then(angular.bind(this, function() {
117120
if (dragSettings.animate === true) {
118-
this.move($draggable, $droppableDraggable.length > 0 ? $droppableDraggable : $droppable, null, 'fast', dropSettings, null);
121+
// be nice with absolutely positioned brethren :-)
122+
$helper = $draggable.clone();
123+
$helper.css({'position': 'absolute'}).css($draggable.offset());
124+
angular.element(document).find('body').append($helper);
125+
$draggable.addClass('angular-dragdrop-hide');
126+
127+
this.move($helper, $droppableDraggable.length > 0 ? $droppableDraggable : $droppable, null, 'fast', dropSettings, function() { $helper.remove(); });
119128
this.move($droppableDraggable.length > 0 && !dropSettings.multiple ? $droppableDraggable : [], $draggable.parent('[jqyoui-droppable],[data-jqyoui-droppable]'), jqyoui.startXY, 'fast', dropSettings, angular.bind(this, function() {
120129
$timeout(angular.bind(this, function() {
121130
// Do not move this into move() to avoid flickering issue
122-
$draggable.css({'position': 'relative', 'left': '', 'top': ''});
131+
$draggable.css({'position': 'relative', 'left': '', 'top': ''}).removeClass('angular-dragdrop-hide');
123132
// Angular v1.2 uses ng-hide to hide an element not display property
124133
// so we've to manually remove display:none set in this.move()
125134
$droppableDraggable.css({'position': 'relative', 'left': '', 'top': '', 'display': $droppableDraggable.css('display') === 'none' ? '' : $droppableDraggable.css('display')});

0 commit comments

Comments
 (0)