-
Notifications
You must be signed in to change notification settings - Fork 0
/
babindex.html
2224 lines (1713 loc) · 96.9 KB
/
babindex.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 lang="en-GB">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description"
content="BeagAirBheag study toolkit: Player, Transcript viewer, Dictionary Links, Note faciities" />
<meta name="keywords" content="beagairbheag" />
<!-- indexedDb promises-version from https://github.com/jakearchibald/idb-->
<script src="https://unpkg.com/idb@5/build/iife/index-min.js"></script>
<title>BeagAirBheag Companion</title>
<link rel="shortcut icon" href="https://ngatesystems.com/beagairbheag/bab.png">
<style>
.fugitivebutton {
height: 4vw;
width: 4vw;
margin: 2vw 1vw 2vw 1vw;
}
.audiobutton {
height: 4vw;
width: 4vw;
border: none;
background-size: 50% 50%;
background-color: white;
background-repeat: no-repeat;
background-position: center;
outline: none;
}
.notemark {
max-height: 3vh;
background: white 0.0;
}
.splashscreen {
max-width: 100%;
max-height: 100%;
margin-left: auto;
margin-right: auto;
display: block;
cursor: pointer;
}
.babbutton {
padding: .25rem;
font: larger;
background-color: aquamarine;
border: 1px solid black;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<!--HTML5 audio-->
<audio id="music" type="audio/mpeg">
</audio>
<div style="display: flex; flex-direction: column;">
<!--############ Page header - Fugitive buttons and Player Controls ############# -->
<div id="pageheader" style="display: flex;height: 100%;justify-content: space-between; text-align: center;">
<!-- The controls are displayed centred between balancing banks of "fugitive" buttons. The idea is to avoid
cluttering the page- the buttons are only displayed when the mouse moves over them. -->
<div id='buttondiv1' style="opacity:1;" onmouseover="displayButtonDiv('buttondiv1');"
onmouseout="fadeButtonDiv('buttondiv1');">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/txtsearch.svg"
title="Click to Search BaB texts and Notes" onclick="setActivityPanelToElement('textsearchpanel');">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/jtrlaunch.svg"
title="Click to open your Jotter" onclick="displayJotter();">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/ggllaunch.svg"
title="Click to open the Google Translator"
onclick="event.stopPropagation(); displayPopupWindow('https://translate.google.com/?sl=gd&tl=enL');">
</div>
<div style="height:4vw; margin: 2vw; border-style: solid;border-width: thin;">
<div style="display: inline-flex; justify-content: center; align-items: center;">
<div>
<button id="pbutton" class="audiobutton"
style="background-image: url('https://ngatesystems.com/beagairbheag/img/play.png');"
onclick="toggleAudio();" ; title="Start or stop the audio-player" type="button"></button>
<button class="audiobutton"
style="background-image: url('https://ngatesystems.com/beagairbheag/img/rplay.png');"
onclick="rewindAudio();"
title="Dè thuirt e? - Rewind the audio-player 5 seconds and restart (alternatively use scroll wheel over playhead)"
type="button"></button>
<button class="audiobutton"
style="background-image: url('https://ngatesystems.com/beagairbheag/img/shriek.png');"
title="Create a note"
onclick="pauseAudio(); postTime=Math.floor(music.currentTime); setActivityPanelToElement('insertnotepanel'); document.getElementById('cnotetext').focus();"
type="button"></button>
</div>
<div style="padding: 0 2vw 0 1vw;">
<span id="currtime">00:00:00</span>/
<span id="finishtime"></span>
</div>
</div>
</div>
<div id='buttondiv2' style="opacity:1;" onmouseover="displayButtonDiv('buttondiv2');"
onmouseout="fadeButtonDiv('buttondiv2');">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/backup.svg?"
title="Copy your jotter and notes to local storage" onclick="backupDataStores();">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/restore.svg?"
title="Restore your jotter and notes from local backup filesf"
onclick="event.stopPropagation(); uploadBackupFile();">
<img class="fugitivebutton" src="https://ngatesystems.com/beagairbheag/img/mark.svg?"
title="Click for Colin Mark Translations Workshops"
onclick="event.stopPropagation(); displayColinMarkWindow(event);">
</div>
</div>
<!-- ############ Audio Header - Note line, Play line and Text line ############# -->
<div id="audioheader" style="
width: 95%;
padding-left: .25vw;
padding-right: .25vw;
margin: auto;
margin-bottom: 4vh;
border: solid;">
<!-- Display an empty noteline - we'll fill this in dynamically later-->
<div id="noteline" style="height: 3vh; margin-top: .5vh; background: whitesmoke;"
title="Marks on this line indicate the position of notes on the audio">
<a id="nsample" style="position:absolute; margin-left: 0px;">
<img class="notemark" src="https://ngatesystems.com/beagairbheag/img/notemarkblack.svg"></a>
<div id="notes"></div>
</div>
<!-- Now the soundbar - ditto, but with the playhead already seeded within it -->
<div id="playline" style="
width: 100%;
background: rgba(0,0,0,.3);
margin-top: .5vh;
margin-bottom: .5vh;
border-radius: 999px;">
<!-- forces radius to be half the height-->
<div id="playhead" style="
cursor: pointer;
width: 4vh;
height: 4vh;
border-radius: 50%;
background: black;"></div>
</div>
<!-- And finally Text bar. -->
<div id="textline" style="height:4vh; margin-top: 1vh; margin-bottom: 1vh;">
</div>
</div>
<!-- ############ Panel Header - Logo panel, Activity panel and Episode panel ############# -->
<!-- flex-grow is used here to allow the children divs of the panel header to occupy
the remaining space on the page without defining height exlicitly -->
<div id="panelheader" style="
display:flex;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;">
<!-- First of all, the "Beag air Bheag" Logo panel, the leftmost of the three display panels-->
<div id="logopanel" style="
width: 25%;
margin: 3vw;
overflow: auto;">
<div id="logoandbuttons">
<img id="logo" style="max-width:100%;" src="https://ngatesystems.com/beagairbheag/img/logo.png"
alt="Beag Air Bheag Companion logo">
<p></p>
<div style="margin-top: 1vh; margin-left: 1vw;">
<button class="babbutton" onclick="setActivityPanelToString(about);" type="button"
title="About the Companion">About
</button>
<button class="babbutton" onclick="setActivityPanelToString(hints);" type="button"
title="Click for Hints">Hints
</div>
</div>
</div>
<!-- Now the multi-function activity panel-->
<div id="activitypanel" style="
width: 50%;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
margin-left: 3vw;
margin-right: 3vw;
padding: 1vw;
border: solid black;
overflow-y: auto;
height: 53vh;">
</div>
<!-- And finally, the "Episode" panel the rightmost of the three display panels-->
<div id="episodepanel" style="
width: 25%;
margin-right: 3vw;
overflow: auto;">
<p><strong>
Now Playing : Series <span id="seriesnum"></span> : <span id="episodenam"></strong>
</p>
<p>First broadcast : <span id="firstondate"></span></p>
<p>Learner of the Week : <span id="learneroftheweek"></span></p>
<p><strong>Want a different programme? </strong></p>
<p>Series <span id="seriespicklistcontainer"></span> : <span id="episodepicklistcontainer"></span></p>
<br>
<p>Current dictionary : <button id="dictionarypref" class="babbutton"
title="Toggle text look-up dictionary" onclick="toggleDictionaryPref()"></button></p>
<p id="currentsplashscreen">Current splash-screen:<br>
<i id='splashscreentitle' style="margin-left:1vw; display: block;"></i></p>
</div>
</div>
</div>
<!-- hidden jotterdiv panel displayed as fixed-size "popup" -->
<div id="jotterdiv" style="
display: none; width: 80%; height: 80%;
position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0; top: 5%;
padding: 3vh 2vw 2vh 2vw; border: 1px solid black;
background: white;
z-index: 10;" onclick="event.stopPropagation();">
<form enctype="multipart/form-data" method="post" name="jotterform" style="width: 100%; height:90%;">
<input type="text" name="action" hidden value="U">
<textarea id="userjotter" name="user_jotter"
style="width:100%; height: 100%; font-size: larger; background:paleturquoise;"
onkeydown="keyPresedOnJotter(event);" spellcheck="false"></textarea>
</form>
<p><button id="jottersavebutton" class="babbutton" type="button" onclick="saveJotter();">Save</button>
<span id="savemessage" style="margin-left: 3vw;"></span>
</p>
</div>
<!-- hidden zoomdiv panel displayed as fixed-size "popup" -->
<div id="zoomdiv" style="
display: none; width: 80%; height: 80%;
position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0; top: 5%;
padding: 1vh 2vw 1vh 2vw; border: 1px solid black;
background: white;
text-align: center;
z-index: 10;" onclick="event.stopPropagation();">
<img id="zoomedimage" style="height: 100%;">
</div>
<!-- hidden text for the 'insertnotepanel' -->
<span id='insertnotepanel' style="display: none;">
<div style="
display: flex;
width: 60%;
margin: 5% auto;
border-style: solid;
border-width: thin;
padding: 1.5%;
justify-content: space-around;">
<div><button id="lBiteButton" title="Start the sound-bite one second ealier" onclick="playBiteNudgedLeft();"
type="button">Nudge L</button></div>
<div><button id="pBiteButton" title="Play a five-second sound-bite centred on the current time"
onclick="postTime=Math.floor(music.currentTime); playBite();" type="button">Play</button></div>
<div><button id="rBiteButton" title="Start the sound-bite one second later" onclick="playBiteNudgedRight();"
type="button">Nudge R</button></div>
</div>
<p style="text-align: center">Note/Query text</p>
<textarea id="cnotetext" rows="4" cols="50" style="margin: 5px auto; display: block;" name="cnotetext"
title="Notes on sound - eg 'jay hoorshht e' = dè thuirt e : what did he say?"></textarea>
<div style="
display: flex;
width: 60%;
margin: 5% auto;
border-style: solid;
border-width: thin;
padding: 1.5%;
justify-content: space-around;">
<div><button class="babbutton" onclick="insertNote('note')" type="button">Save as Note</button></div>
<div><button class="babbutton" onclick="insertNote('query')" type="button">Save as Query</button></div>
<div><button class="babbutton" onclick="setActivityPanelToString('');" type="button">Cancel</button></div>
</div><br>
</span>
<!-- hidden text for the 'editnotepanel' -->
<span id='editnotepanel' style='display: none;'>
<div style='margin: 20px auto; text-align: center;'>
<button id='enBiteButton' class="babbutton" type='button'
title="Replay the five-second sound-bite centred on this note" onclick="playBiteInEditPanel();">Play
Again</button>
</div>
<textarea id='enotetext' rows='4' cols='50' name='ecnotetext' style='margin: 5px auto; display: block;'
onkeydown="document.getElementById('saveeditednotebutton').style.background = 'pink';">
</textarea>
<div style='
display: flex;
border-style: solid;
border-width: thin;
margin: 5% auto;
width: 15%;
padding: 1.5%;
justify-content: center;'>
<button id="saveeditednotebutton" class="babbutton" title='Save edited Note' type='button'>Save</button>
</div>
<div style='
display: flex;
width: 60%;
margin: 5% auto;
border-style: solid;
border-width: thin;
padding: 1.5%;
justify-content: space-around;'>
<button id='changetoquerybutton' class="babbutton" style='display: none;'
title='Change note type to "Query"' type='button'>
Re-save as Query</button>
<button id='changetonotebutton' class="babbutton" style='display: none;' title='Change note type to "Note"'
type='button'>
Re-save as Note</button>
<button id='deletenotebutton' class="babbutton" title='Delete Note' type='button'>Delete</button>
<button type='button' class="babbutton" onclick='setActivityPanelToString("");'>Cancel</button>
</div>
</span>
<!-- hidden text for the 'textsearchpanel' -->
<div id="textsearchpanel" style="display: none; width: 25vw; padding: 2vw">
<p> <label>Search for:</label>
<input id="searchstring" type="text" name="search_words" title="Search string" autofocus size="24"
onKeyPress="trackSearchStringEntry(event)"></p>
<p> <button id="searchbutton" class="babbutton" type="button" onclick="searchTextsAndNotes()">Launch
Search</button> </p>
</div>
<!-- utilities - empty form for the XMLHTTP PHP calls, "spinner for text loads and empty anchor for backup downloads -->
<form id='dummyform'>
</form>
<div id="waiticon" style="position: fixed; z-index: 10; display: none">Loading...
</div>
<a id="backupdownloadlink" download></a>
<script>
var currentSystemVersionNumber = "1.20";
var latestSystemVersionNumber;
var cryptography; // text for cryptography, about and hints will be served from central sources
var about;
var hints;
// The Companion uses numerous centrally-served .svg, .png, .php and .html elements. But changing the server
// copy won't necessarily mean that a Cmopanion user will see the changes because the browser
// will continue to use cached local copies until these become "stale" - which
// may take a few weeks. For php elements, the problem is side-stepped by "pre-staling" the code using
// headers. For html elements, we fool the browser by adding a date-time "GET" parameter (they're called
// so rarely that the associated inefficientcy is insignificant). The numerous graphic elements are a
// different story, however. On balance it seems best to leave alone - nothing is going to change that
// would prejudice operation of the Companion.
///// Screen Management Scripts //////////
// Does local storage contains 'last programme used' details? - (use localStorage.removeItem("lastSeriesNum")
// to clear whn testing)
if (localStorage.getItem('lastSeriesNum') === null) {
// no it doesn't - so initialise them as Series 12 Episode 1
localStorage.setItem('lastSeriesNum', '12');
localStorage.setItem('lastEpisodeNam', 'Episode 1');
localStorage.setItem('lastEpisodeFinishTime', '5421');
localStorage.setItem('lastFirstOnDate', '2020/06/14');
localStorage.setItem('lastLearnerOfTheWeek', 'Kevin Leetion');
localStorage.setItem('lastBBCProgrammeUrl', 'https://www.bbc.co.uk/programmes/m000k423');
localStorage.setItem('lastDictionaryPref', 'BBC');
localStorage.setItem('lastSplashScreenFilename', 'red_book.png');
localStorage.setItem('lastSplashScreenTitle', '"Leabhar Dearg Chlann Mhuirich - courtey Scottish Nat Coll');
localStorage.setItem('lastBBCDownloadFilename', 'BeagAirBheag-20200614-Episode1');
}
// OK can now initialise "current" user and programme variables from
// stable local storage values with known initial settings
var currentSeriesNum = localStorage.getItem('lastSeriesNum');
var currentEpisodeNam = localStorage.getItem('lastEpisodeNam');
var currentEpisodeFinishTime = localStorage.getItem('lastEpisodeFinishTime'); // mmss
var currentFirstOnDate = localStorage.getItem('lastFirstOnDate'); // formatted date (JS date-formatting is rubbish)
var currentLearnerOfTheWeek = localStorage.getItem('lastLearnerOfTheWeek');
var currentBBCProgrammeUrl = localStorage.getItem('lastBBCProgrammeUrl');
var currentDictionaryPref = localStorage.getItem('lastDictionaryPref');
var currentSplashScreenFilename = localStorage.getItem('lastSplashScreenFilename');
var currentSplashScreenTitle = localStorage.getItem('lastSplashScreenTitle');
var currentBBCDownloadFilename = localStorage.getItem('lastBBCDownloadFilename');
var playWidth;
var headWidth;
var noteWidth;
var duration;
var textTypesData; // global array of text-type data
// define startupSplashScreen - you get this only when you use BaB for the very first time
var startupSplashScreenContent = " \
<p style='text-align: center;'> \
<strong>Gàidhlig and Cryptography</strong><br><br> \
The entertaining and thought-provoking novels of Neal Stephenson make frequent reference to the isles of \
Qwhglm (pronounced 'Taghum', with stress on the second syllable), mythically located off the west coast \
of Scotland. The inhabitants, naturally, speak Qwghlmian, an impenetrable language employing just 16 \
consonant and no vowels. Qwghlmian is thus ideally suited to cryptographic applications. Hmm. Very funny, \
I'm sure. \
</p>";
var startupSplashScreenTitle = "Qwghlmian";
var activitypanel = document.getElementById("activitypanel");
window.onload = function () {
// launch a few low-priority asynch operations in parallel
getLatestSystemVersionNumber(); // won't need this until user clicks 'about'
initialiseTextTypeData(); // won't need this until we display the texts line
// make sure we've got an indexedDB database with all the necessary datastores
initialiseIndexedDBStores();
// fade the fugitive buttons by triggering a transition
fadeButtonDiv('buttondiv1');
fadeButtonDiv('buttondiv2');
// get the picklists and build the screen
buildProgrammePicklists(currentSeriesNum, currentEpisodeNam)
}
async function getLatestSystemVersionNumber() {
// get latest system version number - low priority asynch operation
var fData = new FormData(document.getElementById("dummyform"));
fData.append("helper_type", "get_system_data");
try {
const response = await get("https://ngatesystems.com/beagairbheag/php/player_helpers_v1.10.php", fData)
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
const JSONObject = JSON.parse(response);
latestSystemVersionNumber = JSONObject.versionnumber;
cryptography = JSONObject.cryptography;
about = JSONObject.about;
hints = JSONObject.hints;
var aboutHeader = "<p style = 'text-align: center; color:blue;''>\
You are currently using version v" + currentSystemVersionNumber + " of the Companion.";
if (latestSystemVersionNumber > currentSystemVersionNumber) {
var dateObject = new Date();
var currentTime = dateObject.getTime();
aboutHeader += "The latest version is v" + latestSystemVersionNumber + ". Click \
<a href = 'https://ngatesystems.com/beagairbheag/index.html?ver=" + currentTime + "' >here</a> if you would like to upgrade";
} else {
aboutHeader += "This is the latest version of the Companion.";
}
about = aboutHeader + "</p>" + about;
}
}
catch (err) {
alert("Failed! " + err);
return;
}
}
async function initialiseTextTypeData() {
// launch initialisation of textTypesData (header info) - another low priority asynch operation
var fData = new FormData(document.getElementById("dummyform"));
fData.append("helper_type", "get_text_types_data");
try {
const response = await get("https://ngatesystems.com/beagairbheag/php/player_helpers_v1.10.php", fData)
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
textTypesData = JSON.parse(response);
}
}
catch (err) {
alert("Failed! " + err);
return;
}
}
async function initialiseIndexedDBStores() {
const db = await idb.openDB('BaB', 1, {
// the following code is only activated if the database
// has never been opened before
upgrade(db) {
// Create a "notes" store for noteObjects
const notesStore = db.createObjectStore('notes', {
// The 'textkey' property of the textObject will be the key.
keyPath: 'notekey',
});
// Create an index on the 'notekey' property of noteObjects.
notesStore.createIndex('notes_by_key_path', 'notekey');
// Create a secondary non-unique index on the 'noteprogrammekey' property of noteObjects.
notesStore.createIndex('notes_by_programme_path', 'noteprogrammekey', { unique: false });
// Create a "texts" store for textObjects
const textsStore = db.createObjectStore('texts', {
// The 'textkey' property of the textObject will be the key.
keyPath: 'textkey',
});
// Create an index on the 'textkey' property of the textObjects.
textsStore.createIndex('texts_by_key_path', 'textkey');
// Create a "jotter" store forthe jotterObject
const jotterStore = db.createObjectStore('jotter', {
// The 'jotterkey' property of the jotterObject will be the key.
keyPath: 'jotterkey',
});
// Create an index on the 'jotterkey' property of the jotterObjects.
jotterStore.createIndex('jotter_by_key_path', 'jotterkey');
},
});
// put an initial empty jotter record into the jotter store for key
// 'user' if this doesn't already exist
{
const tx = db.transaction('jotter', 'readwrite');
var jotterObject = { 'jotterkey': 'user', 'text': '' };
try {
await Promise.all([
tx.store.add(jotterObject), // only a single store in play, so "store" references this automatically
tx.done,
]);
} catch (e) {
const recordAlreadyExists = 'Key already exists in the object store.';
if (e.toString().indexOf(recordAlreadyExists) != -1) {
return;
} else {
alert("Failed! " + e);
return;
}
}
}
}
async function buildProgrammePicklists(seriesNum, episodeNam) {
var fData = new FormData(document.getElementById("dummyform"));
fData.append("helper_type", "build_programme_picklists");
fData.append("series_num", seriesNum);
fData.append("episode_nam", episodeNam);
try {
const response = await get("https://ngatesystems.com/beagairbheag/php/player_helpers_v1.10.php", fData)
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
const JSONObject = JSON.parse(response);
seriesPicklist = JSONObject.seriespicklist;
episodePicklist = JSONObject.episodepicklist;
document.getElementById('seriespicklistcontainer').innerHTML = seriesPicklist;
document.getElementById('episodepicklistcontainer').innerHTML = episodePicklist;
buildScreenForCurrentEpisode();
if (currentSeriesNum != '') music.src = currentBBCDownloadFilename + ".mp3";
music.currentTime = 0;
}
}
catch (err) {
alert("Failed! " + err);
}
}
var audioExceptionMessageJustDisplayed = false;
var scaleFactor;
var scaleCorrectionForNote;
function buildScreenForCurrentEpisode() {
// display the splashscreen for this instance of the Companion
// choose a splashscreen (use localStorage.removeItem('firstuseofbab'); to test
if (localStorage.getItem('firstuseofbab') === null) {
setActivityPanelToString(startupSplashScreenContent);
document.getElementById('splashscreentitle').innerHTML = startupSplashScreenTitle;
document.getElementById('currentsplashscreen').style.display = "block";
localStorage.setItem('firstuseofbab', 1);
} else {
setActivityPanelToString('<img class="splashscreen" onclick="zoomSplashScreen(); event.stopPropagation();" src="https://ngatesystems.com/beagairbheag/splashscreens/' + currentSplashScreenFilename + '">');
document.getElementById('splashscreentitle').innerHTML = currentSplashScreenTitle;
document.getElementById('currentsplashscreen').style.display = "block";
}
duration = timeToSeconds(currentEpisodeFinishTime);
document.getElementById('finishtime').innerHTML = formatTime(duration);
document.getElementById('seriesnum').innerHTML = currentSeriesNum;
document.getElementById('episodenam').innerHTML = currentEpisodeNam;
document.getElementById('firstondate').innerHTML = currentFirstOnDate;
document.getElementById('learneroftheweek').innerHTML = currentLearnerOfTheWeek;
document.getElementById("dictionarypref").textContent = currentDictionaryPref;
// get the pixel widths of the playline and playhead - these are key parameter
// used throughout the rest of the layout, determining the absolute position of
// notes, playhead and texts in the audioheader
// Also use the sample note mark to get the scaled width of the notemark image -
// this is used to position the centre of the mark precisely
playWidth = document.getElementById('playline').getBoundingClientRect().width; // floating point number
headWidth = document.getElementById('playhead').getBoundingClientRect().width;
noteWidth = document.getElementById('nsample').getBoundingClientRect().width;
// We calculate the left margin of a note img at time t seconds as :
// (0.5 * headWidth) + (t * (playWidth- headWidth) / duration) - (0.5* noteWidth)
// or t*scaleFactor + scaleCorrectionForNote
scaleFactor = (playWidth - headWidth) / duration;
scaleCorrectionForNote = (0.5 * headWidth) - (0.5 * noteWidth); // note this is a floating point number
buildNoteline(currentSeriesNum, currentEpisodeNam, scaleFactor, scaleCorrectionForNote);
// We calculate the left margin of a text img at time t seconds as :
// (0.5 * headWidth) + (t * (playWidth - headWidth) / duration)
// or t*scaleFactor + scaleCorrectionForText
// We calculate the length of a text as rightMargin - leftMargin
var scaleCorrectionForText = (0.5 * headWidth);
buildTextsline(currentSeriesNum, currentEpisodeNam, scaleFactor, scaleCorrectionForText);
// add an event listener for the 'music' audio tag. The "true" value in the third
// parameter means the event is captured in the capturing phase
music.addEventListener('error', function (e) {
var noSourcesLoaded = (this.networkState === HTMLMediaElement.NETWORK_NO_SOURCE);
if (noSourcesLoaded) {
var alertMessage = "\
<div style = 'text-align: center;'>\
Oops - can't find your download file at : <br><br>\
<div style = 'color: red; overflow-y: auto;'>" + music.src + "</div>\
<br><br>You need to download this podcast from its BBC download page at :\
<div style = 'margin-top: 2vh; margin-bottom: 2vh; text-align: center;'>\
<button class = 'babbutton' onclick = 'window.open(\"" + currentBBCProgrammeUrl + "\", \"_blank\");'>BBC Episode Download Page</button>" + "\
</div>\
and wait for the file to appear fully in your download folder. If you are\
running the Companion from the download folder you should now be able to launch the\
episode by simply clicking the 'Play' button. Otherwise you will first need to\
move the downloaded file manually to the new babindex location.\
</div>";
setActivityPanelToString(alertMessage);
audioExceptionMessageJustDisplayed = true;
}
}, true);
}
function toggleDictionaryPref() {
if (currentDictionaryPref == "BBC") {
currentDictionaryPref = "AFB";
} else {
currentDictionaryPref = "BBC";
}
document.getElementById("dictionarypref").textContent = currentDictionaryPref;
//set local storage
localStorage.setItem('lastDictionaryPref', currentDictionaryPref);
}
var noteLeftMargins = [];
async function buildNoteline(seriesNum, episodeNam, scaleFactor, scaleCorrectionForNote) {
// clear away any existing NoteLine content
document.getElementById('notes').innerHTML = "";
const db = await idb.openDB('BaB', 1);
const tx = db.transaction('notes', 'readwrite');
// Get the contents of "notes", for series seriesNum and episode episodeNam
var noteProgrammeKey = currentSeriesNum + "%" + currentEpisodeNam;
const noteObjects = await db.getAllFromIndex('notes', 'notes_by_programme_path', noteProgrammeKey);
var noteLine = '';
if (noteObjects != undefined) {
for (var i = 0; i < noteObjects.length; i++) {
var noteKey = noteObjects[i].notekey;
var noteKeyElements = noteKey.split("%");
var secondsIntoProgramme = noteKeyElements[2];
var noteText = noteObjects[i].notetext;
var noteType = noteObjects[i].notetype;
var marginLeft = Math.round((secondsIntoProgramme * scaleFactor) + scaleCorrectionForNote);
var noteTextStub = noteText;
if (noteText.length > 15) noteTextStub = noteText.substring(0, 15) + ' ...';
noteLine += "\
<a id='n" + secondsIntoProgramme + "'\
style='position:absolute; margin-left: " + marginLeft + "px; cursor: pointer; width: 5px; text-align: center;' \
title='" + noteTextStub + "'\
onclick = 'displayEditNotePanel(\"n" + secondsIntoProgramme + "\");'>";
if (noteType === "note") {
noteLine += "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkblack.svg'></a>";
} else {
noteLine += "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkred.svg'></a>";
}
// create an entry in the noteLeftMargins array - we use this later to prevent the user from
// creating notes that are so close together they obscure each other
noteLeftMargins.push(marginLeft);
}
document.getElementById('notes').innerHTML = noteLine;
noteLeftMargins.sort(function (a, b) { return a - b }); // sort the left margins in ascending numerial order
}
}
async function buildTextsline(seriesNum, episodeNam, scaleFactor, scaleCorrectionForText) {
var fData = new FormData(document.getElementById("dummyform"));
fData.append("helper_type", "build_textline");
fData.append("series_num", seriesNum);
fData.append("episode_nam", episodeNam);
fData.append("scale_factor", scaleFactor);
fData.append("scale_correction_for_text", scaleCorrectionForText);
try {
const response = await get("https://ngatesystems.com/beagairbheag/php/player_helpers_v1.10.php", fData)
if (response.indexOf("%failed%") != -1) {
alert(response);
} else {
document.getElementById('textline').innerHTML = response;
}
}
catch (err) {
alert("Failed! " + err);
}
}
async function insertNote(noteType) {
// insert a note of the given type for the current series and episode into the notes datastore
var postTimeAsInteger = Math.round(postTime);
var newnote = document.getElementById("n" + postTimeAsInteger);
var marginLeft = (0.5 * headWidth) + (postTimeAsInteger * (playWidth - headWidth) / duration) - (0.5 * noteWidth);
if (newNoteTooCloseToExisting(marginLeft)) {
alert('Oops - this note is too close to an existing note');
return;
}
var noteText = document.getElementById('cnotetext').value;
// noteKey is constructed from the following four components:
// ** seriesNum, episodeNam, secondsIntoProgramme separated by % symbols **
// thus, for, eg 4%Episde 3%1805
var noteKey = currentSeriesNum + "%" + currentEpisodeNam + "%" + postTimeAsInteger;
var noteProgrammeKey = currentSeriesNum + "%" + currentEpisodeNam;
var noteObject = { 'notekey': noteKey, 'noteprogrammekey': noteProgrammeKey, 'notetext': noteText, 'notetype': noteType };
// Add the note in a transaction so we can check everything works
const db = await idb.openDB('BaB', 1);
{
const tx = db.transaction('notes', 'readwrite');
try {
await Promise.all([
tx.store.put(noteObject), // only a single store in play, so "store" references this automatically
]);
} catch (e) {
alert(e);
return;
}
}
// add the note to the noteline - rather tedious as you have to build "the new child
// first as an empty <a> element, declare its innerhtml and then add its properties
if (noteType === "note") {
var noteInnerHTML = "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkblack.svg'></a>";
} else {
var noteInnerHTML = "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkred.svg'></a>";
}
var newNote = document.createElement("a"); // create a new <a> element
newNote.innerHTML = noteInnerHTML; // add some html to it
// now add properties to the <a> element as well
newNote.setAttribute("id", "n" + postTimeAsInteger);
newNote.setAttribute("title", noteText.substring(0, 15));
newNote.setAttribute("style", "position: absolute; margin-left: " + marginLeft + "px");
var onclickLink = "displayEditNotePanel('n" + postTimeAsInteger + "')";
newNote.setAttribute("onclick", onclickLink);
// and finally, add the new <a> element into the DOM as a child of the 'notes' div
document.getElementById('notes').appendChild(newNote);
// display an "OK" message in activitypanel
if (noteType === "note") {
var noteDisplayType = "Note";
} else {
var noteDisplayType = "Query";
}
var message = "<p style='margin-top:3vh; text-align: center; color: blue'><span>" + noteDisplayType + " saved</span></p>";
setActivityPanelToString(message);
// add the new note to the noteLeftMargins array and re-sort it
noteLeftMargins.push(marginLeft);
noteLeftMargins.sort(function (a, b) { return a - b });
}
function newNoteTooCloseToExisting(leftMargin) {
// checks that a propsed neew note will not be so close to an existing note that
// their notemarks will obscure one another - they need to be at least 1.25* noteWidth apart
var lastLeftMarginBefore = -1;
var firstLeftMarginAfter = -1;
for (var i = 0; i < noteLeftMargins.length; i++) {
var j = noteLeftMargins.length - i;
if (noteLeftMargins[i] < leftMargin) lastLeftMarginBefore = noteLeftMargins[i];
if (noteLeftMargins[j] > leftMargin) firstLeftMarginAfter = noteLeftMargins[j];
}
if (lastLeftMarginBefore == -1 && firstLeftMarginAfter == -1) return false;
if (lastLeftMarginBefore == -1 && (firstLeftMarginAfter - leftMargin) > .5 * noteWidth) return false;
if (firstLeftMarginAfter == -1 && (leftMargin - lastLeftMarginBefore) > .5 * noteWidth) return false;
if (((firstLeftMarginAfter - leftMargin) > 1.25) && ((leftMargin - lastLeftMarginBefore) > .5 * noteWidth)) return false;
return true;
}
async function displayEditNotePanel(noteId) {
var secondsIntoProgramme = parseInt(noteId.substring(1));
postTime = secondsIntoProgramme;
playBiteInEditPanel();
// retrieve the note from notestore
const db = await idb.openDB('BaB', 1);
var noteKey = currentSeriesNum + "%" + currentEpisodeNam + "%" + secondsIntoProgramme;
const noteObject = await db.get('notes', noteKey);
setActivityPanelToElement('editnotepanel');
document.getElementById('enotetext').value = noteObject.notetext;
document.getElementById('enotetext').focus();
document.getElementById('saveeditednotebutton').onclick = function () { editNote(noteId, noteObject.notetype) };
if (noteObject.notetype === "note") {
document.getElementById('changetoquerybutton').style.display = 'block';
document.getElementById('changetoquerybutton').onclick = function () { editNote(noteId, "query") };
document.getElementById('deletenotebutton').onclick = function () { deleteNote(noteId, "note") };
} else {
document.getElementById('changetonotebutton').style.display = 'block';
document.getElementById('changetonotebutton').onclick = function () { editNote(noteId, "note") };
document.getElementById('deletenotebutton').onclick = function () { deleteNote(noteId, "query") };
}
}
async function editNote(noteId, noteType) {
document.getElementById('saveeditednotebutton').style.background = 'initial';
// replace the text and type of the note at noteId for the current
// series and episode in the notes datastore
var noteText = document.getElementById('enotetext').value;
var secondsIntoProgramme = parseInt(noteId.substring(1));;
var noteKey = currentSeriesNum + "%" + currentEpisodeNam + "%" + secondsIntoProgramme;
var noteProgrammeKey = currentSeriesNum + "%" + currentEpisodeNam;
var noteObject = { 'notekey': noteKey, 'noteprogrammekey': noteProgrammeKey, 'notetext': noteText, 'notetype': noteType };
// Add the note in a transaction so we can check everything works
const db = await idb.openDB('BaB', 1);
{
const tx = db.transaction('notes', 'readwrite');
try {
await Promise.all([
tx.store.put(noteObject), // only a single store in play, so "store" references this automatically
]);
} catch (e) {
alert(e);
return;
}
}
// set the note icon note_type in case it has changed
if (noteType === "note") {
document.getElementById(noteId).innerHTML = "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkblack.svg'>";
document.getElementById('saveeditednotebutton').onclick = function () { editNote(noteId, "note") };
document.getElementById('changetoquerybutton').style.display = 'block';
document.getElementById('changetonotebutton').style.display = 'none';
document.getElementById('changetoquerybutton').onclick = function () { editNote(noteId, "query") };
} else {
document.getElementById(noteId).innerHTML = "<img class='notemark' src='https://ngatesystems.com/beagairbheag/img/notemarkred.svg'>";
document.getElementById('saveeditednotebutton').onclick = function () { editNote(noteId, "query") };
document.getElementById('changetonotebutton').style.display = 'block';
document.getElementById('changetoquerybutton').style.display = 'none';
document.getElementById('changetonotebutton').onclick = function () { editNote(noteId, "note") };
}
// ditto the title
var noteTextStub = document.getElementById('enotetext').value;
if (noteText.length > 15) noteTextStub = noteText.substring(0, 15) + ' ...';
document.getElementById(noteId).title = noteTextStub;
document.getElementById('deletenotebutton').onclick = function () { deleteNote(noteId) };
}
async function deleteNote(noteId, noteType) {
var secondsIntoProgramme = parseInt(noteId.substring(1));
var noteKey = currentSeriesNum + "%" + currentEpisodeNam + "%" + secondsIntoProgramme;
// Delete the note in a transaction so we can check everything works
const db = await idb.openDB('BaB', 1);
{
const tx = db.transaction('notes', 'readwrite');
try {
await Promise.all([