-
Notifications
You must be signed in to change notification settings - Fork 0
/
3by3.html
378 lines (323 loc) · 12.5 KB
/
3by3.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html>
<head>
<title>W3.CSS Template</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata">
<style>
body, html {
height: 100%;
font-family: "Inconsolata", sans-serif;
}
.bgimg {
background-position: center;
background-size: cover;
background-image: url("/w3images/coffeehouse.jpg");
min-height: 60%;
justify-content: center;
height: 100px;
padding: 10px 0;
display: flex;
justify-content: center;
}
.top {
background-position: center;
background-size: cover;
min-height: 8%;
justify-content: center;
height: 10px;
display: flex;
}
.menu {
display: none;
}
.grid {
width: 1000px;
display: flex; /* establish flex container */
flex-wrap: wrap; /* enable flex items to wrap */
justify-content: space-around;
position: relative;
min-height: 75%;
padding-top: 30px;
border-style: solid;
}
.cell { /* don't grow, don't shrink, width */
margin-bottom: 5px;
background-color: #999;
max-width: 270px;
min-width: 270px;
max-height: 130px;
min-height: 130px;
}
.overlay{
position: absolute;
opacity: 0;
color: #fff;
z-index: 2;
transition: .5s ease;
background-color: #2cbdec;
max-width: 270px;
min-width: 270px;
max-height: 130px;
min-height: 130px;
}
.cell:hover .overlay{
opacity:0.8;
}
.overlay p{
text-align: center;
margin-top: 35%;
}
.textarea {
width: 100%;
overflow: hidden;
resize: vertical;
min-height: 130px;
line-height: 20px;
}
.edit {
}
</style>
</head>
<body>
<!-- Links (sit on top) -->
<div class="w3-top" style="position:relative">
<div class="w3-row w3-padding w3-black">
<div class="w3-col s6">
<label for="file-selector" class="w3-button w3-block w3-black">OPEN</label>
<input type="file" id="file-selector" accept=".json" hidden>
</div>
<div class="w3-col s6">
<a class="w3-button w3-block w3-black" onclick="exportJson(this);">SAVE</a>
</div>
</div>
</div>
<!-- Header with image -->
<header class="top">
<div style="position:absolute;">
<h5 id="themeBox" class="w3-center" style="display:block; margin:1px 0px 0px 0px;" ><span class="w3-tag w3-wide" style="padding-left: 100px; padding-right: 100px;">Theme</span></h5>
<input type="text" id="themeBoxInput" name="fname" placeholder="Theme" style="display:none">
<h5 id="nameBox" class="w3-center" style="display:block; margin:0px 0px 0px 0px;"><span class="w3-wide" style="font-family:Trattatello, fantasy ;">Name</span></h5>
<input type="text" id="nameBoxInput" name="fname" placeholder="Name" style="display:none">
</div>
</header>
<header class="bgimg" id="home">
<button style="position:absolute; right: 3px; " type="button" onclick="show_buttons()">Edit</button>
<div class="grid">
<div style="background-size:100% 100%;" class="cell" id="Top-Left">
<button style="display:none; position:absolute;" type="button" class="edit" onclick="edit(0)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(0)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Top">
<button style="display:none" type="button" class="edit" onclick="edit(1)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(1)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Top-Right">
<button style="display:none" type="button" class="edit" onclick="edit(2)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(2)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Left">
<button style="display:none" type="button" class="edit" onclick="edit(3)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(3)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Mid">
<button style="display:none" type="button" class="edit" onclick="edit(4)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(4)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Right">
<button style="display:none" type="button" class="edit" onclick="edit(5)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(5)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Bot-Left">
<button style="display:none" type="button" class="edit" onclick="edit(6)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(6)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Bot">
<button style="display:none" type="button" class="edit" onclick="edit(7)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(7)">
<p>Click to show video</p>
</div>
</div>
<div style="background-size:100% 100%;" class="cell" id="Bot-Right">
<button style="display:none" type="button" class="edit" onclick="edit(8)">Edit</button>
<div class="overlay" style="display:block" onclick="changeVideo(8)">
<p>Click to show video</p>
</div>
</div>
</div>
</header>
<!-- Add a background color and large text to the whole page -->
<div class="w3-sand w3-grayscale w3-large">
<!-- About Container -->
<div class="w3-container" id="about">
<div class="w3-content" style="padding-top: 1%; max-width:700px; text-align: center; font-style: italic;">
<textarea class="textarea" id="messageBoxInput" style="display: none;" placeholder="Why did yu choose this video?"></textarea></p>
<p id="messageBox" style="display: block;"></p>
<h5 class="w3-center w3-padding-64"><span class="w3-tag w3-wide">Video</span></h5>
<!-- put YT here -->
<iframe id="YT" width="640" height="360"
src="">
</iframe>
</div>
</div>
<!-- End page content -->
</div>
<!-- Footer -->
<footer class="w3-center w3-light-grey w3-padding-48 w3-large">
<p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" title="W3.CSS" target="_blank" class="w3-hover-text-green">w3.css</a></p>
</footer>
<script>
let buttonList = document.getElementsByClassName('edit');
let cellList = document.getElementsByClassName('cell');
let overlays = document.getElementsByClassName('overlay');
const messageBoxSelector = document.getElementById('messageBoxInput');
const themeBoxSelector = document.getElementById('themeBoxInput')
const nameBoxSelector = document.getElementById('nameBoxInput')
const nameBox = document.getElementById('nameBox').querySelectorAll('span')[0]
const themeBox = document.getElementById('themeBox').querySelectorAll('span')[0]
let selectedBox = 0
var listOfcellsData = [
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "", videoID: "", thumpnail: "", embed:"", message:""},
{ link: "https://www.youtube.com/watch?v=lqBs1P8afTU", videoID: "lqBs1P8afTU", thumpnail: "https://img.youtube.com/vi/lqBs1P8afTU/mqdefault.jpg", embed:"https://www.youtube.com/embed?v=lqBs1P8afTU"},
];
var finalData = [
{ theme: "", name: "", cellData: listOfcellsData},
]
function show_buttons(){
Array.prototype.forEach.call(buttonList, function(p) {
if (p.style.display === 'none') {
p.style.display = 'block'
} else {
p.style.display = 'none'
}
});
Array.prototype.forEach.call(overlays, function(o) {
if (o.style.display === 'none') {
o.style.display = 'block'
} else {
o.style.display = 'none'
}
});
if (document.getElementById("messageBoxInput").style.display === 'none') {
document.getElementById("messageBoxInput").style.display = 'block'
document.getElementById("messageBox").style.display = 'none'
} else {
document.getElementById("messageBoxInput").style.display = 'none'
document.getElementById("messageBox").style.display = 'block'
}
if (document.getElementById("nameBoxInput").style.display === 'none') {
document.getElementById("nameBoxInput").style.display = 'block'
document.getElementById("nameBox").style.display = 'none'
} else {
document.getElementById("nameBoxInput").style.display = 'none'
document.getElementById("nameBox").style.display = 'block'
}
if (document.getElementById("themeBoxInput").style.display === 'none') {
document.getElementById("themeBoxInput").style.display = 'block'
document.getElementById("themeBox").style.display = 'none'
} else {
document.getElementById("themeBoxInput").style.display = 'none'
document.getElementById("themeBox").style.display = 'block'
}
}
function edit(num) {
selectedBox = num;
messageBoxSelector.value = listOfcellsData[num].message;
let link = prompt("Please enter youtube link:", listOfcellsData[num].link);
let thumbnail;
let videoID = extractVideoIdFromYouTubeUrl(link)
let embed;
if (videoID == null || link == "" || link == null) {
} else {
thumbnail = "https://img.youtube.com/vi/"+videoID+"/mqdefault.jpg";
embed = "https://www.youtube.com/embed/"+videoID
}
listOfcellsData[num].link = link;
listOfcellsData[num].videoID = videoID;
listOfcellsData[num].thumpnail = thumbnail;
listOfcellsData[num].embed = embed
cellList[num].style.backgroundImage = "url("+thumbnail+")";
}
function extractVideoIdFromYouTubeUrl (url) {
var stepOne = url.split('=')[1];
var stepTwo = stepOne.split('/');
var videoId = stepTwo[stepTwo.length-1];
return stepOne;
}
function changeVideo(num){
console.log(num)
document.getElementById('YT').src = listOfcellsData[num].embed;
selectedBox = num;
document.getElementById("messageBox").innerText = "\""+listOfcellsData[num].message+"\"";
messageBoxSelector.value = listOfcellsData[num].message;
}
function exportJson(el) {
finalData[0].cellData = listOfcellsData;
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(finalData));
// what to return in order to show download window?
el.setAttribute("href", "data:"+data);
el.setAttribute("download", "My3by3.json");
}
const fileSelector = document.getElementById('file-selector');
fileSelector.addEventListener('change', (event) => {
const fileList = event.target.files;
new Response(fileList[0]).json().then(json => {
console.log(json)
if(json.length > 1){
listOfcellsData = json;
}else{
listOfcellsData = json[0].cellData;
finalData[0].name = json[0].name;
finalData[0].theme = json[0].theme;
themeBox.textContent = finalData[0].theme;
nameBox.textContent = finalData[0].name;
}
for (let i = 0; i < listOfcellsData.length; i++) {
cellList[i].style.backgroundImage = "url("+listOfcellsData[i].thumpnail+")";
}
console.log(json);
}, err => {
// not json
})
});
messageBoxSelector.addEventListener('change', (event) => {
console.log(messageBoxSelector.value)
listOfcellsData[selectedBox].message = messageBoxSelector.value
});
themeBoxSelector.addEventListener('change', (event) => {
console.log(themeBoxSelector.value)
finalData[0].theme = themeBoxSelector.value
themeBox.textContent = themeBoxSelector.value
});
nameBoxSelector.addEventListener('change', (event) => {
console.log(nameBoxSelector.value)
finalData[0].name = nameBoxSelector.value
nameBox.textContent = nameBoxSelector.value
});
</script>
</body>
</html>