From f1cf2d1338ed0d5b66d79ac5d63a0437018b5e1c Mon Sep 17 00:00:00 2001
From: Dave Welsh <dw927@drexel.edu>
Date: Mon, 27 Feb 2023 21:44:18 -0500
Subject: [PATCH] Fixed a bug where images would duplicate when closing dialog
 with escape key.

---
 front_end/static/js/popup.js | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/front_end/static/js/popup.js b/front_end/static/js/popup.js
index a372452..7afff7f 100644
--- a/front_end/static/js/popup.js
+++ b/front_end/static/js/popup.js
@@ -37,4 +37,19 @@ function createNewTabLink(imageUrl) {
     button.textContent = 'View in New Tab';
     button.classList.add('dialog-button');
     return button;
-}
\ No newline at end of file
+}
+
+document.onkeydown = function(evt) {
+    evt = evt || window.event;
+    var isEscape = false;
+    if ("key" in evt) {
+        isEscape = (evt.key === "Escape" || evt.key === "Esc");
+    } else {
+        isEscape = (evt.keyCode === 27);
+    }
+    if (isEscape) {
+        while (dialog.hasChildNodes()) {
+            dialog.removeChild(dialog.firstChild);
+        }
+    }
+};
\ No newline at end of file
-- 
GitLab