Files
pages/static/js/navigation.js
T
2026-05-19 21:30:42 +09:00

51 lines
1.3 KiB
JavaScript

console.log("navigation.js loaded")
function createChildPage() {
const name = prompt("child page name")
if (!name) return
let path = location.pathname
if (!path.endsWith("/")) path += "/"
location.href = "/e" + path + name
}
function selectObject(uuid) {
const input = document.getElementById("link-object-uuid")
if (input) input.value = uuid
}
async function bindPath() {
const objectUUID = document.getElementById("link-object-uuid")?.value
const path = document.getElementById("link-path")?.value
const res = await fetch("/_/api/v1/paths/bind", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({object_uuid: objectUUID, path: path}),
})
if (!res.ok) {
alert("bind failed")
return
}
location.href = path
}
document.addEventListener("keydown", (ev) => {
if (ev.target && ["TEXTAREA", "INPUT"].includes(ev.target.tagName)) return
if (ev.key === "c") location.href = "/new"
if (ev.key === "e" && !location.pathname.startsWith("/e/")) {
location.href = "/e" + location.pathname
}
if (ev.key === "^") {
const parts = location.pathname.split("/").filter(Boolean)
parts.pop()
location.href = "/" + parts.join("/")
}
})