Inventory implementation

This commit is contained in:
2017-10-04 13:39:59 +02:00
parent 16ab79b3a8
commit 6c2782f18d
7 changed files with 250 additions and 22 deletions

View File

@ -24,4 +24,27 @@ export function canUseWebP(): boolean {
// In very old browsers (IE 8) canvas is not supported
return false
}
}
export function swapElements(a: Node, b: Node) {
let parent = b.parentNode
let bNext = b.nextSibling
// Special case for when a is the next sibling of b
if(bNext === a) {
// Just put a before b
parent.insertBefore(a, b)
} else {
// Insert b right before a
a.parentNode.insertBefore(b, a)
// Now insert a where b was
if(bNext) {
// If there was an element after b, then insert a right before that
parent.insertBefore(a, bNext)
} else {
// Otherwise just append it as the last child
parent.appendChild(a)
}
}
}