// If the document is clicked somewhere $(document).bind("mousedown", function (e) { // If the clicked element is not the menu if ($(e.target).parents(".contextMenu").length == 0) { // Hide it despawnContextMenu(); } }); let contextMenuCloseFn = undefined; function despawnContextMenu() { let menue = $(".contextMenu"); if(!menue.is(":visible")) return; menue.hide(100); if(contextMenuCloseFn) contextMenuCloseFn(); } enum MenuEntryType { CLOSE, ENTRY, HR, EMPTY } class MenuEntry { static HR() { return { callback: () => {}, type: MenuEntryType.HR, name: "", icon: "" }; }; static EMPTY() { return { callback: () => {}, type: MenuEntryType.EMPTY, name: "", icon: "" }; }; static CLOSE(callback: () => void) { return { callback: callback, type: MenuEntryType.EMPTY, name: "", icon: "" }; } } function spawnMenu(x, y, ...entries: { callback: () => void; type: MenuEntryType; name: (() => string) | string; icon: (() => string) | string; disabled?: boolean; invalidPermission?: boolean; }[]) { const menu = $("#contextMenu"); menu.empty(); menu.hide(); contextMenuCloseFn = undefined; let index = 0; for(let entry of entries){ if(entry.type == MenuEntryType.HR) { menu.append("