diff --git a/assets/public/new.js b/assets/public/new.js new file mode 100644 index 0000000..a39ca4d --- /dev/null +++ b/assets/public/new.js @@ -0,0 +1,29 @@ +"use strict"; + +function $(id) { return document.getElementById(id) } + +function toggleButton() { $('publish-button').disabled = !$('tos').checked } + +function submitForm(token) { + var id = $("id").value; + var text = $("text").value; + var deletion = id != "" && text == ""; + if (deletion && !confirm("Do you want to delete this note?")) { + return; + } + var resp = post("/", { + "id": id, + "text": text, + "tos": $("tos").value, + "password": $("password").value, + "token": token + }, function (status, responseRaw) { + var response = JSON.parse(responseRaw); + if (status < 400 && response.Success) { + window.location.replace(deletion ? "/" : "/" + response.Payload) + } else { + grecaptcha.reset(); + $('feedback').innerHTML = status + ": " + response.Payload; + } + }) +} diff --git a/assets/templates/form.html b/assets/templates/form.html index 3a4c8a9..1342ffb 100644 --- a/assets/templates/form.html +++ b/assets/templates/form.html @@ -7,6 +7,7 @@ + @@ -30,33 +31,6 @@ source code · terms of service -