-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
54 lines (50 loc) · 1.47 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="build/styles/index.css">
<script src="build/index.js"></script>
<title>Document</title>
<style>
.icon-table{
background: url('build/styles/images/table.png') no-repeat center;
}
</style>
</head>
<body>
<button id="buttonclick" style="position:absolute;left:50%;top:50%">click me</button>
</body>
<script>
var max = 30
var maxdeep = 2
var createItems = function (deep) {
if (deep > maxdeep) return null
deep = deep || 0
var arr = []
var l = Math.round(Math.random() * max)
for (var i = 0; i < l; i++) {
var hasc = Math.random() > 0.5
var cl = createItems(deep + 1)
var n = (Math.random() > 0.2 ? { text: 'item-' + deep + 'level-' + i, disabled: Math.round(Math.random()) > 0.5, cls: 'icon-table' } : '-')
if (n !== '-') {
if (hasc && cl) {
n.items = cl
} else {
n.command = 'action' + deep + '-' + i
}
}
arr.push(n)
}
return arr
}
ContextMenu.on('itemclick', function (type, e, cmd) {
console.log(arguments)
})
document.querySelector('#buttonclick').addEventListener('contextmenu', function (e) {
var a = createItems()
ContextMenu.show(a, e)
})
</script>
</html>