Skip to main content

move some of the JavaScript out into a separate file, use a switch

ID
3de7e94
date
2023-05-15 19:41:19+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
1588bec
message
move some of the JavaScript out into a separate file, use a switch
changed files
3 files, 53 additions, 46 deletions

Changed files

static/reviewer.js (0) → static/reviewer.js (1179)

diff --git a/static/reviewer.js b/static/reviewer.js
new file mode 100644
index 0000000..c6d125d
--- /dev/null
+++ b/static/reviewer.js
@@ -0,0 +1,43 @@
+function httpPOST(url) {
+  var xmlHttp = null;
+
+  xmlHttp = new XMLHttpRequest();
+  xmlHttp.open("POST", url, false);
+  xmlHttp.send(null);
+  return xmlHttp.responseText;
+}
+
+function handleKeyDown(event, thisIdentifier, nextIdentifier, prevIdentifier) {
+  switch(event.key) {
+    case "ArrowLeft":
+      window.location = `/?localIdentifier=${prevIdentifier}`;
+      break;
+
+    case "ArrowRight":
+      window.location = `/?localIdentifier=${nextIdentifier}`;
+      break;
+
+    case "1":
+      window.location = `/actions?localIdentifier=${thisIdentifier}&action=toggle-approved`;
+      break;
+
+    case "2":
+      window.location = `/actions?localIdentifier=${thisIdentifier}&action=toggle-rejected`;
+      break;
+
+    case "3":
+      window.location = `/actions?localIdentifier=${thisIdentifier}&action=toggle-needs-action`;
+      break;
+
+    case "f":
+      window.location = `/actions?localIdentifier=${thisIdentifier}&action=toggle-favorite`;
+      break;
+
+    case "c":
+      window.location = `/actions?localIdentifier=${thisIdentifier}&action=toggle-cross-stitch`;
+      break;
+
+    case "o":
+      httpPOST(`/open?localIdentifier=${thisIdentifier}`);
+      break;
+  }}

static/style.css (3095) → static/style.css (3095)

diff --git a/static/style.css b/static/style.css
index b631507..cc3003e 100644
--- a/static/style.css
+++ b/static/style.css
@@ -40,7 +40,7 @@ a {
   padding-top: 1px;
   font-size: 13px;
   line-height: 16px;
-  border-top-left-radius: 6px;
+  border-top-left-radius: 4px;
   border-bottom-right-radius: 18px;
   margin-left: -3px;
   margin-top: -3px;

templates/index.html (6671) → templates/index.html (5415)

diff --git a/templates/index.html b/templates/index.html
index 576c8f6..f74ef60 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -60,52 +60,16 @@
 
 <img id="big" src="{{ url_for('image', localIdentifier=this_asset['localIdentifier']) }}">
 
-<script>
-  function httpPOST(url) {
-    var xmlHttp = null;
-
-    xmlHttp = new XMLHttpRequest();
-    xmlHttp.open("POST", url, false);
-    xmlHttp.send(null);
-    return xmlHttp.responseText;
-  }
-
-  function httpDELETE(url) {
-    var xmlHttp = null;
+<script src="/static/reviewer.js"></script>
 
-    xmlHttp = new XMLHttpRequest();
-    xmlHttp.open("DELETE", url, false);
-    xmlHttp.send(null);
-    return xmlHttp.responseText;
-  }
-
-  document.onkeydown = function(e) {
-    if (e.key === "ArrowLeft") {
-      window.location = "/?localIdentifier={{ prev_five[-1]['localIdentifier'] }}";
-    } else if (e.key === "ArrowRight") {
-      {% if next_five %}
-        window.location = "/?localIdentifier={{ next_five[0]['localIdentifier'] }}";
-      {% endif %}
-    } else
-    if (e.key === "1") {
-      window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-approved";
-    } else if (e.key === "2") {
-      window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-rejected";
-    } else if (e.key === "3") {
-      window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-needs-action";
-    }
-    else
-    if (e.key === "f") {
-      window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-favorite";
-    }
-    else
-    if (e.key === "c") {
-      window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-cross-stitch";
-    }
-    else
-    if (e.key === "o") {
-      httpPOST("/open?localIdentifier={{ this_asset['localIdentifier'] }}")
-    }
+<script>
+  document.onkeydown = function(event) {
+    return handleKeyDown(
+      event,
+      "{{ this_asset['localIdentifier'] }}",
+      {% if next_five %}"{{ next_five[0]['localIdentifier'] }}"{% else %}""{% endif %},
+      "{{ prev_five[-1]['localIdentifier'] }}",
+    )
   }
 </script>