editor loads content
parent
6e23d9022d
commit
c2f5edead6
|
|
@ -41,6 +41,29 @@ func main() {
|
|||
"Title": "title id11",
|
||||
"PID": "id00",
|
||||
"PTitle": "title id00",
|
||||
"Content": `
|
||||
# hello
|
||||
|
||||
## world
|
||||
|
||||
| this | is | my | table |
|
||||
| ---- | ---| ---| ----- |
|
||||
| hey |
|
||||
| ya | hey | ya |
|
||||
|
||||
* and
|
||||
* a bulleted
|
||||
* list
|
||||
|
||||
> but here is a quote
|
||||
|
||||
` + "```" + `go
|
||||
// and some go code
|
||||
func main() {
|
||||
log.Println("hi")
|
||||
}
|
||||
` + "```" + `
|
||||
`,
|
||||
},
|
||||
"Tree": `{
|
||||
"Leaf": {"Title": ""},
|
||||
|
|
|
|||
|
|
@ -28,27 +28,6 @@
|
|||
}
|
||||
</style>
|
||||
<script>
|
||||
function deleteFile() {
|
||||
if (!confirm("would you like to delete this file?"))
|
||||
return
|
||||
const id = easyMDE.meta.id
|
||||
if (!id || id.length == 0)
|
||||
return
|
||||
http("DELETE", "/api/v0/files/" + id, (body, status) => {
|
||||
if (status != 200) {
|
||||
alert(`failed to delete file ${id}: ${status}: ${body}`)
|
||||
throw `failed to delete file ${id}: ${status}: ${body}`
|
||||
}
|
||||
drawTree()
|
||||
var pid = id.slice(0, id.lastIndexOf("/"))
|
||||
if (pid) {
|
||||
drawFile(pid)
|
||||
} else {
|
||||
disableMDE()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var saveFeedbackInterval = null
|
||||
function pushFile() {
|
||||
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
||||
|
|
@ -71,82 +50,6 @@
|
|||
saveFeedbackInterval = setTimeout(() => {document.getElementById("saveFeedback").innerHTML = ""}, 5000)
|
||||
}, body, headers)
|
||||
}
|
||||
|
||||
function drawFile(id) {
|
||||
if (!id || id.length < 1) {
|
||||
return
|
||||
}
|
||||
http("GET", "/api/v0/files/"+id, (body, status, headers) => {
|
||||
if (status != 200) {
|
||||
throw `ERR loading file: ${status}: ${body}`
|
||||
}
|
||||
const title = headers("title") ? headers("title") : ""
|
||||
setMDE(id, title, body)
|
||||
})
|
||||
}
|
||||
|
||||
function drawNewFile(pid) {
|
||||
setMDE(pid + "/" + crypto.randomUUID().substr(0, 5), "", "")
|
||||
if (easyMDE.isPreviewActive()) {
|
||||
easyMDE.togglePreview()
|
||||
}
|
||||
}
|
||||
|
||||
function enableMDE() {
|
||||
document.getElementById("searchResults").className = "mia";
|
||||
document.getElementById("article").className = "";
|
||||
}
|
||||
|
||||
function disableMDE() {
|
||||
document.getElementById("article").className = "mia";
|
||||
document.getElementById("searchResults").className = "";
|
||||
}
|
||||
|
||||
var liveLeafTimeout = null
|
||||
|
||||
function setMDE(id, title, body) {
|
||||
if (id[0] == "/")
|
||||
id = id.slice(1, id.length)
|
||||
if (id[id.length-1] == "/")
|
||||
id = id.slice(0, id.length-1)
|
||||
var pids = id.split("/")
|
||||
pids = pids.slice(0, pids.length-1)
|
||||
|
||||
var titlePath = "/"
|
||||
for (var i = 0; i < pids.length; i++) {
|
||||
const fullPid = pids.slice(0, i+1)
|
||||
titlePath = `/ <input type="button" class="lil_btn" value="${idsToTitle(fullPid)}" onclick="drawFile('${fullPid.join("/")}');"/> /`
|
||||
}
|
||||
if (pids.length > 1) {
|
||||
titlePath = "/ ... "+titlePath
|
||||
}
|
||||
|
||||
enableMDE()
|
||||
document.getElementById("titlePath").innerHTML = titlePath
|
||||
document.getElementById("title").innerHTML = title
|
||||
easyMDE.value(body)
|
||||
easyMDE.meta = {
|
||||
id: id,
|
||||
}
|
||||
if (!easyMDE.isPreviewActive()) {
|
||||
easyMDE.togglePreview()
|
||||
var previews = document.getElementsByClassName("preview")
|
||||
}
|
||||
const previouslyHighlighted = document.getElementsByClassName("live_leaf")
|
||||
for (var i in previouslyHighlighted)
|
||||
if (previouslyHighlighted && previouslyHighlighted[i] && previouslyHighlighted[i].classList)
|
||||
previouslyHighlighted[i].classList.remove("live_leaf")
|
||||
if (liveLeafTimeout)
|
||||
clearTimeout(liveLeafTimeout)
|
||||
liveLeafTimeout = setTimeout(() => {
|
||||
const toHighlight = document.getElementsByClassName(btoa("/"+id))
|
||||
for (var i = 0; i < toHighlight.length; i++) {
|
||||
if (toHighlight && toHighlight[i] && toHighlight[i].classList)
|
||||
toHighlight[i].classList.add("live_leaf")
|
||||
}
|
||||
}, 100)
|
||||
navigateToQuery("f", id)
|
||||
}
|
||||
</script>
|
||||
<article id="article">
|
||||
<div class="columns">
|
||||
|
|
@ -163,7 +66,7 @@
|
|||
</span>
|
||||
<span id="title" class="thic_flex" contenteditable>{{ .This.Title }}</span>
|
||||
<span class="l_buffer">
|
||||
<form action="#" onsubmit="return confirm('are you sure?') && deleteFile();"> <!-- TODO -->
|
||||
<form action="" method="delete" onsubmit="return confirm('are you sure?');"> <!-- TODO -->
|
||||
<input class="button-error lil_btn" type="submit" value="DELETE"/>
|
||||
</form>
|
||||
</span>
|
||||
|
|
@ -205,5 +108,6 @@
|
|||
},
|
||||
status: ["lines", "words", "cursor"],
|
||||
})
|
||||
easyMDE.value({{ .This.Content }})
|
||||
</script>
|
||||
{{ end }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue