-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
134 lines (120 loc) · 2.88 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue Context Menu</title>
<style>
html {
font-family: sans-serif;
font-size: 14px;
color: #333;
background: whitesmoke;
}
.colored-box {
height: 8em;
width: 8em;
display: inline-block;
margin-right: .75rem;
border: 1px solid;
box-shadow: 1px 1px gray;
opacity: .75;
}
.example {
border: 1px solid darkgray;
padding: 2rem 1rem;
margin: 0;
box-shadow: 1px 1px lightgray;
opacity: .75;
color: #000;
}
.rhs {
font-size: 1.1rem;
float: right;
width: 40vw;
padding: .5rem 0 1rem 0;
min-height: 8em;
margin: 1rem 0;
}
.lhs {
float:left;
padding: 0 1em;
}
h2 {
margin: .5rem 0;
}
hr {
margin: 1rem auto;
}
</style>
</head>
<body>
<div id="app">
<div class="lhs">
<h2 >Vue Context Menu - Demo</h2>
<p>right-click on a colored square to trigger a custom context menu</p>
<div
v-for="(color, index) in colors"
class="colored-box"
:style="{background: color}"
@click="sayColor(color)"
@contextmenu.prevent="$refs.ctx.open($event, {color: color, index: index})">
</div>
</div>
<div class="rhs">
Local Menu Data: <pre class="example">{{ menuData }}</pre>
</div>
<div style="clear:both;"></div>
<hr>
<pre class="example">{{ contextClicks }}</pre>
<context-menu id="testingctx" ref="ctx" @ctx-open="onCtxOpen" @ctx-cancel="resetCtxLocals" @ctx-close="onCtxClose">
<li class="ctx-header">{{menuData.color}}</li>
<li class="ctx-item">option one</li>
<li class="ctx-item disabled">option two (disabled)</li>
<li class="ctx-item" @click="logClick($event, menuData)">add to log</li>
</context-menu>
</div>
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="vue-context-menu.js"></script>
<script>
// install globally as <context-menu>
Vue.use(VueContextMenu)
const newMenuData = () => ({ color: null })
new Vue({
el: '#app',
data() {
return {
colors: ['pink', 'lightblue', 'green', 'red', 'turquoise'],
showCtx: false,
menuData: newMenuData(),
contextClicks: []
}
},
methods: {
onCtxOpen(locals) {
console.log('open', locals)
this.menuData = locals
},
onCtxClose(locals) {
console.log('close', locals)
},
resetCtxLocals() {
this.menuData = newMenuData()
},
logClick(e,context) {
this.contextClicks.push(Object.assign({},this.menuData))
return logger('click')(context)
},
sayColor(color) {
window.alert('left click on ' + color)
}
}
})
function logger(n) {
let name = 'event:ctx-' + n
return function(...more) {
console.log(name, ...more)
}
}
</script>
</body>
</html>