forked from angular-ui/ui-sortable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortable.test-helper.js
More file actions
136 lines (119 loc) · 3.66 KB
/
Copy pathsortable.test-helper.js
File metadata and controls
136 lines (119 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
angular
.module('ui.sortable.testHelper', [])
.factory('sortableTestHelper', function() {
var EXTRA_DY_PERCENTAGE = 0.25;
function listContent(list, contentSelector) {
if (!contentSelector) {
contentSelector = '[ng-repeat], [data-ng-repeat], [x-ng-repeat]';
}
if (list && list.length) {
return list
.children(contentSelector)
.map(function() {
return this.innerHTML;
})
.toArray();
}
return [];
}
function listFindContent(list, contentSelector) {
if (!contentSelector) {
contentSelector = '.sortable-item';
}
if (list && list.length) {
return list
.find(contentSelector)
.map(function() {
return this.innerHTML;
})
.toArray();
}
return [];
}
function listInnerContent(list, contentSelector) {
if (!contentSelector) {
contentSelector = '.itemContent';
}
if (list && list.length) {
return list
.children()
.map(function() {
return $(this)
.find(contentSelector)
.html();
})
.toArray();
}
return [];
}
function simulateElementDrag(draggedElement, dropTarget, options) {
var dragOptions = {
dx: dropTarget.position().left - draggedElement.position().left,
dy: dropTarget.position().top - draggedElement.position().top,
moves: 30,
action: (options && options.action) || 'drag'
};
if (options === 'above') {
options = { place: 'above' };
} else if (options === 'below') {
options = { place: 'below' };
}
if (typeof options === 'object') {
if ('place' in options) {
if (options.place === 'above') {
dragOptions.dy -=
EXTRA_DY_PERCENTAGE * draggedElement.outerHeight();
} else if (options.place === 'below') {
dragOptions.dy +=
EXTRA_DY_PERCENTAGE * draggedElement.outerHeight();
}
}
if (isFinite(options.dx)) {
dragOptions.dx = options.dx;
}
if (isFinite(options.dy)) {
dragOptions.dy = options.dy;
}
if (isFinite(options.extrady)) {
dragOptions.dy += options.extrady;
}
if (isFinite(options.extradx)) {
dragOptions.dx += options.extradx;
}
if (isFinite(options.moves) && options.moves > 0) {
dragOptions.moves = options.moves;
}
}
draggedElement.simulate(dragOptions.action, dragOptions);
}
function hasUndefinedProperties(testObject) {
return (
testObject &&
Object.keys(testObject).filter(function(key) {
return (
testObject.hasOwnProperty(key) && testObject[key] !== undefined
);
}).length === 0
);
}
return {
EXTRA_DY_PERCENTAGE: EXTRA_DY_PERCENTAGE,
listContent: listContent,
listFindContent: listFindContent,
listInnerContent: listInnerContent,
simulateElementDrag: simulateElementDrag,
hasUndefinedProperties: hasUndefinedProperties,
extraElements: {
beforeLiElement: '<li>extra element</li>',
afterLiElement: '<li>extra element</li>',
beforeTrElement: '<tr><td>extra element</td></tr>',
afterTrElement: '<tr><td>extra element</td></tr>',
beforeDivElement: '<div>extra element</div>',
afterDivElement: '<div>extra element</div>'
}
};
})
.controller('dummyController', function($scope) {
$scope.testItems = ['One', 'Two', 'Three'];
});