From 524ab7ee1b07ca51b47bed437d377aa491949eeb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFs=20Poujade?= <lois.poujade@tetras-libre.fr>
Date: Tue, 12 Apr 2022 15:04:21 +0200
Subject: [PATCH] Check if image is present before adding annotation

---
 capsule-prototype/js/online-script.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/capsule-prototype/js/online-script.js b/capsule-prototype/js/online-script.js
index 7ec5349..6204a50 100644
--- a/capsule-prototype/js/online-script.js
+++ b/capsule-prototype/js/online-script.js
@@ -339,7 +339,10 @@ function setEditionControls() {
 	});
 
 	$("#paste_modal button.validate").click(function(event) {
-		var b64img = $("#paste_modal img")[0].src;
+		var img = $("#paste_modal img");
+		if (img.length < 1)
+			return;
+		var b64img = img[0].src;
 		var data = b64img.match(/data:([a-z]+)\/([a-z]+);base64,(.*)/);
 		var type = data[1], subtype = data[2], b64data = data[3];
 		var bin_str = atob(b64data);
-- 
GitLab