Skip to content

Commit ec74799

Browse files
author
Amit Gharat
committed
fix(*): Closes #83 - position issue while swapping
1 parent 92c8253 commit ec74799

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Do not pass evaluated expressions in callbacks. For example,
2222
* **onStop** – string – callback method to be invoked when dragging stops
2323
* **onDrag** – string – callback method to be invoked while the mouse is moved during the dragging
2424
* **applyFilter** - string - applies AngularJS $filter on the list before swapping items. Only applicable, if ngRepeat has any filter (such as orderBy, limitTo) associated with it.
25+
* **containment** – string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
2526
* **data-drag** – boolean – If true, element can be draggable. Disabled otherwise.
2627
* **data-jqyoui-options** – object – should hold all the valid options supported by [jQueryUI Draggable](http://api.jqueryui.com/draggable)
2728
* **ng-model** – string – An angular model defined in a controller. Should be a JS array or object
@@ -35,6 +36,7 @@ Do not pass evaluated expressions in callbacks. For example,
3536
* **onOver** – string – callback method to be invoked when an accepted draggable is dragged over the droppable
3637
* **onOut** – string – callback method to be invoked when an accepted draggable is dragged out of the droppable
3738
* **applyFilter** - string - requires if both droppable as well as draggable share the same ngModel.
39+
* **containment** – string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
3840
* **data-drop** – boolean – If true, element can be droppable. Disabled otherwise.
3941
* **data-jqyoui-options** – object – should hold all the valid options supported by [jQueryUI Droppable](http://api.jqueryui.com/droppable)
4042
* **ng-model** – string – An angular model defined in a controller. Should be a JS array or object.

src/angular-dragdrop.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
131131
}
132132

133133
var zIndex = 9999,
134-
fromPos = $fromEl.offset(),
134+
fromPos = $fromEl[dropSettings.containment || 'offset'](),
135135
wasVisible = $toEl && $toEl.is(':visible'),
136136
hadNgHideCls = $toEl.hasClass('ng-hide');
137137

138138
if (toPos === null && $toEl.length > 0) {
139139
if (($toEl.attr('jqyoui-draggable') || $toEl.attr('data-jqyoui-draggable')) !== undefined && $toEl.ngattr('ng-model') !== undefined && $toEl.is(':visible') && dropSettings && dropSettings.multiple) {
140-
toPos = $toEl.offset();
140+
toPos = $toEl[dropSettings.containment || 'offset']();
141141
if (dropSettings.stack === false) {
142142
toPos.left+= $toEl.outerWidth(true);
143143
} else {
@@ -147,7 +147,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
147147
// Angular v1.2 uses ng-hide to hide an element
148148
// so we've to remove it in order to grab its position
149149
if (hadNgHideCls) $toEl.removeClass('ng-hide');
150-
toPos = $toEl.css({'visibility': 'hidden', 'display': 'block'}).offset();
150+
toPos = $toEl.css({'visibility': 'hidden', 'display': 'block'})[dropSettings.containment || 'offset']();
151151
$toEl.css({'visibility': '','display': wasVisible ? 'block' : 'none'});
152152
}
153153
}
@@ -256,7 +256,7 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
256256
start: function(event, ui) {
257257
zIndex = angular.element(jqyouiOptions.helper ? ui.helper : this).css('z-index');
258258
angular.element(jqyouiOptions.helper ? ui.helper : this).css('z-index', 9999);
259-
jqyoui.startXY = angular.element(this).offset();
259+
jqyoui.startXY = angular.element(this)[dragSettings.containment || 'offset']();
260260
ngDragDropService.callEventCallback(scope, dragSettings.onStart, event, ui);
261261
},
262262
stop: function(event, ui) {

src/angular-dragdrop.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)