mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 07:03:35 +08:00
Revert from a while ago: always append if reference item not found
API still needs some work though
This commit is contained in:
parent
35cd1f3b51
commit
951db23ffd
|
@ -44,12 +44,18 @@ export default class ItemList {
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
var key = item.position.before || item.position.after;
|
var key = item.position.before || item.position.after;
|
||||||
var type = item.position.before ? 'before' : 'after';
|
var type = item.position.before ? 'before' : 'after';
|
||||||
|
// TODO: Allow both before and after to be specified, and multiple keys to
|
||||||
|
// be specified for each.
|
||||||
|
// e.g. {before: ['foo', 'bar'], after: ['qux', 'qaz']}
|
||||||
|
// This way extensions can make sure they are positioned where
|
||||||
|
// they want to be relative to other extensions.
|
||||||
if (key) {
|
if (key) {
|
||||||
var index = array.indexOf(this[key]);
|
var index = array.indexOf(this[key]);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
index = type === 'before' ? 0 : array.length;
|
array.push(item);
|
||||||
|
} else {
|
||||||
|
array.splice(index + (type === 'after' ? 1 : 0), 0, item);
|
||||||
}
|
}
|
||||||
array.splice(index + (type === 'after' ? 1 : 0), 0, item);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user