-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
621 lines (617 loc) · 26.7 KB
/
index.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
<!DOCTYPE html>
<html>
<head>
<title>Takahashi Method Presentation</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml, %3Csvg width='256' height='230' viewBox='0 0 256 230' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='10' y='10' width='236' height='136' rx='10' fill='white' stroke='%230A73A7' stroke-width='20' stroke-linejoin='round'/%3E%3Cline x1='20' y1='35' x2='236' y2='35' stroke='%23E29002' stroke-width='30'/%3E%3Cpath d='M 128 35 L 128 220 M 64 220 L 192 220' stroke='%23E29002' stroke-width='20' stroke-linejoin='round' stroke-linecap='round'/%3E%3C/svg%3E%0A">
<div id="menubar">
<div id="presentation-editor">
<div id="presentation-editor-title" class="menu-title">ADD SLIDES</div>
<div>
<input type="file" id="file-input" class="file-input">
<input type="checkbox" id="parse-comments-checkbox">Parse Presenter Notes?
<button onclick="addNewSlide(`Slide ${slide_total+1}`)">Append Empty Slide</button>
</div>
<div>
<div class="menu-title">EXPORT SLIDES</div>
<button onclick="exportToTXT()">Export to .TXT</button>
</div>
</div>
<div id="display-settings">
<div id="display-settings-title" class="menu-title">Display Settings</div>
<div id="navigation-controls">
Navigate (or use arrow keys):
<button onclick="changeSlide(-1)">←</button>
<button onclick="changeSlide(1)">→</button>
</div>
<div id="shortcuts-text">
Shortcuts: <br>
[<hl>H</hl>]ide or Click on screen to hide header <br>
[<hl>E</hl>]dit slide (toggle editor) <br>
<button onclick="toggleFullscreen()" style="padding: 0">[<hl>F</hl>]ullscreen toggle </button><br>
<button onclick="reloadSlides()" style="padding: 0">[<hl>R</hl>]egenerate Slides</button>
</div>
<button id="theme-switch" onclick="changeTheme()" style="--active-theme-color:yellow;--inactive-theme-color:black;">
<svg width="40" height="40" viewBox="0 0 100 100">
<circle cx="60" cy="50" r="30" id="theme-circle-inactive" fill="var(--inactive-theme-color)"/>
<circle cx="40" cy="50" r="30" id="theme-circle-active" fill="var(--active-theme-color)"/>
</svg>
</button>
<div id="slide-count-display">No Slides Yet</div>
<div style="position: absolute">
QR Codes:
<select name="qrcode-select" id="qrcode-select">
<option value="disabled">Disabled</option>
<option value="CDN">Load library via CDN</option>
<option value="local">Load library from Local</option>
</select>
</div>
</div>
<div id="information-section">
<div id="github-link">
<a target="_blank" href="https://github.com/andrei-akopian/TMPTSCH">
<div>Info/Code</div>
<svg width="50" height="50" viewBox="10 10 80 80">
<circle cx="50" cy="50" r="30" fill="black"/>
<polygon points="20,50 20,15 50,40" fill="black"/>
<polygon points="80,50 80,15 50,40" fill="black"/>
<polyline points="40,40 30,50 40,60 60,40 70,50 60,60" stroke="white" stroke-width="2px" class="code-icon"/>
<line x1="50" y1="70" x2="50" y2="50" stroke="white" stroke-width="5px" stroke-linecap="round" class="info-icon"/>
<circle cx="50" cy="40" r="5px" fill="white" class="info-icon" />
</svg>
</a>
</div>
</div>
</div>
<script>
//TODO: make persistent configuration, and add dropdown to prioritize image loading source if missmatch
let slide_i = 0;
let slide_total = 0;
const header_element = document.getElementById("menubar");
const parse_comments_checkbox = document.getElementById("parse-comments-checkbox");
let editor_sidebar;
let slide_content_editor;
let presentation;
let slide_count_display;
const QR_code = {
loaded: false,
QRCode: null,
options: {
width: 512,
height: 512
}
};
onload = () => {
presentation = document.getElementById("presentation");
presentation.addEventListener('click', function(event) {
hideHeader(); // FIXME: clicking on links triggers this event
});
slide_count_display = document.getElementById("slide-count-display");
editor_sidebar = document.getElementById("editor-sidebar");
slide_content_editor = document.getElementById("slide-content-editor");
slide_total = presentation.querySelectorAll(".slide").length;
// Puts placeholder slide if there are no slides
if (slide_total == 0 && presentation.childElementCount == 0){
let placeholder = document.createElement("div");
placeholder.id = "presentation-placeholder";
placeholder.innerText = "No Slides Yet";
presentation.appendChild(placeholder);
} else { // Handle images having different sources
//TODO: think about the best way to hande this
let images = presentation.querySelectorAll(".image");
let default_to = null;
for (img of images){
if (img.src != img.alt) {
if (default_to==null){
default_to = confirm("Images are using a different source.\n\n" +
"Clicking OK will keep the source.\n" +
"Clicking Cancel will overwrite it with the original source\n\n" +
"Example of a different source: "+img.src+"\n"+
"Example of an original source: "+img.alt+"\n\n"+
"These changes will NOT be saved, so reloading the browser tab will reset this choice."
);
}
if (default_to){
img.parentElement.dataset.slide_content = img.parentElement.dataset.slide_content.replace(img.alt,img.src);
} else {
img.parentElement.dataset.slide_content = img.parentElement.dataset.slide_content.replace(img.src,img.alt);
img.src = img.alt;
}
}
}
if (default_to){
reloadSlides();
}
}
};
window.onbeforeunload = () => {
return "Your progress will be lost. You can save the presentation using Ctrl/Cmd+S";
};
async function loadQRCodeLib(source){
if (QR_code.loaded){
return;
};
if (source=='CDN'){
let response = await fetch("https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js", {
integrity: "sha512-CNgIRecGo7nphbeZ04Sc13ka07paqdeTu0WR1IM4kNcpmBAUSHSQX0FslNhTDadL4O5SAGapGt4FodqL8My0mA==",
crossorigin: "anonymous",
referrerpolicy: "no-referrer",
});
let code = await response.text();
eval(code);
QR_code.QRCode = QRCode;
QR_code.loaded = true;
reloadSlides();
} else if (source=="local") {
let filenames = ["qrcode.js","qrcode.min.js"];
loadLocalQRLib(filenames,0);
}
};
function loadLocalQRLib(filenames,i){ //TODO maybe find a better way to do this
let node = document.createElement("script");
node.type = "text/javascript";
node.src = filenames[i];
node.onload = () => {
QR_code.QRCode = QRCode;
QR_code.loaded = true;
reloadSlides();
};
if (i<filenames.length-1) {
node.onerror = () => {
node.remove();
console.log(filenames[i]+" failed to load, trying to load "+filenames[i+1]);
loadLocalQRLib(filenames,i+1);
};
}
document.body.appendChild(node);
}
document.getElementById("file-input").addEventListener("change", (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = (e) => {
const fileContent = e.target.result;
generateSlides(fileContent);
};
}
document.getElementById("file-input").value = "";
});
document.getElementById("qrcode-select").addEventListener("change", (e)=>{
loadQRCodeLib(document.getElementById("qrcode-select").value);
});
function exportToTXT(){
if (slide_total==0){
return;
}
let content = "";
const link = document.createElement("a");
for (slide of presentation.children) {
content += slide.dataset.slide_content + "\n\n";
}
content = content.trim("\n");
let file = new Blob([content], {type: 'text/plain'});
link.href = URL.createObjectURL(file);
link.download = "presentation.txt";
link.click();
URL.revokeObjectURL(link.href);
}
/*
// Slide Creation
*/
function generateSlides(text){
for (let content of text.split("\n\n")){
addSlide(content);
}
document.getElementById("s0").style.display = "block";
slide_content_editor.value = document.getElementById("s0").dataset.slide_content;
}
function addNewSlide(text){
//TODO: appends slides to the presentation, make it insert
// creates new slide from the buttom, requires a bit of style.display = block
addSlide(text);
changeSlide(slide_total-1); //Goto new slide
editor_sidebar.style.display = "block";
}
function addSlide(text){
let node = document.createElement("div");
node.dataset.slide_content = text;
node.className = "slide";
node.id = "s"+slide_total;
if (slide_total == 0){ //remove placeholder message
document.getElementById("presentation-placeholder").remove();
}
slide_total+=1;
presentation.appendChild(node);
generateSlideContents(node,text);
//refresh counters etc.
changeSlide(0);
}
function generateSlideContents(node,text){
node.innerHTML = "";
let has_image = false;
let lines = text.split("\n");
for (let line_i=0; line_i<lines.length; line_i++) {
let line = lines[line_i];
if (!has_image && line[0]=="@"){
node.appendChild(generateImage(line.trim("").slice(1)));
node.style.display='none';
has_image = true;
} else if (parse_comments_checkbox.checked && line.slice(0,2)=="//") {
//TODO: there is probably a better way to place the comments
let presenter_note = document.createElement("notes");
presenter_note.innerHTML = line.slice(2);
node.appendChild(presenter_note);
} else if (!has_image) {
// parse markdown links
let i = line.indexOf("](");
while (i>=0) { //TODO: doesn't handle all edgecases eg. "Title)[google.com]"
let opening_braket = line.lastIndexOf("[",i);
let closing_parenth = line.indexOf(")");
if (closing_parenth<0 || opening_braket<0) {
i = line.indexOf("](",i+2);
continue;
}
let link_title = line.substring(opening_braket+1,i);
let link_url = line.substring(i+2,closing_parenth);
node.appendChild(document.createTextNode(line.substring(0,opening_braket)));
node.appendChild(generateLinkTag(link_title, link_url));
line = line.substring(closing_parenth+1);
i = line.indexOf("](");
}
node.appendChild(document.createTextNode(line));
if (line_i<lines.length-1){
node.appendChild(document.createElement("br"));
}
}
}
fit(node);
}
function generateImage(source){
let image = document.createElement("img");
image.src = source;
image.alt = source;
image.onerror = () => {
logAlert("Image failed to laod from "+source);
};
image.className = "image";
return image;
}
function generateLinkTag(link_title, link_url){
if (document.getElementById("qrcode-select").value=="disabled" || !QR_code.loaded){ // Normal link option
let hyperlink_a = document.createElement("a");
hyperlink_a.target = "_blank";
hyperlink_a.href = link_url;
hyperlink_a.textContent = link_title;
return hyperlink_a
} else { // QR Code options
let tempnode = document.createElement("div");
tempnode.className = "link";
tempnode.textContent = link_title;
let qrcode_container = document.createElement("qrcode");
tempnode.appendChild(qrcode_container);
tempnode.addEventListener("click",(event) => {
showQRCode(event,qrcode_container);
});
let qr = new QR_code.QRCode(qrcode_container,QR_code.options);
qr.makeCode(link_url); //TODO: a very dirty way to do this, and a <canvas> element stays behind
return tempnode;
}
}
function changeSlide(n){
if (slide_total == 0){
logAlert("Error: There are no slides\nFix: Click button in top right to add some.");
return;
}
document.getElementById("s"+slide_i).style.display = "none";
slide_i = Math.max(Math.min(slide_total-1,slide_i+n),0);
document.getElementById("s"+slide_i).style.display = "block";
// Display other info
slide_count_display.innerText = `Slide: ${slide_i+1} of ${slide_total}`;
if (parse_comments_checkbox.checked){ //TODO inconsisten name for presenter's notes/comments
let notes = document.getElementById("s"+slide_i).querySelectorAll("notes");
for (note of notes){
console.log("Slide "+(slide_i+1)+"/"+slide_total+" Notes: "+note.innerHTML);
}
}
// setup editor
slide_content_editor.value = document.getElementById("s"+slide_i).dataset.slide_content;
}
function fit(slide) {
var style = slide.style
var i = 1000
style.display = "inline";
style.fontSize = i + "px";
//Math.floor and division by 5 are to add margins to the text
style.fontSize = Math.floor(Math.min(i/slide.offsetWidth*innerWidth,i/slide.offsetHeight*innerHeight)/5)*5+"px";
style.display = "none";
}
function editSlideContent(){
let slide = document.getElementById("s"+slide_i);
slide.dataset.slide_content=slide_content_editor.value;
generateSlideContents(slide, slide.dataset.slide_content);
slide.style.display = "block";
}
function reloadSlides(){
if (slide_total==0){
return;
}
let slide;
for (slide of presentation.children){
generateSlideContents(slide, slide.dataset.slide_content);
}
document.getElementById("s"+slide_i).style.display = "block";
}
/*
// Display Settings related functions
*/
function hideHeader(){
if (header_element.style.display == "none"){
header_element.style.display = "";
} else {
header_element.style.display = "none";
editor_sidebar.style.display = "none";
}
}
function hideEditor(){
if (editor_sidebar.style.display === ''){
if (slide_total > 0){
editor_sidebar.style.display = "block";
}
} else {
editor_sidebar.style.display = '';
}
}
function showQRCode(event, element){
event.stopPropagation();
if (element.style.display == "block"){
element.style.display = "";
} else {
element.style.display = "block";
}
}
document.body.addEventListener("keydown", function (event) {
if (document.activeElement === slide_content_editor){
return;
}
if (event.keyCode == 37){
changeSlide(-1);
} else if (event.keyCode == 39) {
changeSlide(1);
} else if (event.keyCode ==72) {
hideHeader();
} else if (event.keyCode == 69) {
hideEditor();
} else if (event.keyCode == 82) {
reloadSlides();
} else if (event.keyCode == 70) {
toggleFullscreen();
}
});
function changeTheme(){
// toggle dark mode
document.body.classList.toggle('dark-theme');
// swap colors on the toggle (aesthetic, no functionality)
let theme_button = document.getElementById("theme-switch");
let temp = theme_button.style.getPropertyValue("--active-theme-color");
theme_button.style.setProperty("--active-theme-color",theme_button.style.getPropertyValue("--inactive-theme-color"))
theme_button.style.setProperty("--inactive-theme-color",temp);
};
function toggleFullscreen() {
if (document.fullscreen) {
document.exitFullscreen();
} else if (document.fullscreenEnabled){
document.body.requestFullscreen();
} else {
logAlert("Fullscreen unavailable/disabled in your browser.");
}
};
function logAlert(message){
console.log(message);
alert(message);
}
</script>
<style>
#main-display-area {
position: relative;
display: grid;
}
.image {
max-height: 100vh;
max-width: 100vw;
object-fit: contain;
height: 100vh;
width: 100vh;
}
#menubar {
margin-top: 0px;
background-color: #0A73A7;
color: #BBBBBB;
height: 15%;
width: 100%;
display: grid;
grid-template-columns: 30% 50% 20%;
}
.file-input {
width: 200px;
}
#display-settings {
height: 120%;
background-color: #E29002;
border-width: 5px;
border-color: #C37515;
border-style: solid;
border-radius: 0px 0px 20px 20px;
position: relative;
color: #000000;
z-index: 2;
}
#display-settings-title{
color: #0A42C5;
}
.menu-title {
width 100%;
text-align: center;
}
#presentation-editor-title {
color: #E2A619;
}
#slide-count-display {
position: relative;
}
hl { /* custom highlight tag for shortcut letters*/
color: #0A42C5;
}
#shortcuts-text {
padding-left: 5px;
}
#theme-switch {
position: absolute;
top: 0;
right: 0;
background-color: #C37515;
border: none;
border-radius: 0px 0px 0px 20px;
}
#theme-switch:hover #theme-circle-active {
fill: var(--inactive-theme-color);
}
#theme-switch:hover #theme-circle-inactive {
fill: var(--active-theme-color);
}
#navigation-controls {
position: absolute;
bottom: 5px;
right: 5px;
}
#presentation-editor {
float: left;
height: 90%;
padding-left: 10px;
padding-right: 10px;
}
#slide-content-editor {
width: 90%;
height: 90%;
outline: none;
border: none;
padding: 0;
margin-top: 5%;
margin-left: 5%;
}
#confirm-edit{
height: 5%;
width: 80%;
margin-top: 5%;
}
#close-editor-button {
height: 5%;
margin-left: 4%;
margin-top: 5%;
width: 10%;
}
#information-section {
position: relative;
}
#github-link {
position: absolute;
right: 10px;
height: 100%;
text-align: center;
}
#github-link > a {
color: #BBBBBB;
}
.info-icon {
display: none;
}
#github-link:hover .info-icon{
display: block;
}
#github-link:hover .code-icon{
display: none;
}
#editor-sidebar {
background-color: #0A73A7;
width: 20%;
display: none;
position: absolute;
right: 0;
top: 0;
height: 100%;
}
.text-input {
height: 100px;
position: absolute;
right: 0px;
}
#presentation {
height: 100vh;
display: grid;
overflow: hidden;
}
body {
margin: 0;
padding: 0;
background: #FFFFFF;
color: #000000;
font-family: Trebuchet MS;
--placeholder-color: #C0C0C0;
}
body::backdrop, body:fullscreen {
background: #FFFFFF;
}
.slide {
text-align: left;
white-space: nowrap;
place-self: center;
}
notes {
display: none;
}
a {
color: #0A42C5;
}
.link {
display: inline;
color: #0A42C5;
text-decoration: underline;
}
qrcode {
position: absolute;
display: none;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
qrcode > img {
max-height: 100vh;
max-width: 100vw;
object-fit: contain;
height: 100vh;
width: 100vh;
}
#presentation-placeholder {
color: var(--placeholder-color);
place-self: center;
text-align: center;
font-size: 20vh;
}
.dark-theme {
background-color: #000000;
color: #FFFFFF;
--placeholder-color: #303030;
}
</style>
</head>
<body>
<div id="main-display-area">
<div id="editor-sidebar">
<button id="close-editor-button" onclick="hideEditor()">⇛</button>
<button id="confirm-edit" onclick="editSlideContent()">Enter</button>
<textarea type="text" id="slide-content-editor"></textarea>
</div>
<div id="presentation">
</div>
</div>
</body>
</html>