forked from tools/josh
1
0
Fork 0
josh/src/js/shared.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

export const asciiHeader = ` ________ _______ _ _
| ____\\ \\ / / __ \\ | | | |
| |__ \\ \\ /\\ / /| | | | ___| | _| | _____ _ __
| __| \\ \\/ \\/ / | | | |/ _ \\ |/ / |/ / _ \\ '__|
| | \\ /\\ / | |__| | __/ <| < __/ |
|_| \\/ \\/ |_____/ \\___|_|\\_\\_|\\_\\___|_| `;
export const asciiHeaderHtml = `<span class="wideScreenOnly">${asciiHeader}</span><span class="smallScreenOnly"><b><u>FWDekker</u></b></span>`;
export const emptyFunction = () => {};
export function addOnLoad(fun: () => void) {
2019-10-21 02:25:42 +02:00
const oldOnLoad = window.onload || emptyFunction;
window.onload = (() => {
2019-10-21 02:25:42 +02:00
// @ts-ignore: Call works without parameters as well
oldOnLoad();
fun();
});
}
export function moveCaretToEndOf(element: Node) {
const range = document.createRange();
range.selectNodeContents(element);
range.collapse(false);
const selection = window.getSelection();
2019-10-21 17:07:16 +02:00
if (selection !== null) {
selection.removeAllRanges();
selection.addRange(range);
}
}
2019-10-21 02:25:42 +02:00
export function q(query: string): HTMLElement {
2019-10-21 17:07:16 +02:00
const element = document.querySelector(query);
if (!(element instanceof HTMLElement))
throw "Could not find element `query`.";
return element;
}