Files
archived-verso/resources/components/context_menu.html
Jason Tsai 6ca28dd25a feat(prompt): add prompt support (#250)
* feat(context-menu): create webview on wayland

* dynamic generate menu items on html

* add context_menu.html

* add check mouse hit on context-menu webview

* fix: context menu prompt back to verso

* feat(context-menu): on linux, handle selection

* fix: disble right click on context menu

* organize code

* adding cfg target linux

* fix(linux): shift context menu to avoid overflow, best effort

* prompt temp

* add alert prompt

* refactor: move prompt and context menu to components

* remove redundant import

* feat(prompt): add ok/cancel, yes/no prompt

* feat(prompt): add input prompt dialog

* fix: add serde to all platform's dep

* refactor: organize verso html files

* update gitignore

* refactor: remove dialog show method depends on Window

* refactor: code clean

* fix: don't show context menu when prompt exist

* update css

* fix(prompt): handle resize when prompt exists

* fix(prompt): close prompt when navigate to new url

* chore: restore default home page

* chore: fix linux mod path, remove unused pipeline fn

* feat: handle EmbedderMsg::PromptPermission

* refactor: rename components to webview and move WebView into it
2024-12-04 12:55:38 +00:00

82 lines
1.9 KiB
HTML

<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background: #dfdfdf;
width: 184px;
}
.menu {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
}
.menu-item {
cursor: pointer;
display: inline-block;
height: 30px;
width: 100%;
line-height: 30px;
padding-left: 5px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.menu-item:hover {
background: #cecece;
border-radius: 5px;
}
.menu-item.disabled {
cursor: default;
background: #dfdfdf;
color: #505050;
cursor: pointer;
}
.menu-item:hover.disabled {
background: #dfdfdf;
}
</style>
</head>
<body>
<div id="menu" class="menu"></div>
</body>
<script>
const menuEl = document.getElementById('menu');
let url = URL.parse(window.location.href);
let params = url.searchParams;
const options = JSON.parse(params.get('items'));
for (option of options) {
createMenuItem(option.id, option.label, option.enabled);
}
function createMenuItem(id, label, enabled) {
const menuItem = document.createElement('div');
menuItem.classList.add('menu-item');
menuItem.id = id;
menuItem.innerText = label;
if (!enabled) {
menuItem.classList.add('disabled');
} else {
menuItem.onclick = (ev) => {
// accept left click only
if (ev.buttons !== 1) {
return;
}
const msg = JSON.stringify({
id,
close: true,
});
console.log(`CONTEXT_MENU:${msg}`);
window.prompt(`CONTEXT_MENU:${msg}`);
};
}
menuEl.appendChild(menuItem);
}
</script>
</html>