Skip to content

added overflowContainment option #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion demo/scripts/controllers/KanbanController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ angular.module('demoApp').controller('KanbanController', ['$scope', 'BoardServic
},
orderChanged: function (event) {
},
containment: '#board'
containment: '#board',
allowOverflow: true
};

$scope.removeCard = function (column, card) {
Expand Down
31 changes: 18 additions & 13 deletions dist/ng-sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
* @param containerPositioning - absolute or relative positioning.
* @param {Object} [scrollableContainer] (optional) Scrollable container object
*/
movePosition: function (event, element, pos, container, containerPositioning, scrollableContainer) {
movePosition: function (event, element, pos, container, containerPositioning, scrollableContainer, allowOverflow) {
var bounds;
var useRelative = (containerPositioning === 'relative');

Expand All @@ -227,15 +227,17 @@
bounds.top = 0;
}

if (element.x < bounds.left) {
element.x = bounds.left;
} else if (element.x >= bounds.width + bounds.left - this.offset(element).width) {
element.x = bounds.width + bounds.left - this.offset(element).width;
}
if (element.y < bounds.top) {
element.y = bounds.top;
} else if (element.y >= bounds.height + bounds.top - this.offset(element).height) {
element.y = bounds.height + bounds.top - this.offset(element).height;
if(!allowOverflow){
if (element.x < bounds.left) {
element.x = bounds.left;
} else if (element.x >= bounds.width + bounds.left - this.offset(element).width) {
element.x = bounds.width + bounds.left - this.offset(element).width;
}
if (element.y < bounds.top) {
element.y = bounds.top;
} else if (element.y >= bounds.height + bounds.top - this.offset(element).height) {
element.y = bounds.height + bounds.top - this.offset(element).height;
}
}
}

Expand Down Expand Up @@ -629,7 +631,8 @@
isPlaceHolderPresent,//is placeholder present.
isDisabled = false, // drag enabled
escapeListen, // escape listen event
isLongTouch = false; //long touch disabled.
isLongTouch = false, //long touch disabled.
allowOverflow; //allow dragged element to overflow containment

hasTouch = 'ontouchstart' in $window;
isIOS = /iPad|iPhone|iPod/.test($window.navigator.userAgent) && !$window.MSStream;
Expand Down Expand Up @@ -796,8 +799,10 @@
dragElement.append(scope.itemScope.element);
}

allowOverflow = !!scope.sortableScope.options.allowOverflow;

containment.append(dragElement);
$helper.movePosition(eventObj, dragElement, itemPosition, containment, containerPositioning, scrollableContainer);
$helper.movePosition(eventObj, dragElement, itemPosition, containment, containerPositioning, scrollableContainer, allowOverflow);

scope.sortableScope.$apply(function () {
scope.callbacks.dragStart(dragItemInfo.eventArgs());
Expand Down Expand Up @@ -904,7 +909,7 @@
targetElement = angular.element($document[0].elementFromPoint(targetX, targetY));
dragElement.removeClass(sortableConfig.hiddenClass);

$helper.movePosition(eventObj, dragElement, itemPosition, containment, containerPositioning, scrollableContainer);
$helper.movePosition(eventObj, dragElement, itemPosition, containment, containerPositioning, scrollableContainer, allowOverflow);

//Set Class as dragging starts
dragElement.addClass(sortableConfig.dragging);
Expand Down
Loading