-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto-grid-context-menu.html
69 lines (55 loc) · 1.73 KB
/
proto-grid-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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="proto-context-menu.html">
<!--
`proto-context-menu`
Context menu element prototype
@demo demo/index.html
-->
<dom-module id="proto-grid-context-menu">
<template>
<style>
:host {
display: block;
}
</style>
<content></content>
</template>
<script>
Polymer({
is: 'proto-grid-context-menu',
listeners: {
'grid-context-menu': '_onGridContextMenu',
'menu-item-click': '_onMenuItemClick'
},
_onGridContextMenu: function(event) {
event.preventDefault();
if (this._contextMenu) {
this._contextMenu.cancel();
Polymer.dom(this).removeChild(this._contextMenu);
}
var template = this.queryEffectiveChildren('template');
this._menuData = {
cell: event.detail.cell,
row: event.detail.row
};
this._contextMenu = template.stamp(this._menuData).root.firstElementChild;
Polymer.dom(this).appendChild(this._contextMenu);
this._contextMenu.addEventListener('iron-overlay-closed', function(event) {
var closedContextMenu = event.currentTarget;
if (closedContextMenu.isAttached) {
Polymer.dom(this).removeChild(closedContextMenu);
}
if (this._contextMenu === closedContextMenu) {
this._contextMenu = undefined;
}
}.bind(this));
this._contextMenu.open(event);
},
_onMenuItemClick: function(event) {
if (!event.detail || Object.keys(event.detail).length === 0) {
this.fire('grid-menu-item-click', this._menuData, {node: event.target});
}
}
});
</script>
</dom-module>