unfuck js
This commit is contained in:
parent
d4a741127d
commit
bb4fa28f6c
1
assets/htmx@1.9.10.min.js
vendored
1
assets/htmx@1.9.10.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,12 +1,36 @@
|
||||
// TODO
|
||||
class PoemLine extends HTMLDivElement {
|
||||
constructor() {
|
||||
super();
|
||||
const ltp = document.querySelector("#linetmpl");
|
||||
var l = ltp.content.cloneNode(true);
|
||||
this.appendChild(l);
|
||||
this.addEventListener("regen", function() {
|
||||
console.log("poot");
|
||||
});
|
||||
}
|
||||
|
||||
regen() {
|
||||
fetch(new Request("/line")).then((resp) => {
|
||||
if (!resp.ok) {
|
||||
throw new Error(`sadness stalks the land in ${resp.status} ways`);
|
||||
}
|
||||
return resp.json();
|
||||
}).then((payload) => {
|
||||
this.querySelector(".linetext").innerText = payload.Text;
|
||||
this.querySelector(".linetext").setAttribute("data-source", payload.Source);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("poem-line", PoemLine, { extends: "div" });
|
||||
const regen = new Event("regen");
|
||||
|
||||
function addLine() {
|
||||
const ltp = document.querySelector("#linetmpl");
|
||||
const lines = document.querySelector("#lines");
|
||||
const l = ltp.content.cloneNode(true);
|
||||
|
||||
lines.appendChild(l);
|
||||
var ld = document.createElement("div", { is: "poem-line" });
|
||||
document.querySelector("#lines").append(ld);
|
||||
ld.regen();
|
||||
}
|
||||
|
||||
function main() {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
addLine();
|
||||
|
3
main.go
3
main.go
@ -97,7 +97,8 @@ func main() {
|
||||
}
|
||||
p.Source = s
|
||||
p.ID = id.Int64()
|
||||
c.HTML(http.StatusOK, "phrase.tmpl", p)
|
||||
//c.HTML(http.StatusOK, "phrase.tmpl", p)
|
||||
c.JSON(http.StatusOK, p)
|
||||
})
|
||||
|
||||
r.Run() // 8080
|
||||
|
@ -10,14 +10,15 @@
|
||||
</head>
|
||||
<body>
|
||||
<template id="linetmpl">
|
||||
<div class="linecontainer unpinned">
|
||||
<div class="linecontainer unpinned" hx-trigger="regen from:body" hx-swap="outerHTML" hx-get="/line">
|
||||
<span class="linecontrols">
|
||||
<button _="on click toggle .unpinned on the closest <div/>">pin</button>
|
||||
<button>edit</button>
|
||||
<button>move</button>
|
||||
<button _="on click remove the closest <div/>">remove</button>
|
||||
<button class="pin">pin</button>
|
||||
<button class"edit">edit</button>
|
||||
<button class="moveup">up</button>
|
||||
<button class="movedown">down</button>
|
||||
<button class="remove">remove</button>
|
||||
</span>
|
||||
<span hx-trigger="load" hx-swap="outerHTML" hx-get="/line" class="linetext"></span>
|
||||
<span class="linetext"></span>
|
||||
</div>
|
||||
</template>
|
||||
<h1>Trunkless</h1>
|
||||
@ -26,7 +27,7 @@
|
||||
<a id="togglescheme" href="/#togglescheme">light|dark</a>
|
||||
</div>
|
||||
<p id="poemcontrols">
|
||||
<button id="regen">regen</button>
|
||||
<button _="on click send regen to div.linecontainer.unpinned">regen</button>
|
||||
<button id="new">new</button>
|
||||
<button id="save">save</button>
|
||||
</p>
|
||||
@ -37,8 +38,6 @@
|
||||
<div>
|
||||
<button _="on click call addLine()">add</button>
|
||||
</div>
|
||||
<script src="/htmx.js"></script>
|
||||
<script src="/hyperscript.js"></script>
|
||||
<script src="/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1 +1,9 @@
|
||||
<span class="linetext" hx-get="/line" data-source="{{.Source.Name}}">{{.Text}}</span>
|
||||
<div class="linecontainer unpinned" hx-trigger="regen" hx-swap="outerHTML" hx-get="/line">
|
||||
<span class="linecontrols">
|
||||
<button>pin</button>
|
||||
<button>edit</button>
|
||||
<button>move</button>
|
||||
<button>remove</button>
|
||||
</span>
|
||||
<span class="linetext" data-source="{{.Source.Name}}">{{.Text}}</span>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user