Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ uiModules
.get('app/visualize')
.directive('draggableContainer', function () {

const $scopes = new WeakMap();

return {
restrict: 'A',
scope: true,
controllerAs: 'draggableContainerCtrl',
controller($scope, $attrs, $parse) {
controller($scope, $attrs, $parse, $element) {
$scopes.set($element.get(0), $scope);
this.linkDraggableItem = (el, $scope) => {
$scopes.set(el, $scope);
};

this.getList = () => $parse($attrs.draggableContainer)($scope);
},
link($scope, $el, attr) {
const drake = dragula({
containers: $el.toArray(),
moves(el, source, handle) {
const itemScope = $(el).scope();
if (!('draggableItemCtrl' in itemScope)) {
const itemScope = $scopes.get(el);
if (!itemScope || !('draggableItemCtrl' in itemScope)) {
return; // only [draggable-item] is draggable
}
return itemScope.draggableItemCtrl.moves(handle);
Expand Down Expand Up @@ -53,21 +60,24 @@ uiModules

function markDragging(isDragging) {
return el => {
const scope = $(el).scope();
const scope = $scopes.get(el);
if (!scope) return;
scope.isDragging = isDragging;
scope.$apply();
};
}

function forwardEvent(type, el, ...args) {
const name = `drag-${prettifiedDrakeEvents[type] || type}`;
const scope = $(el).scope();
const scope = $scopes.get(el);
if (!scope) return;
scope.$broadcast(name, el, ...args);
}

function drop(el, target, source, sibling) {
const list = $scope.draggableContainerCtrl.getList();
const itemScope = $(el).scope();
const itemScope = $scopes.get(el);
if (!itemScope) return;
const item = itemScope.draggableItemCtrl.getItem();
const fromIndex = list.indexOf(item);
const siblingIndex = getItemIndexFromElement(list, sibling);
Expand All @@ -91,7 +101,8 @@ uiModules
function getItemIndexFromElement(list, element) {
if (!element) return -1;

const scope = $(element).scope();
const scope = $scopes.get(element);
if (!scope) return;
const item = scope.draggableItemCtrl.getItem();
const index = list.indexOf(item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ uiModules
return movable;
};
},
link($scope, $el, attr) {
link($scope, $el, attr, draggableController) {
draggableController.linkDraggableItem($el.get(0), $scope);
}
};
});