-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_items.html
More file actions
76 lines (65 loc) · 1.7 KB
/
multiple_items.html
File metadata and controls
76 lines (65 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>ContextMenu multiple items demo</title>
<style>
html {
height: 100%;
}
body {
/* Affects click coordinates */
margin: 0;
width: 100%;
height: 100%;
}
body {
font-family: sans-serif;
margin: 0;
padding: 0;
line-height: 150%;
}
.item-list {
width: fit-content;
height: 15em;
display: flex;
}
.item-list .item {
background: #aaa;
border: white 1px solid;
padding: 1em;
margin-left: 1em;
}
.item:not(:first-child) {
margin-left: 1em;
}
</style>
</head>
<body>
<div class="item-list js-with-context-menu">
<div class="item" data-id="1">item1</div>
<div class="item" data-id="2">item2</div>
</div>
<script type="module">
const { ContextMenu } = await import("../context_menu.mjs");
new ContextMenu({
target: document.querySelector('.js-with-context-menu'),
items: [{
label: 'Edit', action: function () {
console.log('Editing...');
}
},
{
label: 'Delete', action: function () {
console.log('Deleting...');
}
}],
openCondition: function (target) {
const matched = target.matches(".item");
const id = target.dataset.id;
console.log(id);
return matched;
},
});
</script>
</body>
</html>