Repository navigation
Expand file tree
/
Copy pathcasper-context-select.js
More file actions
131 lines (109 loc) · 3.28 KB
/
Copy pathcasper-context-select.js
File metadata and controls
131 lines (109 loc) · 3.28 KB
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
/*
- Copyright (c) 2018 Cloudware S.A. All rights reserved.
-
- This file is part of casper-context-menu.
-
- casper-context-menu is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- casper-context-menu is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with casper-context-menu. If not, see <http://www.gnu.org/licenses/>.
-
*/
import '@cloudware-casper/casper-common-ui/casper-overlay.js';
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
class CasperContextSelect extends PolymerElement {
static get template() {
return html`
<style>
:host {
/* display: flex; */
display: inline-block;
}
:host([opened]) {
background-color: green;
}
#trigger {
color: black;
/* background-color: yellow; */
}
#trigger:hover{
cursor: pointer;
/* background-color: yellow; */
color: var(--primary-color);
}
:host #list_slot {
/* width: 200px; */
/* display: flex; */
}
</style>
<div id="trigger">
<slot name="trigger"></slot>
</div>
<casper-overlay id="list" scroll-action="lock" no-overlap="" vertical-align="[[vertical_align]]" horizontal-align="[[horizontal_align]]">
<slot name="list"></slot>
</casper-overlay>
`;
}
static get is () {
return 'casper-context-select';
}
static get properties () {
return {
vertical_align: {
value: 'auto'
},
horizontal_align: {
value: 'left'
},
closable: {
value: 'true' // close
},
opening: {
value: undefined
}
}
}
customclick(e){
var level = Number(e.target.getAttribute("data-level"));
var text = e.target.text;
this.innerText = text;
this.$.list.close();
}
_openList(){
clearTimeout(this.opening);
this.$.list.open()
}
_delayHide(e){
this.opening = setTimeout(function(){
this.$.list.close();
}.bind(this), 300)
}
ready () {
super.ready();
this.$.trigger.addEventListener('click', e => this._openList());
this.$.trigger.addEventListener('mouseover', e => this._openList());
this.$.trigger.addEventListener('mouseout', e => this._delayHide());
this.$.list.addEventListener('mouseover', e => this._openList());
this.$.list.addEventListener('mouseout', e => this.$.list.close());
if(this.closable != 'false'){
this.$.list.addEventListener('click', e => this._mustClose(e));
}
}
_mustClose(e){
this.$.list.close();
}
connectedCallback () {
super.connectedCallback();
// this.$.list_slot.style.width = '500px';
// this.$.list.style.display = 'none';
}
}
window.customElements.define(CasperContextSelect.is, CasperContextSelect);