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() {
|
function addLine() {
|
||||||
const ltp = document.querySelector("#linetmpl");
|
var ld = document.createElement("div", { is: "poem-line" });
|
||||||
const lines = document.querySelector("#lines");
|
document.querySelector("#lines").append(ld);
|
||||||
const l = ltp.content.cloneNode(true);
|
ld.regen();
|
||||||
|
|
||||||
lines.appendChild(l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
for (var i = 0; i < 10; i++) {
|
for (var i = 0; i < 10; i++) {
|
||||||
addLine();
|
addLine();
|
||||||
|
3
main.go
3
main.go
@ -97,7 +97,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
p.Source = s
|
p.Source = s
|
||||||
p.ID = id.Int64()
|
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
|
r.Run() // 8080
|
||||||
|
@ -10,14 +10,15 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<template id="linetmpl">
|
<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">
|
<span class="linecontrols">
|
||||||
<button _="on click toggle .unpinned on the closest <div/>">pin</button>
|
<button class="pin">pin</button>
|
||||||
<button>edit</button>
|
<button class"edit">edit</button>
|
||||||
<button>move</button>
|
<button class="moveup">up</button>
|
||||||
<button _="on click remove the closest <div/>">remove</button>
|
<button class="movedown">down</button>
|
||||||
|
<button class="remove">remove</button>
|
||||||
</span>
|
</span>
|
||||||
<span hx-trigger="load" hx-swap="outerHTML" hx-get="/line" class="linetext"></span>
|
<span class="linetext"></span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<h1>Trunkless</h1>
|
<h1>Trunkless</h1>
|
||||||
@ -26,7 +27,7 @@
|
|||||||
<a id="togglescheme" href="/#togglescheme">light|dark</a>
|
<a id="togglescheme" href="/#togglescheme">light|dark</a>
|
||||||
</div>
|
</div>
|
||||||
<p id="poemcontrols">
|
<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="new">new</button>
|
||||||
<button id="save">save</button>
|
<button id="save">save</button>
|
||||||
</p>
|
</p>
|
||||||
@ -37,8 +38,6 @@
|
|||||||
<div>
|
<div>
|
||||||
<button _="on click call addLine()">add</button>
|
<button _="on click call addLine()">add</button>
|
||||||
</div>
|
</div>
|
||||||
<script src="/htmx.js"></script>
|
|
||||||
<script src="/hyperscript.js"></script>
|
|
||||||
<script src="/main.js"></script>
|
<script src="/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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