merge fixes from pandora
This commit is contained in:
parent
7459299bf2
commit
fcf7c24c23
7 changed files with 154 additions and 91 deletions
|
|
@ -125,7 +125,10 @@ const clickLink = function(event) {
|
|||
}
|
||||
document.location.hash = '#' + link.slice(1)
|
||||
} else {
|
||||
if (!link.startsWith('/m')) {
|
||||
if (link.includes('/download/')) {
|
||||
document.location.href = link
|
||||
return
|
||||
} else if (!link.startsWith('/m')) {
|
||||
link = '/m' + link
|
||||
}
|
||||
history.pushState({}, '', link);
|
||||
|
|
@ -161,3 +164,59 @@ const getVideoURL = function(id, resolution, part, track, streamId) {
|
|||
return prefix + '/' + getVideoURLName(id, resolution, part, track, streamId);
|
||||
};
|
||||
|
||||
const getSortValue = function(value) {
|
||||
var sortValue = value;
|
||||
function trim(value) {
|
||||
return value.replace(/^\W+(?=\w)/, '');
|
||||
}
|
||||
if (
|
||||
isEmpty(value)
|
||||
|| isNull(value)
|
||||
|| isUndefined(value)
|
||||
) {
|
||||
sortValue = null;
|
||||
} else if (isString(value)) {
|
||||
// make lowercase and remove leading non-word characters
|
||||
sortValue = trim(value.toLowerCase());
|
||||
// move leading articles to the end
|
||||
// and remove leading non-word characters
|
||||
['a', 'an', 'the'].forEach(function(article) {
|
||||
if (new RegExp('^' + article + ' ').test(sortValue)) {
|
||||
sortValue = trim(sortValue.slice(article.length + 1))
|
||||
+ ', ' + sortValue.slice(0, article.length);
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
// remove thousand separators and pad numbers
|
||||
sortValue = sortValue.replace(/(\d),(?=(\d{3}))/g, '$1')
|
||||
.replace(/\d+/g, function(match) {
|
||||
return match.padStart(64, '0')
|
||||
});
|
||||
}
|
||||
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 && map[key] ? map[key](a[key], a) : a[key]
|
||||
);
|
||||
bValue = getSortValue(
|
||||
map && 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…
Add table
Add a link
Reference in a new issue