github.com/troglobit / digit

Close the branch dropdown on outside click too

Clicking outside the clone dropdown closed it, but the branch dropdown
only closed on a second click of its summary: clone.js matched only
details.clone-menu.  Match the branch menu as well.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Joachim Wiberg · 59 days ago commit 71cf00d · parent 5b981d2 · child 213b268 · patch
diff --git a/static/clone.js b/static/clone.js
index b6d3c94..6e1cbce 100644
--- a/static/clone.js
+++ b/static/clone.js
@@ -1,5 +1,5 @@
-/* Clone menu: copy buttons and close-on-outside-click.  The menu is
- * a plain <details>, so it works without JavaScript too. */
+/* Repo dropdowns (branch + clone): copy buttons and close-on-outside-
+ * click.  They are plain <details>, so they work without JavaScript too. */
 (function () {
 	"use strict";
 
@@ -18,8 +18,9 @@
 				done();
 			return;
 		}
-		var open = document.querySelector("details.clone-menu[open]");
-		if (open && !open.contains(e.target))
-			open.removeAttribute("open");
+		var opens = document.querySelectorAll("details.refmenu[open], details.clone-menu[open]");
+		for (var i = 0; i < opens.length; i++)
+			if (!opens[i].contains(e.target))
+				opens[i].removeAttribute("open");
 	});
 })();