-
Notifications
You must be signed in to change notification settings - Fork 0
/
QLCpTextBook.html
1146 lines (1032 loc) · 48.3 KB
/
QLCpTextBook.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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>QLCpTextBookEditor V0.1.0</title>
<meta charset="UTF-8">
<link rel="icon" href="./include/icon/QLCp-TBicon.png">
<!-- use local first, CDN as fallback -->
<!-- include libraries(jQuery, bootstrap) -->
<link rel="stylesheet" href="./inclext/bootstrap.min.css" onerror="this.onerror=null;this.href='https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css';" />
<!-- (loaded if "typeof jQuery == 'function'") -->
<script src="./inclext/jquery-3.5.1.min.js"></script>
<script> if ("undefined" == typeof jQuery) { document.write('<script src="https://code.jquery.com/jquery-3.5.1.min.js"><\/script>') } </script>
<!-- (loaded if "typeof $.fn.emulateTransitionEnd == 'function'") -->
<script src="./inclext/bootstrap.min.js"></script>
<script> if ("undefined" == typeof $.fn.emulateTransitionEnd) { document.write('<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"><\/script>') } </script>
<!-- include summernote css/js -->
<link rel="stylesheet" href="./inclext/summernote.min.css" onerror="this.onerror=null;this.href='https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote.min.css';" />
<!-- (loaded if "typeof $.fn.summernote === 'function'") -->
<script src="./inclext/summernote.min.js"></script>
<script> if ("undefined" == typeof $.fn.summernote) { document.write('<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote.min.js"><\/script>') } </script>
<!-- include qlcp css and js (local) -->
<link href="./include/qlcp.css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="./include/qlcp.js"></script>
<!-- ******************************************* CSS **************************************************************************************************************** -->
<style>
:root {
--header1h: 40px;
--header2h: 20px;
--header3h: 4px;
--sidbarWidth: 400px;
--sidbarTopH: 86px;
}
html,body {
height: 100%;
}
td {
vertical-align: top;
}
.header1 {
height: var(--header1h);
background-color: #F5F5F5;
vertical-align: middle;
}
.header2 {
height: var(--header2h);
background-color: #F5F5F5;
vertical-align: middle;
}
.header3 {
height: var(--header3h);
background-color: #FFFFFF;
vertical-align: middle;
}
.h2progressBar {
height: 4px;
background: #04AA6D80;
width: 0%;
z-index: 20;
}
.h2canvas {
position: fixed;
width: 100%;
height: 4px;
overflow: hidden;
/*border:1px solid #d3d3d3;*/
z-index: 10;
}
.sidebarTop {
height: var(--sidbarTopH);
width: var(--sidbarWidth);
padding-left: 5px;
vertical-align: middle;
background-color: #F5F5F5;
}
.sidebar {
background-color: white; /*#00FFFF;*/
/*height:100%;*/
height: calc(100vh - (var(--header1h) + var(--header2h) + var(--header3h) + var(--sidbarTopH) + 4px)); /* 4px for Border? */
width: var(--sidbarWidth);
overflow-y:auto;
white-space: nowrap;
}
.sidebarIndexBox {
background-color: white; /*#00FFFF;*/
/*height:100%;*/
height: calc(100vh - (var(--header1h) + var(--header2h) + var(--header3h) + 4px)); /* 4px for Border? */
width: var(--sidbarWidth);
overflow-y:auto;
white-space: nowrap;
cursor: pointer;
}
/* Sidebar in editor mode */
.sidebarRootTreeButton {
width:100%;
padding-left: 10px;
border: 1px solid white;
border-radius: 3px;
text-align: left;
background-color: white;
transition-duration: 0.4s;
}
.sidebarRootTreeButton:hover {
background-color: #008CFF10;
border: 1px solid #008CBA;
}
.sidebarButton {
width:calc(100% - 30px);
padding-left: 10px;
margin-left: 30px;
border: 1px solid white;
border-radius: 3px;
text-align: left;
background-color: white;
transition-duration: 0.2s;
}
.sidebarButton:hover {
background-color: #008CFF10;
border: 1px solid #008CBA;
transition-duration: 0.2s;
}
/* Sidebar in text view mode */
.sidebarIndex {
border: 1px solid white;
border-radius: 3px;
background-color: white;
}
.sidebarIndex:hover {
background-color: #008CFF10;
border: 1px solid #008CBA;
}
.sidebarIndexInView {
border: 1px solid white;
border-radius: 3px;
background-color: #eee;
}
.sidebarIndexInView:hover {
background-color: #007CEF10;
border: 1px solid #008CBA;
}
.click2edit {
height: calc(100vh - (var(--header1h) + var(--header2h) + var(--header3h) + 4px)); /* 3 (Border?) */
overflow-y:auto;
padding-top: 10px;
padding-right: 10px;
padding-left: 10px;
}
.top-button {
border-radius: 3px;
background: #fff;
border: 1px solid #bbb;
}
.top-button:hover {
background: #eee;
}
.top-button-on {
background: #bdb;
}
.top-button-on:hover {
background: #aca;
}
.top-button-off {
background: #f00;
border: 1px solid red;
}
.top-button-off:hover {
background: #a00;
}
.top-button:disabled {
opacity: 0.3;
}
.toggle-buttons input[type="radio"] {
clip: rect(0 0 0 0);
clip-path: inset(50%);
font-size: 10pt;
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.toggle-buttons label {
font-size:8pt;
text-align: center;
height: 22px;
border: 1px solid #aaa;
border-radius: 3px;
padding: 1px;
z-index: -1;
background: #fff;
}
.toggle-buttons input:checked + label {
/* background: #ebf5d7; */
color: #1365A4;
box-shadow: none;
border: 2px solid #1365A4;
}
input:hover + label /*,
input:focus + label */{
background: #eee; /*#ffebe6; */
}
.toggle-box {
border-radius: 3px;
}
</style>
</head>
<!-- ******************************************* HTML **************************************************************************************************************** -->
<body onresize="resizeFunction()" onload="onloadFunction()">
<table width=100% height=100% border>
<tr>
<td class="header1" colspan=2>
<div style="display: flex; justify-content: space-between; white-space: nowrap; ">
<span style="margin-left: 15px; ">
<!--
All my testbuttons
<button id="edit" class="btn btn-primary" onclick="edit()" type="button">Edit</button>
<button id="save" class="btn btn-primary" onclick="save()" type="button">Save</button>
<button id="insert" class="btn btn-primary" onclick="insert()" type="button">Test Insert</button>
<button class="top-button" id="save" onclick="save()" type="button">Close</button>
<button class="top-button" id="insert" onclick="toggleEditButton(this)" type="button">Test Insert</button>
-->
<button class="top-button" id="edit" onclick="toggleEditButton(this)" type="button">Edit</button>
<!-- <input class="top-button" value="Load File" onclick="loadFileOld()" type="button" /> -->
<button class="top-button" onclick="loadFile()">Load File</button><input id="loadFileinput" type='file' accept=".html" style="visibility:hidden; position:absolute;" onchange="readFile(event)"/>
<button class="top-button" id="saveFileID" disabled=true onclick="saveFile()" type="button">Save File</button>
<button class="top-button" id="tbButtonID" onclick="toggleTextBookIndexButton(this)" type="button">Textbook Index</button>
QLC+ IP:
<input type="text" id="qlcplusIP" value="127.0.0.1:9999"></input>
<input class="top-button" id="QLCpConnButton" style="width: 80px;" type="button" value="Connect" onclick="connectQLCpWebSocket(document.getElementById('qlcplusIP').value,QLCpConnected);"></input>
<div id="QLCpConnStatus" style="display: inline-block;"><img src="include/icon/QLCp_off.png"> <font color=red>Not connected</font></div>
<!--
<button class="top-button" onclick="displayEditClass('.qlcpMode1', 'none')" type="button">hide</button>
<button class="top-button" onclick="displayEditClass('.qlcpMode1', 'inline')" type="button">show</button>
-->
</span>
<span style="margin-right: 20px;">
<button class="top-button" id="hideButton1" onclick="displayButtonToggle(this, '.qlcpButtonColor1')" type="button"><div class="toggle-box qlcpButtonColor1" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton2" onclick="displayButtonToggle(this, '.qlcpButtonColor2')" type="button"><div class="toggle-box qlcpButtonColor2" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton3" onclick="displayButtonToggle(this, '.qlcpButtonColor3')" type="button"><div class="toggle-box qlcpButtonColor3" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton4" onclick="displayButtonToggle(this, '.qlcpButtonColor4')" type="button"><div class="toggle-box qlcpButtonColor4" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton5" onclick="displayButtonToggle(this, '.qlcpButtonColor5')" type="button"><div class="toggle-box qlcpButtonColor5" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton6" onclick="displayButtonToggle(this, '.qlcpButtonColor6')" type="button"><div class="toggle-box qlcpButtonColor6" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton7" onclick="displayButtonToggle(this, '.qlcpButtonColor7')" type="button"><div class="toggle-box qlcpButtonColor7" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton8" onclick="displayButtonToggle(this, '.qlcpButtonColor8')" type="button"><div class="toggle-box qlcpButtonColor8" style="width: 20px;"> </div></button>
<button class="top-button" id="hideButton9" onclick="displayButtonToggle(this, '.qlcpButtonColor9')" type="button"><div class="toggle-box qlcpButtonColor9" style="width: 20px;"> </div></button>
</span>
</div>
</td>
</tr>
<tr>
<td colspan=2>
<div class="header3">
<canvas class="h2canvas" id="scrollBarCanvasID" width="10040" height="4"> Your browser does not support the HTML5 canvas tag.</canvas>
<div class="h2progressBar" id="scrollProgressBarID"></div>
</div>
</td>
</tr>
<tr>
<td colspan=2>
<div class="header2">
<span style="text-align: left; margin-left: 20px;">
<span class="h1index" id="h1infoID"></span>
<span class="h2index" id="h2infoID"></span>
<span class="h3index" id="h3infoID"></span>
<span class="h4index" id="h4infoID"></span>
</span>
<span style="float: right; margin-right: 30px;">
<span class="h5index" id="h5infoID"></span>
<span class="h6index" id="h6infoID"></span>
</span>
</div>
</td>
</tr>
<tr>
<td class="summernotetab">
<div class="textbook">
<!-- start here empty-->
<div class="click2edit" id="clic2editID"><p><br></p></div>
</div>
</td>
<td width=1px>
<div class="sidebarTop" hidden=hidden>
<!-- TestCode
Test
-->
<table cellspacing="0" cellpadding="0">
<tr>
<td>
Mode:
</td>
<td>
<div class="toggle-buttons">
<input type="radio" id="rb-a1" value='0' name="group-a" /><label style="width: 40px;" for="rb-a1">Stop</label>
<input type="radio" id="rb-a2" value='1' name="group-a" checked="checked" /><label style="width: 40px;" for="rb-a2">Run</label>
<input type="radio" id="rb-a3" value='2' name="group-a" /><label style="width: 40px;" for="rb-a3">Flash</label>
Width:
<input type="radio" id="rb-b1" value='0' name="group-b" /><label style="width: 45px;" for="rb-b1">Normal</label>
<input type="radio" id="rb-b2" value='1' name="group-b" /><label style="width: 45px;" for="rb-b2">50%</label>
<input type="radio" id="rb-b3" value='2' name="group-b" checked="checked" /><label style="width: 45px;" for="rb-b3">100%</label>
</div>
</td>
</tr>
<tr>
<td>
Icon:
</td>
<td>
<div class="toggle-buttons">
<input type="radio" id="rb-c1" value='' name="group-c" checked="checked" /><label style="width: 34px;" for="rb-c1">Auto</label>
<input type="radio" id="rb-c2" value='Audio' name="group-c" /><label style="width: 29px;" for="rb-c2"><img src="include/icon/audio.png" style="height: 15px;"></label>
<input type="radio" id="rb-c3" value='Chaser' name="group-c" /><label style="width: 29px;" for="rb-c3"><img src="include/icon/chaser.png" style="height: 15px;"></label>
<input type="radio" id="rb-c4" value='Collection' name="group-c" /><label style="width: 29px;" for="rb-c4"><img src="include/icon/collection.png" style="height: 15px;"></label>
<input type="radio" id="rb-c5" value='EFX' name="group-c" /><label style="width: 29px;" for="rb-c5"><img src="include/icon/efx.png" style="height: 15px;"></label>
<input type="radio" id="rb-c6" value='RGBMatrix' name="group-c" /><label style="width: 29px;" for="rb-c6"><img src="include/icon/rgbmatrix.png" style="height: 15px;"></label>
<input type="radio" id="rb-c7" value='Scene' name="group-c" /><label style="width: 29px;" for="rb-c7"><img src="include/icon/scene.png" style="height: 15px;"></label>
<input type="radio" id="rb-c8" value='Script' name="group-c" /><label style="width: 29px;" for="rb-c8"><img src="include/icon/script.png" style="height: 15px;"></label>
<input type="radio" id="rb-c9" value='Sequence' name="group-c" /><label style="width: 29px;" for="rb-c9"><img src="include/icon/sequence.png" style="height: 15px;"></label>
<input type="radio" id="rb-c10" value='Video' name="group-c" /><label style="width: 29px;" for="rb-c10"><img src="include/icon/video.png" style="height: 15px;"></label>
</div>
</td>
</tr>
<tr>
<td>
Colour:
</td>
<td>
<div class="toggle-buttons">
<input type="radio" id="rb-d1" value='0' name="group-d" checked="checked" /><label style="width: 34px;" for="rb-d1">Auto</label>
<input type="radio" id="rb-d2" value='1' name="group-d" /><label style="width: 29px;" for="rb-d2"><div class="toggle-box qlcpButtonColor1"> </div></label>
<input type="radio" id="rb-d3" value='2' name="group-d" /><label style="width: 29px;" for="rb-d3"><div class="toggle-box qlcpButtonColor2"> </div></label>
<input type="radio" id="rb-d4" value='3' name="group-d" /><label style="width: 29px;" for="rb-d4"><div class="toggle-box qlcpButtonColor3"> </div></label>
<input type="radio" id="rb-d5" value='4' name="group-d" /><label style="width: 29px;" for="rb-d5"><div class="toggle-box qlcpButtonColor4"> </div></label>
<input type="radio" id="rb-d6" value='5' name="group-d" /><label style="width: 29px;" for="rb-d6"><div class="toggle-box qlcpButtonColor5"> </div></label>
<input type="radio" id="rb-d7" value='6' name="group-d" /><label style="width: 29px;" for="rb-d7"><div class="toggle-box qlcpButtonColor6"> </div></label>
<input type="radio" id="rb-d8" value='7' name="group-d" /><label style="width: 29px;" for="rb-d8"><div class="toggle-box qlcpButtonColor7"> </div></label>
<input type="radio" id="rb-d9" value='8' name="group-d" /><label style="width: 29px;" for="rb-d9"><div class="toggle-box qlcpButtonColor8"> </div></label>
<input type="radio" id="rb-d10" value='9' name="group-d" /><label style="width: 29px;" for="rb-d10"><div class="toggle-box qlcpButtonColor9"> </div></label>
</div>
</td>
</tr>
</table>
</div>
<div class="sidebar" hidden=hidden>
</div>
<div class="sidebarIndexBox" id="textbookID" hidden=hidden>
</div>
</td>
</tr>
</table>
<!-- ******************************************* JS ****************************************************************************************************************** -->
<script>
var qlcpButtonColor_count = 9; // number of select Buttons 1..9
var summernoteActive = false;
var textBookIndexActive = false;
var QLCpConnectedStatus = false;
var onIntervalTimer;
document.querySelector("#clic2editID").onscroll = function() {onScrollText()};
window.addEventListener('beforeunload', function (e) {
// Cancel the event
e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
// Chrome requires returnValue to be set
e.returnValue = '';
});
document.addEventListener('keydown', function(event) {
if (!summernoteActive) {
//console.log(event.keyCode);
let element = document.querySelector('#clic2editID');
if(event.keyCode == 38) {
// key up
element.scrollTop -= 5;
}
else if(event.keyCode == 40) {
// key down
element.scrollTop += 5;
}
else if(event.keyCode == 33) {
// key page up
element.scrollTop -= element.clientHeight;
}
else if(event.keyCode == 34) {
// key page down
element.scrollTop += element.clientHeight;
}
}
});
function onScrollText() {
if(summernoteActive) {
updateTextBookInfo('.note-editable');
}
else {
updateTextBookInfo('#clic2editID');
if (textBookIndexActive) { updateTextBookIndex('#clic2editID'); }
}
}
var toggleHide = function (id) {
let elementTop = document.getElementById(id+'Top');
let element = document.getElementById(id);
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
//elementTop.innerText = "+";
elementTop.innerHTML = '<span style="display: inline-block; transform: rotate(90deg);">></span>';
}
else {
element.setAttribute("hidden", "hidden");
//elementTop.innerText = "-";
elementTop.innerHTML = '>';
}
}
function toggleEditButton(element) {
if (summernoteActive) {
// stop editor mode
element.classList.remove("top-button-on");
save();
if (textBookIndexActive) {
document.getElementById('textbookID').removeAttribute("hidden");
updateTextBookIndex('#clic2editID');
}
}
else {
// start editor mode
element.classList.add("top-button-on");
document.getElementById('textbookID').setAttribute("hidden", "hidden");
document.getElementById('textbookID').innerHTML = "";
edit()
}
}
function toggleTextBookIndexButton(element) {
if (textBookIndexActive) {
// deactivate textbook index
textBookIndexActive = false;
element.classList.remove("top-button-on");
document.getElementById('textbookID').setAttribute("hidden", "hidden");
document.getElementById('textbookID').innerHTML = "";
}
else {
// activate textbook index
textBookIndexActive = true;
element.classList.add("top-button-on");
document.getElementById('textbookID').removeAttribute("hidden");
updateTextBookIndex('#clic2editID')
}
}
function displayButtonToggle(element, className) {
if (element.classList.contains("top-button-off")){
element.classList.remove("top-button-off");
displayEditClass(className, 'inline');
}
else {
element.classList.add("top-button-off");
displayEditClass(className, 'none');
}
}
/* use inline, block, hidden, none */
function displayEditClass(className, display) {
//only affect Buttons in TextBook view mode
Array.from(document.getElementById('clic2editID').querySelectorAll(className)).forEach(function(element) {
element.style.display = display;
});
}
function hideClass(className, hide) {
if (hide) {
Array.from(document.querySelectorAll(className)).forEach(function(element) {
element.setAttribute("hidden", "hidden");
});
}
else {
Array.from(document.querySelectorAll(className)).forEach(function(element) {
element.removeAttribute("hidden");
});
}
}
var markParagraph2playText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child h1color"/>P Play',
tooltip: 'Set paragraph with play style',
click: function () {
context.invoke('formatH1');
}
});
return button.render(); // return button as jquery object
}
var markParagraph2actText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child h2color"/>P Act',
tooltip: 'Set paragraph with act style',
click: function () {
context.invoke('formatH2');
}
});
return button.render(); // return button as jquery object
}
var markParagraph2sceneText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child h3color"/>P Scene',
tooltip: 'Set paragraph with scene style',
click: function () {
context.invoke('formatH3');
}
});
return button.render(); // return button as jquery object
}
var markParagraph2actorlistText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child h4color"/>P Actorlist',
tooltip: 'Set paragraph with actor style',
click: function () {
context.invoke('formatH4');
}
});
return button.render(); // return button as jquery object
}
var markParagraph2pageText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child h6color"/>P Page',
tooltip: 'Set paragraph with page style',
click: function () {
context.invoke('formatH6');
}
});
return button.render(); // return button as jquery object
}
var markText2hintText = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="fa fa-child hint-text-style"/> Hint',
tooltip: 'Hint text style',
click: function () {
// invoke insertText method with 'hello' on editor module.
var text = context.invoke('editor.getSelectedText');
// You can initialize node with class instead of calling addClass.
//alert(html);
//var $node = $(jQuery(html).text());
var html = '<i class="hint-text-style">'+text+'</i>';
//alert($node[0]);
// http://summernote.org/deep-dive/#insertnode
//context.invoke('editor.insertText', text);
context.invoke('editor.saveRange');
context.invoke('editor.pasteHTML', html);
}
});
return button.render(); // return button as jquery object
}
var markText2actorText = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<b class="fa fa-child actor-style"/> Actor',
tooltip: 'Actor name text style',
click: function () {
// invoke insertText method with 'hello' on editor module.
var text = context.invoke('editor.getSelectedText');
var html = '<b class="actor-style">'+text+'</b>';
context.invoke('editor.saveRange');
context.invoke('editor.pasteHTML', html);
}
});
return button.render(); // return button as jquery object
}
var markParagraph2hintText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child hint-text-style"/>P Hint',
tooltip: 'Set paragraph with hint style',
click: function () {
var range = context.invoke('createRange');
var nodes = range.nodes();
for (i=0; i<nodes.length; ++i) {
let node = nodes[i].parentNode;;
if (nodes[i].nodeType === Node.TEXT_NODE) {
let nodeText = nodes[i].nodeValue;
let newNode = document.createElement('p');
newNode.className = "hint-text-style text-size";
newNode.innerHTML = nodeText;
node.parentNode.insertBefore(newNode, node);
node.parentNode.removeChild(node);
}
}
context.invoke('editor.getLastRange');
}
});
return button.render(); // return button as jquery object
}
var autoActorText = function (context) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<b class="fa fa-child"/>P Auto',
tooltip: 'Convert selection into actor text, mark text until first ":" as actor, text between "(..)" as hint and single numbers in a line as page',
click: function () {
var range = context.invoke('createRange');
var nodes = range.nodes();
for (i=0; i<nodes.length; ++i) {
let node = nodes[i].parentNode;;
if (nodes[i].nodeType === Node.TEXT_NODE) {
let nodeText = nodes[i].nodeValue;
let newNode = formatActorText(nodeText);
node.parentNode.insertBefore(newNode, node);
node.parentNode.removeChild(node);
}
}
context.invoke('editor.getLastRange');
}
});
return button.render(); // return button as jquery object
}
// select colour --> https://stackoverflow.com/questions/52310374/adding-custom-colours-to-summernote
var summernoteOptions = {
height: 100, // set editor height
minHeight: null, // set minimum height of editor
maxHeight: null, // set maximum height of editor
tabsize: 4,
focus: true, // set focus to editable area after initializin
toolbar: [
['style', ['style', 'fontname', 'fontsize']],
['font', ['bold', 'italic', 'underline', 'strikethrough', 'color', 'clear']],
/*['color', ['color' , 'forecolor', 'backcolor']],*/
['para', ['ul', 'ol', 'paragraph']],
['table', []],
['insert', ['link', 'picture', 'hr', /*'video',*/ 'table']],
['view', ['undo', 'redo', /*'fullscreen',*/ 'codeview', 'help']],
['misc1', ['pPlayText', 'pActText', 'pSceneText', 'pHintText', 'pActorText', 'pPageText', 'pAutoActor']],
['misc2', ['hintText', 'actorText']]
],
styleTags: [
{ title: 'Play', tag: 'h1', value: 'h1' },
{ title: 'Act', tag: 'h2', value: 'h2' },
{ title: 'Scene', tag: 'h3', value: 'h3' },
{ title: 'Actorlist', tag: 'h4', value: 'h4' },
{ title: 'Page Number', tag: 'h6', value: 'h6' },
{ title: '<tab15/>Actor Text', tag: 'p', className: 'actor-text text-size', value: 'p' },
{ title: 'Hint Text', tag: 'p', className: 'hint-text-style text-size', value: 'p' },
{ title: 'Text', tag: 'p', className: 'text-size', value: 'p3' },
'p', 'div', 'h5', 'pre',
{ title: 'Blockquote', tag: 'blockquote', className: 'blockquote', value: 'blockquote' }
],
buttons: {
pPlayText: markParagraph2playText,
pActText: markParagraph2actText,
pSceneText: markParagraph2sceneText,
pActorText: markParagraph2actorlistText,
pPageText: markParagraph2pageText,
pAutoActor: autoActorText,
pHintText: markParagraph2hintText,
actorText: markText2actorText,
hintText: markText2hintText
}
}
function formatActorText(pText) {
if (Number.isInteger(+pText)) {
// Detect Page number if it includes only a number
// result e.g.
// <h6>17</h6>
let node = document.createElement('h6');
node.innerHTML = pText;
return node;
}
else {
// Parse actor name and text format
// result e.g.
// <p class="actor-text text-size"><b class="actor-style">Hans:</b> hallo <i class="hint-text-style">(sagt er)</i> das ist halt so</p>
// <p class="actor-text text-size"><b class="actor-style">Hans </b><i class="hint-text-style">(wartet)</i><b class="actor-style">:</b> Hallo zusammen</p>
let node = document.createElement('p');
node.className = "actor-text text-size";
// Find and format actor name, search for : and uns actor-style, search one time for ( ) and use hint-text-style
let actText = "";
let pos = pText.search(':') + 1;
let p1 = -1;
let p2 = -1;
if (pos > 0) {
actText = pText.substr(0, pos);
p1 = actText.indexOf("(");
if (p1 >= 0 ) {
let actName1 = "";
let actInfo = "";
let actName2 = "";
p2 = actText.indexOf(")", p1) + 1;
if (p2 > 0 && p2 > p1) {
//nop
}
else {
p2 = pos-1;
}
actName1 = actText.substr(0, p1);
actInfo = actText.substr(p1, p2-p1);
actName2 = actText.substr(p2);
actText = actName1 +'</b><i class="hint-text-style">'+ actInfo +'</i><b class="actor-style">'+ actName2
}
actText = '<b class="actor-style">' + actText + '</b>';
}
// If no actor name found start with indent
if (actText === "") {
actText = '<tab15/>'
}
// Find and format actor text, search for ( ) and use hint-text-style
let oText = pText.substr(pos);
let nText = "";
p1 = 0;
p2 = 0;
while(true) {
p1 = oText.indexOf("(", p2);
if (p1 >= 0) {
nText += oText.substr(p2, p1-p2) + '<i class="hint-text-style">';
p2 = oText.indexOf(")", p1) + 1;
if (p2 > 0) {
nText += oText.substr(p1, p2-p1) + '</i>';
}
else {
nText += oText.substr(p1) + '</i>';
break;
}
}
else {
nText += oText.substr(p2);
break;
}
}
node.innerHTML = actText + nText;
return node;
}
}
function resizeFunction() {
if (summernoteActive) {
let summernoteToolbarHeigth = document.querySelector(".note-toolbar").offsetHeight;
let newHeigth = window.innerHeight - $('.summernotetab').offset().top - summernoteToolbarHeigth - 41 ; // additional 41px are needed to avoid scrolling, 40 FF, 41 Chrome
summernoteOptions.height = newHeigth;
summernoteOptions.minHeight = newHeigth;
summernoteOptions.maxHeight = newHeigth;
let content = $('.click2edit').summernote('code');
$('.click2edit').summernote('destroy');
$('.click2edit').summernote(summernoteOptions);
$('.click2edit').summernote('code', content);
document.querySelector(".note-editable").onscroll = function() {onScrollText()}; // needs to be redone after summernote destroy
//onScrollText();
}
else {
//onScrollText()
//updateTextBookInfo('#clic2editID');
//if (textBookIndexActive) { updateTextBookIndex('#clic2editID'); }
}
onScrollText();
}
function onloadFunction() {
connectQLCpWebSocket('127.0.0.1:9999', QLCpConnected);
onScrollText();
}
function QLCpConnected(status) {
//alert("QLC+ connection status: " + status);
if (status === 'onopen') {
QLCpConnectedStatus = true;
}
else if (status === 'onclose') {
QLCpConnectedStatus = false;
}
else if (status === 'onerror') {
alert("QLC+ connection error!");
}
if (QLCpConnectedStatus) {
document.getElementById('QLCpConnStatus').innerHTML = '<img src="include/icon/QLCp.png"> <font color=green>Connected</font>';
document.getElementById('QLCpConnButton').value = "Reload";
getQLCpFunctionList(QLCpFunctionRead);
}
else {
document.getElementById('QLCpConnStatus').innerHTML = '<img src="include/icon/QLCp_off.png"> <font color=red>Not connected</font>'
document.getElementById('QLCpConnButton').value = "Connect";
}
}
function QLCpFunctionRead() {
//alert("QLCpFunctionRead");
// update and check the function Buttons!!!!
editorSidebarTree();
updateQLCpButton();
}
function loadFile() {
document.getElementById('loadFileinput').click();
}
function readFile(e) {
var file = e.target.files[0];
if (!file) return;
var reader = new FileReader();
reader.onload = function(e) {
//document.getElementById('contents').innerHTML = e.target.result;
if (summernoteActive) {
$('.click2edit').summernote('code', content.split(fileDelimiterTag)[1]);
}
else {
$('.click2edit').html(e.target.result.split(fileDelimiterTag)[1]);
}
onScrollText();
if (QLCpConnectedStatus) {
getQLCpFunctionList(QLCpFunctionRead);
// updateQLCpButton(); is done in callback
}
}
reader.readAsText(file)
}
async function saveFile() {
if (summernoteActive) {
// create the BLOB object
var markup = $('.click2edit').summernote('code');
markup = fileHtmlPreData + fileDelimiterTag + markup + fileDelimiterTag + fileHtmlPostData;
var myBlob = new Blob([markup], {type: "text/plain"});
if ("undefined" == typeof window.showSaveFilePicker) {
// no File Picker - use download
let downloadLink = document.createElement("a");
downloadLink.href = window.URL.createObjectURL(myBlob);
downloadLink.download = "QLCp-TextBookData.html";
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click();
}
else {
try{
// file handler & file stream
const fileHandle = await window.showSaveFilePicker({
suggestedName: "QLCp-TextBookData.html",
types: [{
description: "Text file",
accept: {"text/html": [".html"]}
}]
});
const fileStream = await fileHandle.createWritable();
// write file
await fileStream.write(myBlob);
await fileStream.close();
}
catch (error) {
if (error.message !== 'The user aborted a request.') {
alert(error);
}
}
}
}
}
function save() {
//alert('close');
//var lastRange = $('.click2edit').summernote("editor.getLastRange").ec;
//alert(lastRange);
// Get old scroll position from Editor view
let element = document.querySelector('.note-editable');
let viewWinScroll = element.scrollTop;
let viewHeight = element.scrollHeight - element.clientHeight;
let viewScrolled = viewWinScroll / viewHeight;
clearInterval(onIntervalTimer);
var markup = $('.click2edit').summernote('code');
$('.click2edit').summernote('destroy');
summernoteActive = false;
document.getElementById("saveFileID").disabled = true;
document.getElementById("tbButtonID").disabled = false;
// Resore hided QLCP buttons
for (i = 1; i <= qlcpButtonColor_count; i++) {
let element = document.getElementById("hideButton"+i);
element.disabled = false;
if(element.classList.contains("top-button-off")) {
displayEditClass('.qlcpButtonColor'+i, 'none');
}
}
// Hide Sidebar
hideClass('.sidebarTop, .sidebar', true);
//Array.from(document.querySelectorAll('.sidebarTop, .sidebar')).forEach(function(element) {
// element.setAttribute("hidden", "hidden");
//});
// Set scroll Position in Text view info
element = document.querySelector('#clic2editID');
viewHeight = element.scrollHeight - element.clientHeight;
viewWinScroll = viewScrolled * viewHeight;
element.scrollTop = viewWinScroll;
// Editor no longer active, update Text View
onScrollText();
};
function edit() {
// schow all QLCP buttons
for (i = 1; i <= qlcpButtonColor_count; i++) {
displayEditClass('.qlcpButtonColor'+i, 'inline');
document.getElementById("hideButton"+i).disabled = true;
}
// Get old scroll position from Text view
let element = document.querySelector('#clic2editID');
let viewWinScroll = element.scrollTop;
let viewHeight = element.scrollHeight - element.clientHeight;
let viewScrolled = viewWinScroll / viewHeight;
// Show Sidebar
hideClass('.sidebarTop, .sidebar', false)
summernoteActive = true;
document.getElementById("saveFileID").disabled = false;
document.getElementById("tbButtonID").disabled = true;
document.getElementById("scrollProgressBarID").style.width = 0; // Scroll Bar off
document.getElementById("h1infoID").innerText = '';
document.getElementById("h2infoID").innerText = '';
document.getElementById("h3infoID").innerText = '';
document.getElementById("h4infoID").innerText = '';
document.getElementById("h5infoID").innerText = '';
document.getElementById("h6infoID").innerText = '';
let newHigth = window.innerHeight - $('.summernotetab').offset().top - 83 ; // additional 82px are needed to avoid scrolling
//alert($('.summernotetab').height() + " " + $(document).height() + " " + window.innerHeight );
//alert(newHigth + " " + document.getElementById("click2edit").clientHeight);
//alert(newHigth + " " + $('.summernotetab').height() + " " + $('.summernotetab').outerHeight() + " " + (window.innerHeight - $('.summernotetab').offset().top - 82) );
summernoteOptions.height = newHigth;
summernoteOptions.minHeight = newHigth;
summernoteOptions.maxHeight = newHigth;