MCPcopy Create free account
hub / github.com/arfct/itty-bitty / ShareForm

Class ShareForm

docs/bitty-menu.js:3–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import * as bitty from '/bitty.js';
2
3class ShareForm {
4 constructor() {
5
6 // element created
7 }
8
9 parse(form) {
10
11 let formData = new FormData(form);
12 let formObj = Object.fromEntries(formData);
13 console.log("DATA", formObj)
14
15 console.log("object", formObj);
16 let url = formData.get("url");
17 formData.delete("url")
18 let title = formData.get("t");
19 formData.delete("t")
20
21 if (!title.length) return;
22 let path = `/${dashspaces(title)}/`
23 let encodedFields = ["i", "v"];
24 formData.forEach((value, key) => {
25 if (!value.length) return;
26 if (encodedFields.includes(key)) value = btoa(key)
27 path += `/${key}/${value}`
28 });
29 formData.forEach((value, key) => {if (value.length) object[key] = value});
30
31 path += "#" + url;
32 console.log(path);
33 document.getElementById("rurl").value = `https://redirect.app${path}`;
34 // history.replaceState(null, path, path);
35 }
36
37 render() {
38 return el("form#share-form.flex-column",
39 el("input", {type: "image", target: "i", class: "thumbnail", onclick: "getURL(this)", src: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='600' viewBox='0 0 1200 600'%3E%%3C/svg%3E%0A"}),
40 el("div.flex-row",
41 el("div.flex-column",
42 el("input", {name: "t", oninput: this.parse, placeholder: "Title"}),
43 el("input", {name: "d", oninput: this.parse, placeholder: "Description"}),
44 el("input", {id: "i", name: "i", type: "hidden", oninput: this.parse}),
45 el("input", {id: "f", name: "i", type: "hidden", oninput: this.parse}),
46 el("input", {name: "url", oninput: this.parse, placeholder: "example.com"}),
47 el("button", {type: "sumbit", style: "display:none"}, "submit")
48 ),
49 el("input", {type: "image", src: "", id: "favicon", target: "f", onclick: "getURL(this)", oninput: this.parse, placeholder: "icon"})
50 )
51 )
52 }
53}
54
55class Menu {
56 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected