Skip to content

Commit 5fa6006

Browse files
authoredNov 29, 2016
[draggable] continue to work when debug info is disabled (#9167)
1 parent c64abe3 commit 5fa6006

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed
 

‎src/core_plugins/kibana/public/visualize/editor/draggable_container.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@ uiModules
77
.get('app/visualize')
88
.directive('draggableContainer', function () {
99

10+
const $scopes = new WeakMap();
11+
1012
return {
1113
restrict: 'A',
1214
scope: true,
1315
controllerAs: 'draggableContainerCtrl',
14-
controller($scope, $attrs, $parse) {
16+
controller($scope, $attrs, $parse, $element) {
17+
$scopes.set($element.get(0), $scope);
18+
this.linkDraggableItem = (el, $scope) => {
19+
$scopes.set(el, $scope);
20+
};
21+
1522
this.getList = () => $parse($attrs.draggableContainer)($scope);
1623
},
1724
link($scope, $el, attr) {
1825
const drake = dragula({
1926
containers: $el.toArray(),
2027
moves(el, source, handle) {
21-
const itemScope = $(el).scope();
22-
if (!('draggableItemCtrl' in itemScope)) {
28+
const itemScope = $scopes.get(el);
29+
if (!itemScope || !('draggableItemCtrl' in itemScope)) {
2330
return; // only [draggable-item] is draggable
2431
}
2532
return itemScope.draggableItemCtrl.moves(handle);
@@ -53,21 +60,24 @@ uiModules
5360

5461
function markDragging(isDragging) {
5562
return el => {
56-
const scope = $(el).scope();
63+
const scope = $scopes.get(el);
64+
if (!scope) return;
5765
scope.isDragging = isDragging;
5866
scope.$apply();
5967
};
6068
}
6169

6270
function forwardEvent(type, el, ...args) {
6371
const name = `drag-${prettifiedDrakeEvents[type] || type}`;
64-
const scope = $(el).scope();
72+
const scope = $scopes.get(el);
73+
if (!scope) return;
6574
scope.$broadcast(name, el, ...args);
6675
}
6776

6877
function drop(el, target, source, sibling) {
6978
const list = $scope.draggableContainerCtrl.getList();
70-
const itemScope = $(el).scope();
79+
const itemScope = $scopes.get(el);
80+
if (!itemScope) return;
7181
const item = itemScope.draggableItemCtrl.getItem();
7282
const fromIndex = list.indexOf(item);
7383
const siblingIndex = getItemIndexFromElement(list, sibling);
@@ -91,7 +101,8 @@ uiModules
91101
function getItemIndexFromElement(list, element) {
92102
if (!element) return -1;
93103

94-
const scope = $(element).scope();
104+
const scope = $scopes.get(element);
105+
if (!scope) return;
95106
const item = scope.draggableItemCtrl.getItem();
96107
const index = list.indexOf(item);
97108

‎src/core_plugins/kibana/public/visualize/editor/draggable_item.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ uiModules
2323
return movable;
2424
};
2525
},
26-
link($scope, $el, attr) {
26+
link($scope, $el, attr, draggableController) {
27+
draggableController.linkDraggableItem($el.get(0), $scope);
2728
}
2829
};
2930
});

0 commit comments

Comments
 (0)
Please sign in to comment.