1
0
Fork 0
forked from 0x2620/oxjs

update VideoEditor/AnnotationPanel/Editable/...; update OxJS array functions

This commit is contained in:
rlx 2012-01-04 01:11:50 +05:30
commit 85652471c6
8 changed files with 280 additions and 120 deletions

View file

@ -1409,25 +1409,33 @@ Ox.List = function(options, self) {
}
function updateSort() {
var key = self.options.sort[0].key,
map = self.options.sort[0].map,
operator = self.options.sort[0].operator,
selectedIds,
sort = {};
var length = self.options.sort.length,
operator = [],
sort = [];
//if (self.listLength > 1) {
if (!self.isAsync) {
getSelectedIds(function(selectedIds) {
self.options.items.forEach(function(item) {
sort[item.id] = map ? map(item[key], item) : item[key];
});
self.options.sort.forEach(function(v, i) {
operator.push(v.operator);
sort.push({});
self.options.items.forEach(function(item) {
sort[i][item.id] = v.map
? v.map(item[v.key], item)
: item[v.key]
});
});
self.options.items.sort(function(a, b) {
var aValue = sort[a.id],
bValue = sort[b.id],
ret = 0;
if (aValue < bValue) {
ret = operator == '+' ? -1 : 1;
} else if (aValue > bValue) {
ret = operator == '+' ? 1 : -1;
var aValue, bValue, index = 0, ret = 0;
while (ret == 0 && index < length) {
aValue = sort[index][a.id];
bValue = sort[index][b.id];
if (aValue < bValue) {
ret = operator[index] == '+' ? -1 : 1;
} else if (aValue > bValue) {
ret = operator[index] == '+' ? 1 : -1;
} else {
index++;
}
}
return ret;
});