move JS into a file

This commit is contained in:
Christian Müller
2017-09-24 00:43:58 +02:00
parent 47050985bc
commit 96d9015d08
3 changed files with 31 additions and 27 deletions
+29
View File
@@ -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;
}
})
}
+1 -27
View File
@@ -7,6 +7,7 @@
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" />
<link href="/style.css" rel="stylesheet" type="text/css" /> <link href="/style.css" rel="stylesheet" type="text/css" />
<script src='https://www.google.com/recaptcha/api.js'></script> <script src='https://www.google.com/recaptcha/api.js'></script>
<script src='/new.js'></script>
<script src='/note.js'></script> <script src='/note.js'></script>
</head> </head>
<body> <body>
@@ -30,33 +31,6 @@
<a href="https://github.com/chmllr/NoteHub">source code</a> &middot; <a href="https://github.com/chmllr/NoteHub">source code</a> &middot;
<a href="/TOS.md">terms of service</a> <a href="/TOS.md">terms of service</a>
</footer> </footer>
<script>
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;
}
})
}
</script>
<div class="g-recaptcha" <div class="g-recaptcha"
data-sitekey="6LfamjEUAAAAAANI45H3fpWG_xaSAcpYhENN4EnO" data-sitekey="6LfamjEUAAAAAANI45H3fpWG_xaSAcpYhENN4EnO"
data-callback="submitForm" data-callback="submitForm"
+1
View File
@@ -57,6 +57,7 @@ func main() {
e.File("/favicon.ico", "assets/public/favicon.ico") e.File("/favicon.ico", "assets/public/favicon.ico")
e.File("/robots.txt", "assets/public/robots.txt") e.File("/robots.txt", "assets/public/robots.txt")
e.File("/style.css", "assets/public/style.css") e.File("/style.css", "assets/public/style.css")
e.File("/new.js", "assets/public/new.js")
e.File("/note.js", "assets/public/note.js") e.File("/note.js", "assets/public/note.js")
e.File("/index.html", "assets/public/index.html") e.File("/index.html", "assets/public/index.html")
e.File("/", "assets/public/index.html") e.File("/", "assets/public/index.html")