chore: clean up repo
This commit is contained in:
parent
7d93dffaed
commit
92bc424361
11 changed files with 7 additions and 900 deletions
|
@ -63,8 +63,8 @@ function get_cookie(key) {
|
|||
function check_message() {
|
||||
const element = document.getElementById("messages");
|
||||
|
||||
const message = get_cookie("Atto-Message");
|
||||
const message_good = get_cookie("Atto-Message-Good") === "true";
|
||||
const message = get_cookie("App-Message");
|
||||
const message_good = get_cookie("App-Message-Good") === "true";
|
||||
|
||||
if (message) {
|
||||
element.style.marginBottom = "1rem";
|
||||
|
@ -88,151 +88,6 @@ globalThis.show_message = (message, message_good = true) => {
|
|||
|
||||
check_message();
|
||||
|
||||
// editor
|
||||
globalThis.init_editor = (
|
||||
name = "editor",
|
||||
mode = "markdown",
|
||||
element = "editor_tab",
|
||||
content_element = "editor_content",
|
||||
) => {
|
||||
globalThis[name] = CodeMirror(document.getElementById(element), {
|
||||
value: (document.getElementById(content_element) || { innerHTML: "" })
|
||||
.innerHTML,
|
||||
mode,
|
||||
lineWrapping: true,
|
||||
lineNumbers: false,
|
||||
autoCloseBrackets: true,
|
||||
autofocus: true,
|
||||
viewportMargin: Number.POSITIVE_INFINITY,
|
||||
inputStyle: "contenteditable",
|
||||
highlightFormatting: false,
|
||||
fencedCodeBlockHighlighting: false,
|
||||
xml: false,
|
||||
smartIndent: false,
|
||||
indentUnit: 4,
|
||||
tabSize: 4,
|
||||
indentWithTabs: false,
|
||||
placeholder: "",
|
||||
extraKeys: {
|
||||
Home: "goLineLeft",
|
||||
End: "goLineRight",
|
||||
Enter: (cm) => {
|
||||
cm.replaceSelection("\n");
|
||||
},
|
||||
Tab: "insertSoftTab",
|
||||
},
|
||||
});
|
||||
|
||||
if (name === "editor") {
|
||||
window.addEventListener("beforeunload", (e) => {
|
||||
if (!globalThis.ALLOW_LEAVE) {
|
||||
e.preventDefault();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
globalThis.tab_editor = () => {
|
||||
document.getElementById("editor_tab").classList.remove("hidden");
|
||||
document.getElementById("preview_tab").classList.add("hidden");
|
||||
document.getElementById("metadata_tab").classList.add("hidden");
|
||||
|
||||
document.getElementById("editor_tab_button").classList.remove("camo");
|
||||
document.getElementById("preview_tab_button").classList.add("camo");
|
||||
document.getElementById("metadata_tab_button").classList.add("camo");
|
||||
|
||||
if (document.getElementById("metadata_css")) {
|
||||
document.getElementById("metadata_css").remove();
|
||||
}
|
||||
};
|
||||
|
||||
globalThis.get_preview = async () => {
|
||||
return await (
|
||||
await fetch("/api/v1/render", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
content: globalThis.editor.getValue(),
|
||||
metadata: globalThis.metadata_editor.getValue(),
|
||||
}),
|
||||
})
|
||||
).text();
|
||||
};
|
||||
|
||||
globalThis.tab_preview = async () => {
|
||||
if (
|
||||
!document
|
||||
.getElementById("preview_tab_button")
|
||||
.classList.contains("camo")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// render
|
||||
const res = await get_preview();
|
||||
|
||||
document.getElementById("preview_tab").innerHTML = res;
|
||||
hljs.highlightAll();
|
||||
|
||||
// ...
|
||||
document.getElementById("editor_tab").classList.add("hidden");
|
||||
document.getElementById("preview_tab").classList.remove("hidden");
|
||||
document.getElementById("metadata_tab").classList.add("hidden");
|
||||
|
||||
document.getElementById("editor_tab_button").classList.add("camo");
|
||||
document.getElementById("preview_tab_button").classList.remove("camo");
|
||||
document.getElementById("metadata_tab_button").classList.add("camo");
|
||||
};
|
||||
|
||||
globalThis.first_time_on_metadata_tab = true;
|
||||
globalThis.tab_metadata = () => {
|
||||
document.getElementById("editor_tab").classList.add("hidden");
|
||||
document.getElementById("preview_tab").classList.add("hidden");
|
||||
document.getElementById("metadata_tab").classList.remove("hidden");
|
||||
|
||||
document.getElementById("editor_tab_button").classList.add("camo");
|
||||
document.getElementById("preview_tab_button").classList.add("camo");
|
||||
document.getElementById("metadata_tab_button").classList.remove("camo");
|
||||
|
||||
if (globalThis.first_time_on_metadata_tab) {
|
||||
globalThis.metadata_editor.refresh();
|
||||
}
|
||||
|
||||
globalThis.first_time_on_metadata_tab = false;
|
||||
};
|
||||
|
||||
let exists_timeout = null;
|
||||
globalThis.check_exists_input = (e) => {
|
||||
if (exists_timeout) {
|
||||
clearTimeout(exists_timeout);
|
||||
}
|
||||
|
||||
exists_timeout = setTimeout(async () => {
|
||||
if (e.target.value.length < 2 || e.target.value.length > 32) {
|
||||
e.target.setCustomValidity("");
|
||||
e.target.removeAttribute("data-invalid");
|
||||
e.target.reportValidity();
|
||||
return;
|
||||
}
|
||||
|
||||
const exists = (
|
||||
await (await fetch(`/api/v1/entries/${e.target.value}`)).json()
|
||||
).payload;
|
||||
|
||||
console.log(exists);
|
||||
if (exists) {
|
||||
e.target.setCustomValidity("Slug is already in use");
|
||||
e.target.setAttribute("data-invalid", "true");
|
||||
} else {
|
||||
e.target.setCustomValidity("");
|
||||
e.target.removeAttribute("data-invalid");
|
||||
}
|
||||
|
||||
e.target.reportValidity();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// components
|
||||
function close_dropdowns() {
|
||||
for (const dropdown of Array.from(
|
||||
|
@ -314,46 +169,6 @@ globalThis.init_dropdowns = (bind_to) => {
|
|||
});
|
||||
};
|
||||
|
||||
globalThis.METADATA_CSS_ENABLED = true;
|
||||
globalThis.toggle_metadata_css = (e) => {
|
||||
e.target.classList.add("yellow");
|
||||
|
||||
METADATA_CSS_ENABLED = !METADATA_CSS_ENABLED;
|
||||
if (!METADATA_CSS_ENABLED) {
|
||||
media_theme_pref(); // user user theme
|
||||
document.getElementById("metadata_css").remove(); // remove css
|
||||
|
||||
// reset colored text
|
||||
for (const element of Array.from(
|
||||
document.querySelectorAll("#content_rect .color_block"),
|
||||
)) {
|
||||
element.removeAttribute("style");
|
||||
element.classList.remove("color_block");
|
||||
}
|
||||
|
||||
// strikethrough auto theme since it's disabled
|
||||
if (document.getElementById("auto_theme")) {
|
||||
document.getElementById("auto_theme").style.textDecoration =
|
||||
"line-through";
|
||||
}
|
||||
|
||||
// remove styles
|
||||
for (const element of Array.from(
|
||||
document.querySelectorAll("#content_rect style"),
|
||||
)) {
|
||||
element.remove();
|
||||
}
|
||||
|
||||
for (const element of Array.from(
|
||||
document.querySelectorAll("#content_rect [style]"),
|
||||
)) {
|
||||
element.removeAttribute("style");
|
||||
}
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
globalThis.hash_check = (hash) => {
|
||||
if (hash.startsWith("#/")) {
|
||||
for (const x of Array.from(document.querySelectorAll(".subpage"))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue