mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 23:53:42 +08:00
Improve ordering of list items when specified key doesn't exist
This commit is contained in:
parent
cc6113243a
commit
f667313cc2
|
@ -41,21 +41,17 @@ export default class ItemList {
|
|||
addItems('push', false);
|
||||
addItems('push', 'last');
|
||||
|
||||
items = items.filter(function(item) {
|
||||
items.forEach(item => {
|
||||
var key = item.position.before || item.position.after;
|
||||
var type = item.position.before ? 'before' : 'after';
|
||||
if (key) {
|
||||
var index = array.indexOf(this[key]);
|
||||
if (index === -1) {
|
||||
console.log("Can't find item with key '"+key+"' to insert "+type+", inserting at end instead");
|
||||
return true;
|
||||
} else {
|
||||
array.splice(array.indexOf(this[key]) + (type === 'after' ? 1 : 0), 0, item);
|
||||
index = type === 'before' ? 0 : array.length;
|
||||
}
|
||||
array.splice(index + (type === 'after' ? 1 : 0), 0, item);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
array = array.concat(items);
|
||||
});
|
||||
|
||||
return array.map((item) => item.content);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user