Add support for disabled context menu items through puter.js

This commit is contained in:
Nariman Jelveh 2024-06-16 20:18:11 -07:00
parent 04adade80e
commit ccf6ebef4d
2 changed files with 9 additions and 1 deletions

View File

@ -426,6 +426,7 @@ window.addEventListener('message', async (event) => {
html: item.label, html: item.label,
icon: item.icon ? `<img style="width: 15px; height: 15px; position: absolute; top: 4px; left: 6px;" src="${html_encode(item.icon)}" />` : undefined, icon: item.icon ? `<img style="width: 15px; height: 15px; position: absolute; top: 4px; left: 6px;" src="${html_encode(item.icon)}" />` : undefined,
icon_active: item.icon_active ? `<img style="width: 15px; height: 15px; position: absolute; top: 4px; left: 6px;" src="${html_encode(item.icon_active)}" />` : undefined, icon_active: item.icon_active ? `<img style="width: 15px; height: 15px; position: absolute; top: 4px; left: 6px;" src="${html_encode(item.icon_active)}" />` : undefined,
disabled: item.disabled,
onClick: () => { onClick: () => {
if (item.action !== undefined) { if (item.action !== undefined) {
item.action(); item.action();

View File

@ -261,7 +261,14 @@ function UIContextMenu(options){
} }
}); });
// Useful in cases such as where a menu item is over a window, this prevents from the mousedown event // disabled item mousedown event
$(`#context-menu-${menu_id} > li.context-menu-item-disabled`).on('mousedown', function (e) {
e.preventDefault();
e.stopPropagation();
return false;
})
// Useful in cases such as where a menu item is over a window, this prevents the mousedown event from
// reaching the window underneath // reaching the window underneath
$(`#context-menu-${menu_id} > li:not(.context-menu-item-disabled)`).on('mousedown', function (e) { $(`#context-menu-${menu_id} > li:not(.context-menu-item-disabled)`).on('mousedown', function (e) {
e.preventDefault(); e.preventDefault();