-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto-context-menu.html
87 lines (68 loc) · 1.74 KB
/
proto-context-menu.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="proto-menu.html">
<!--
`proto-context-menu`
Context menu element prototype
@demo demo/index.html
-->
<dom-module id="proto-context-menu">
<template>
<style>
:host {
display: block;
}
</style>
<content id="content"></content>
</template>
<script>
Polymer({
is: 'proto-context-menu',
properties: {
_listenerBound: {
type: 'Function',
value: function() {
return this._listener.bind(this);
}
},
disabled: {
type: Boolean,
reflectToAttribute: true
}
},
get _menu() {
return this.queryEffectiveChildren('proto-menu');
},
open: function(event) {
if (this.disabled) {
return;
}
event.preventDefault();
var x = event.detail && event.detail.x || event.clientX;
var y = event.detail && event.detail.y || event.clientY;
var menu = this._menu;
menu.resetFit();
menu.style.position = 'fixed';
menu.style.left = x + 'px';
menu.style.top = y + 'px';
menu.open();
},
close: function() {
this._menu.close();
},
cancel: function() {
this._menu.cancel();
},
_listener: function(event) {
this.open(event);
},
attached: function() {
this._parent = Polymer.dom(this).parentNode;
this._parent.addEventListener('contextmenu', this._listenerBound);
},
detached: function() {
this._parent.removeEventListener('contextmenu', this._listenerBound);
this._parent = undefined;
}
});
</script>
</dom-module>