-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube-dialog.js
81 lines (69 loc) · 1.56 KB
/
cube-dialog.js
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
import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
import '@polymer/paper-dialog/paper-dialog.js';
class CubeDialog extends PolymerElement {
static get is() {return 'cube-dialog';}
static get template()
{
return html`<style>
:host {
display: none;
}
</style>
<paper-dialog id="dialog" with-backdrop="[[withBackdrop]]" modal="[[modal]]" style="border-radius:5px;overflow:hidden"></paper-dialog>
<div id="helper">
<slot id="cSlot"></slot>
</div>`;
}
static get properties()
{
return {
modal: {type: Boolean},
withBackdrop: {type: Boolean}
}
}
connectedCallback()
{
super.connectedCallback();
let self = this;
this.$.cSlot.addEventListener('slotchange', function () {
let elements = self.querySelectorAll('*');
for(let i = 0; i < elements.length; i++)
{
self.$.dialog.appendChild(elements[i]);
}
});
}
open()
{
if(!this._dlg)
{
this._dlg = this.root.querySelector('#dialog');
this._dlg.addEventListener('cube-dialog-close', function () {this._dlg.close()}.bind(this));
document.body.appendChild(this._dlg);
}
this._dlg.open();
}
close()
{
if(this._dlg)
{
this._dlg.close();
}
}
refit()
{
if(this._dlg)
{
this._dlg.refit();
}
}
query(selector)
{
return this.$.dialog.querySelector(selector);
}
queryAll(selector)
{
return this.$.dialog.querySelectorAll(selector);
}
}
customElements.define(CubeDialog.is, CubeDialog);