anki/ts/editor/toolbar.ts
2021-02-23 12:55:04 +01:00

39 lines
1.2 KiB
TypeScript

/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
export function updateButtonState(): void {
const buts = ["bold", "italic", "underline", "superscript", "subscript"];
for (const name of buts) {
const elem = document.querySelector(`#${name}`) as HTMLElement;
elem.classList.toggle("highlighted", document.queryCommandState(name));
}
// fixme: forecolor
// 'col': document.queryCommandValue("forecolor")
}
export function preventButtonFocus(): void {
for (const element of document.querySelectorAll("button.linkb")) {
element.addEventListener("mousedown", (evt: Event) => {
evt.preventDefault();
});
}
}
export function disableButtons(): void {
$("button.linkb:not(.perm)").prop("disabled", true);
}
export function enableButtons(): void {
$("button.linkb").prop("disabled", false);
}
export function setFGButton(col: string): void {
document.getElementById("forecolor")!.style.backgroundColor = col;
}
export function toggleEditorButton(buttonid: string): void {
const button = $(buttonid)[0];
button.classList.toggle("highlighted");
}