-
Notifications
You must be signed in to change notification settings - Fork 3
/
tangy-overlay.js
179 lines (162 loc) · 4.38 KB
/
tangy-overlay.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import './util/html-element-props.js'
import './style/tangy-common-styles.js'
/**
* `tangy-overlay`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
export class TangyOverlay extends PolymerElement {
static get template () {
return html`
<style include="tangy-common-styles"></style>
<style>
#overlay {
position: fixed; /* Sit on top of the page content */
display: none; /* Hidden by default */
width: 100%; /* Full width (cover the whole page) */
height: 100%; /* Full height (cover the whole page) */
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5); /* Black background with opacity */
z-index: 2; /* Specify a stack order in case you're using a different order for other elements */
cursor: pointer; /* Add a pointer on hover */
text-align:center;
}
#lightbox {
width: calc(100vw - 100px);
height: calc(100vh - 100px);
overflow-y: scroll;
overscroll-behavior: contain;
/*margin: 0;*/
padding: 0;
background-color: #fafafa;
margin:auto;
}
.media-button-top-left {
position: fixed;
left:20px;
padding: 10px;
margin-left: -10px;
margin-top: -20px;
z-index: 999999999999999;
}
.media-button-top-right {
position: fixed;
top:30px;
right:30px;
padding: 10px;
margin-top: -20px;
z-index: 999999999999999;
}
.media-button-bottom-left {
position: fixed;
bottom:0;
left:20px;
margin:10px;
z-index: 999999999999999;
}
.media-button-bottom-right {
position: fixed;
bottom:50px;
right:50px;
margin:0px;
z-index: 999999999999999;
}
</style>
<div id="media-button" on-click="handleMediaButtonClick" >
</div>
<div id="overlay">
<div id="lightbox" on-click="handleLightboxClick">
</div>
</div>
<br/>
`
}
static get is () {
return 'tangy-overlay'
}
static get properties() {
return {
onOpen: {
type: String,
value: ''
},
open: {
type: Boolean,
value: false,
reflectToAttribute: true,
observer: 'reflect'
},
position: {
type: String,
value: '',
reflectToAttribute: true,
},
overlayContent: {
type: String,
value: '',
},
icon: {
type: String,
value: 'icons:open-with'
}
};
}
// Element class can define custom element reactions
connectedCallback() {
super.connectedCallback();
// Set up the store.
this.store = window.tangyFormStore
this.$['media-button'].innerHTML = `
<paper-fab icon="${this.icon}" raised on-click="open"></paper-fab>
`
if (this.position === 'top-right') {
this.shadowRoot.getElementById('media-button').className = 'media-button-top-right'
} else if (this.position === 'top-left') {
this.shadowRoot.getElementById('media-button').className = 'media-button-top-left'
} else if (this.position === 'bottom-right') {
this.shadowRoot.getElementById('media-button').className = 'media-button-bottom-right'
} else if (this.position === 'bottom-left') {
this.shadowRoot.getElementById('media-button').className = 'media-button-bottom-left'
}
}
reflect(ev) {
// let currentDisplay = this.shadowRoot.getElementById("overlay").style.display
if (this.open) {
this.shadowRoot.getElementById("overlay").style.display = "block"
} else {
this.shadowRoot.getElementById("overlay").style.display = "none"
}
if (this.onOpen) {
let getValue = this.getValue.bind(this)
let newOverlayContent = ''
eval(`
function go() {
${this.onOpen}
}
newOverlayContent = go()
`)
this.$.lightbox.innerHTML = newOverlayContent
} else {
this.$.lightbox.innerHTML = this.innerHTML
}
}
getValue(name) {
let state = this.store.getState()
let input = state.inputs.find((input) => input.name == name)
if (input) return input.value
}
handleMediaButtonClick() {
this.open = !this.open
}
handleLightboxClick() {
if (!this.position) this.open = !this.open
}
}
window.customElements.define(TangyOverlay.is, TangyOverlay)