/
demo_prod.html
101 lines (96 loc) · 2.92 KB
/
demo_prod.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<title>Context Menu Demo</title>
<style>
.panel {
background-color: #454d55;
border-width:0;
color:white;
box-shadow: 5px 5px #88888855;
border-radius: 10px;
}
.item {
border-bottom-style: outset;
padding:3px;
border-bottom-width: 1px;
font-weight:bold;
font-size:15px;
text-transform: uppercase;
}
.item:hover {
background-color: yellow;
color: black;
}
.last_item {
padding:3px;
border-bottom-width: 0;
font-weight:bold;
font-size:15px;
text-transform: uppercase;
}
.last_item:hover {
background-color: yellow;
color: black;
}
</style>
<script src="../context_menu.umd.cjs"></script>
</head>
<body>
<div id="myDiv">My element</div>
<script>
// obtain an element for menu
const div = document.getElementById("myDiv");
// define menu items
const items = [
{
id:"item1",
title: "Batman",
image:"https://code.germanov.dev/context_menu/assets/batman.svg"
},
{
id:"item2",
title: "Hacker",
image:"https://code.germanov.dev/context_menu/assets/hacker.svg"
},
{
id:"item3",
title: "Santa",
image:"https://code.germanov.dev/context_menu/assets/santa.svg"
}
];
// create the menu with specified items and bind it to specified DIV
const menu = Menus.create(items,div);
// apply custom CSS classes to the menu and items
// Set class for menu panel
menu.setPanelClass("panel");
// Set class for all menu items
menu.setItemClass("item");
// Set specific class for last menu item (remove bottom border)
menu.setItemClass("last_item","item3");
// Reset default styles of text to use text color from panel
menu.setTextClass(" ");
// react when user clicks on menu items
menu.on('click', (event) => {
// run different actions depending on ID of item
// on which user has clicked
switch (event.itemId) {
case "item1":
console.log("User clicked first item");
console.log("Mouse cursor position X:",
event.cursorX,"Y:",event.cursorY);
break;
case "item2":
console.log("User clicked second item");
console.log("Mouse cursor position X:",
event.cursorX,"Y:",event.cursorY);
break;
case "item3":
console.log("User clicked third item");
console.log("Mouse cursor position X:",
event.cursorX,"Y:",event.cursorY);
break;
}
})
</script>
</body>
</html>