forked from enguyen/io-menu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathio-menu-layer.html
89 lines (88 loc) · 2.27 KB
/
io-menu-layer.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
<link rel="import" href="../polymer/polymer.html">
<dom-module id="io-menu-layer">
<style>
:host {
display: none;
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 100000;
/*background: rgba(0, 0, 0, 0.2);*/
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
overflow: hidden;
}
:host([opened]) {
display: block;
}
</style>
<template></template>
</dom-module>
<script>
(function() {
document.body.appendChild(document.createElement('io-menu-layer'));
Polymer({
is: 'io-menu-layer',
properties: {
opened: {
type: Boolean,
reflectToAttribute: true
},
_groups: {
value: []
}
},
listeners: {
'mouseup': '_onMouseup'
},
created: function() {
var stopper = function(event) {
event.stopPropagation();
if (event.target === this) {
event.preventDefault();
}
}.bind(this);
this.addEventListener('click', stopper);
this.addEventListener('dblclick', stopper);
this.addEventListener('contextmenu', stopper);
this.addEventListener('mouseup', stopper);
this.addEventListener('mousedown', stopper);
this.addEventListener('touchstart', stopper);
this.addEventListener('touchend', stopper);
},
attached: function() {
document.body.addEventListener('io-menu-open-group', this._onOpen.bind(this));
document.body.addEventListener('io-menu-option-clicked', this._onMenuClose.bind(this));
},
_onOpen: function(event) {
this.opened = true;
if (event.detail) {
event.detail.opened = true;
this.appendChild(event.detail);
this._groups.push(event.detail);
}
},
_onMenuClose: function(event) {
this._closeAll();
},
_onMouseup: function(event) {
if (event.target === this) {
event.stopPropagation();
event.preventDefault();
this._closeAll();
}
},
_closeAll: function() {
this.opened = false;
for (var i = 0; i < this._groups.length; i++) {
this._groups[i].opened = false;
}
}
});
}());
</script>