Skip to main content

max / makenotwork

489 B · 11 lines History Blame Raw
1 function toggleContextMenu(event, itemId) {
2 event.stopPropagation();
3 var menu = document.getElementById('menu-' + itemId);
4 var wasOpen = menu.classList.contains('open');
5 document.querySelectorAll('.context-menu').forEach(function(m) { m.classList.remove('open'); });
6 if (!wasOpen) { menu.classList.add('open'); }
7 }
8 document.addEventListener('click', function(e) {
9 document.querySelectorAll('.context-menu').forEach(function(m) { m.classList.remove('open'); });
10 });
11