sort annotations
This commit is contained in:
parent
9e00dd09e3
commit
c69ca372ee
2 changed files with 31 additions and 0 deletions
|
@ -129,6 +129,7 @@ async function loadData(id, args) {
|
|||
<span class="icon">${icon.down}</span>
|
||||
${layerData.title}
|
||||
</h3>`)
|
||||
data.layers[layer] = sortBy(data.layers[layer], ["+in", "+created"])
|
||||
data.layers[layer].forEach(annotation => {
|
||||
if (pandora.url) {
|
||||
annotation.value = annotation.value.replace(
|
||||
|
|
|
@ -161,3 +161,33 @@ const getVideoURL = function(id, resolution, part, track, streamId) {
|
|||
return prefix + '/' + getVideoURLName(id, resolution, part, track, streamId);
|
||||
};
|
||||
|
||||
function getSortValue(value) {
|
||||
var getSortValue = Ox.cache(function getSortValue(value) {
|
||||
var sortValue = value;
|
||||
return sortValue;
|
||||
}
|
||||
|
||||
function sortBy(array, by, map) {
|
||||
return array.sort(function(a, b) {
|
||||
var aValue, bValue, index = 0, key, ret = 0;
|
||||
while (ret == 0 && index < by.length) {
|
||||
key = by[index].key;
|
||||
aValue = getSortValue(
|
||||
map[key] ? map[key](a[key], a) : a[key]
|
||||
);
|
||||
bValue = getSortValue(
|
||||
map[key] ? map[key](b[key], b) : b[key]
|
||||
);
|
||||
if ((aValue === null) != (bValue === null)) {
|
||||
ret = aValue === null ? 1 : -1;
|
||||
} else if (aValue < bValue) {
|
||||
ret = by[index].operator == '+' ? -1 : 1;
|
||||
} else if (aValue > bValue) {
|
||||
ret = by[index].operator == '+' ? 1 : -1;
|
||||
} else {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue