Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ e.g.
.as-sortable-dragging{
border: 1px dotted #000 !important;
}
- When the "as-sortable-item" can be dragged from that mouse position, the CSS class "as-sortable-item-draggable" is added to that element.


#### Callbacks:
Expand Down
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
65 changes: 51 additions & 14 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 All @@ -258,7 +260,6 @@
* moveTo: moveTo, isSameParent: isSameParent, isOrderChanged: isOrderChanged, eventArgs: eventArgs, apply: apply}}
*/
dragItem: function (item) {

return {
index: item.index(),
parent: item.sortableScope,
Expand Down Expand Up @@ -629,7 +630,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 @@ -659,10 +661,17 @@
}
});

scope.index = function () {
return scope.itemScope.$index;
};

scope.$on('$destroy', function () {
angular.element($document[0].body).unbind('keydown', escapeListen);
});

element.on('mouseenter', function(){scope.itemScope.DraggableOn();});
element.on('mouseleave', function(){scope.itemScope.DraggableOff();});

createPlaceholder = function (itemScope) {
if (typeof scope.sortableScope.options.placeholder === 'function') {
return angular.element(scope.sortableScope.options.placeholder(itemScope));
Expand Down Expand Up @@ -796,8 +805,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 +915,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 Expand Up @@ -1166,6 +1177,21 @@
}
};
}]);

mainModule.directive('noDrag', [function () {
return {
require: ['^asSortableItem', '^asSortableItemHandle'],
scope: true,
restrict: 'A',
link: function (scope, element, attrs, Controllers) {
var itemScope = Controllers[0].scope;

element.on('mouseenter', function(){itemScope.DraggableOff();});
element.on('mouseleave', function(){itemScope.DraggableOn();});

}
};
}]);
}());

/*jshint indent: 2 */
Expand Down Expand Up @@ -1232,7 +1258,18 @@
} else {
scope.modelValue = sortableController.scope.modelValue[scope.$index];
}

scope.element = element;
var isDraggable = false;
scope.DraggableOn = function(){
isDraggable = true;
element.addClass('as-sortable-item-draggable');
};
scope.DraggableOff = function(){
isDraggable = false;
element.removeClass('as-sortable-item-draggable');
};

element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-sortable.min.js

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions source/sortable-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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 @@ -186,15 +186,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 All @@ -217,7 +219,6 @@
* moveTo: moveTo, isSameParent: isSameParent, isOrderChanged: isOrderChanged, eventArgs: eventArgs, apply: apply}}
*/
dragItem: function (item) {

return {
index: item.index(),
parent: item.sortableScope,
Expand Down
31 changes: 28 additions & 3 deletions source/sortable-item-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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 @@ -103,10 +104,17 @@
}
});

scope.index = function () {
return scope.itemScope.$index;
};

scope.$on('$destroy', function () {
angular.element($document[0].body).unbind('keydown', escapeListen);
});

element.on('mouseenter', function(){scope.itemScope.DraggableOn();});
element.on('mouseleave', function(){scope.itemScope.DraggableOff();});

createPlaceholder = function (itemScope) {
if (typeof scope.sortableScope.options.placeholder === 'function') {
return angular.element(scope.sortableScope.options.placeholder(itemScope));
Expand Down Expand Up @@ -240,8 +248,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 @@ -348,7 +358,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 Expand Up @@ -610,4 +620,19 @@
}
};
}]);

mainModule.directive('noDrag', [function () {
return {
require: ['^asSortableItem', '^asSortableItemHandle'],
scope: true,
restrict: 'A',
link: function (scope, element, attrs, Controllers) {
var itemScope = Controllers[0].scope;

element.on('mouseenter', function(){itemScope.DraggableOff();});
element.on('mouseleave', function(){itemScope.DraggableOn();});

}
};
}]);
}());
11 changes: 11 additions & 0 deletions source/sortable-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@
} else {
scope.modelValue = sortableController.scope.modelValue[scope.$index];
}

scope.element = element;
var isDraggable = false;
scope.DraggableOn = function(){
isDraggable = true;
element.addClass('as-sortable-item-draggable');
};
scope.DraggableOff = function(){
isDraggable = false;
element.removeClass('as-sortable-item-draggable');
};

element.data('_scope',scope); // #144, work with angular debugInfoEnabled(false)
}
};
Expand Down