b94dba3d9b
Fix bluring keyboard on Android Fix reading messages when page was blured Fix instant reading messages if there only one page of them Split dom functions
28 lines
722 B
TypeScript
28 lines
722 B
TypeScript
/*
|
|
* https://github.com/morethanwords/tweb
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
*/
|
|
|
|
import whichChild from "./whichChild";
|
|
|
|
export default function positionElementByIndex(element: HTMLElement, container: HTMLElement, pos: number, prevPos?: number) {
|
|
if(prevPos === undefined) {
|
|
prevPos = element.parentElement === container ? whichChild(element) : -1;
|
|
}
|
|
|
|
if(prevPos === pos) {
|
|
return false;
|
|
} else if(prevPos !== -1 && prevPos < pos) { // was higher
|
|
pos += 1;
|
|
}
|
|
|
|
if(container.childElementCount > pos) {
|
|
container.insertBefore(element, container.children[pos]);
|
|
} else {
|
|
container.append(element);
|
|
}
|
|
|
|
return true;
|
|
}
|