-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripts-local.html
790 lines (655 loc) · 18.2 KB
/
scripts-local.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
<script src="/scripts/scripts-common.js"></script>
{% include_relative listeners.html %}
{% include_relative templates.html %}
<script>
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Thu Mar 24 21:40:22 PDT 2016
// Last Modified: Sat Sep 22 11:34:46 PDT 2018
// Filename: tasso/scripts-local.html
// Web Address: https://www.tassomusic.org/scripts-local.html
// Syntax: JavaScript 1.8/ECMAScript 5
// vim: ts=3: ft=javascript
//
// Description: JavaScript management for the Tasso homepage.
//
var RWORKLIST = {};
////////////////////////////
//
// displayFrontPage --
//
function displayFrontPage() {
PrepareGlobalTassoObjects();
buildReverseWorklist();
let url = window.location.href;
if (url.match(/#gerusalemme/)) {
displayGerusalemmeList("#contents");
} else if (url.match(/#aminta/)) {
displayAmintaList("#contents");
} else if (url.match(/#rime/)) {
displayRimeList("#contents");
} else if (url.match(/#other/)) {
displayOtherList("#contents");
} else if (url.match(/#ecloghe/)) {
displayOtherList("#contents");
} else if (url.match(/#rinaldo/)) {
displayOtherList("#contents");
} else if (url.match(/#lagrime/)) {
displayOtherList("#contents");
} else if (url.match(/#torrismondo/)) {
displayOtherList("#contents");
} else if (url.match(/#conquistata/)) {
displayOtherList("#contents");
} else {
if (CGI && CGI.c) {
if (CGI.c === "gerusalemme") {
displayGerusalemmeList("#contents");
} else if (CGI.c === "aminta") {
displayAmintaList("#contents");
} else if (CGI.c === "other") {
displayOtherList("#contents");
} else {
displayRimeList("#contents");
}
} else {
displayRimeList("#contents");
}
}
}
//////////////////////////////
//
// displayRimeList -- Show the Rime list within the given
// target element.
//
function displayRimeList(target) {
if (!target) {
target = "#contents";
}
var element = document.querySelector(target);
if (!element) {
console.log("Error: cannot place Rime list on page.");
return;
}
window.location.hash = "rime";
continueProcessingRime(element);
}
//////////////////////////////
//
// displayAmintaList -- Show the Aminta list within the given
// target element.
//
function displayAmintaList(target) {
if (!target) {
target = "#contents";
}
var element = document.querySelector(target);
if (!element) {
console.log("Error: cannot place Aminta list on page.");
return;
}
window.location.hash = "aminta";
continueProcessingAminta(element);
}
//////////////////////////////
//
// displayOtherList -- Show the Other list within the given
// target element.
//
function displayOtherList(target) {
if (!target) {
target = "#contents";
}
var element = document.querySelector(target);
if (!element) {
console.log("Error: cannot place Other list on page.");
return;
}
window.location.hash = "other";
continueProcessingOther(element);
}
//////////////////////////////
//
// displayGerusalemmeList -- Show the Gerusalemme Liberata list within
// the given target element.
//
function displayGerusalemmeList(target) {
if (!target) {
target = "#contents";
}
var element = document.querySelector(target);
if (!element) {
console.log("Error: cannot place Gerusalemme list on page.");
return;
}
window.location.hash = "gerusalemme";
continueProcessingGL(element);
}
//////////////////////////////
//
// showTab --
//
function showTab(hiid) {
var rime = document.querySelector("#rime-heading");
var gl = document.querySelector("#gl-heading");
var aminta = document.querySelector("#aminta-heading");
var other = document.querySelector("#other-heading");
rime.className = hiid == "rime-heading" ? "active" : "";
gl.className = hiid == "gl-heading" ? "active" : "";
aminta.className = hiid == "aminta-heading" ? "active" : "";
other.className = hiid == "other-heading" ? "active" : "";
}
//////////////////////////////
//
// continueProcessingRime --
//
function continueProcessingRime(element) {
var tsource = document.querySelector("#rime-template")
.textContent;
var rimeTemplate = Handlebars.compile(tsource);
element.innerHTML = rimeTemplate(RIMEVERSELIST);
showTab("rime-heading");
}
//////////////////////////////
//
// continueProcessingGL --
//
function continueProcessingGL(element) {
var tsource = document.querySelector("#gerusalemme-template")
.textContent;
var gerusalemmeTemplate = Handlebars.compile(tsource);
var cantolist = makeCantoList(GERUSETTINGLIST);
element.innerHTML = gerusalemmeTemplate(cantolist);
showTab("gl-heading");
}
//////////////////////////////
//
// makeCantoList --
//
function makeCantoList(gllist) {
var output = {};
var data = output;
for (var i=0; i<gllist.length; i++) {
var key = gllist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].gtitle = gllist[i].TITLE;
data[key].canto = gllist[i].CANTO;
data[key].ottava = gllist[i].OTTAVA;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by Canto/Ottava
// as stored in catalog number.
return output;
}
//////////////////////////////
//
// makeConquistataList --
//
function makeConquistataList(gllist) {
var output = {};
var data = output;
if (!gllist.length) {
gllist = [gllist];
}
for (var i=0; i<gllist.length; i++) {
var key = gllist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].ctitle = gllist[i].TITLE;
data[key].canto = gllist[i].CANTO;
data[key].ottava = gllist[i].OTTAVA;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by Canto/Ottava
// as stored in catalog number.
return output;
}
/////////////////////////////
//
// makeEclogheList --
//
function makeEclogheList(elist) {
var output = {};
var data = output;
for (var i=0; i<elist.length; i++) {
var key = elist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].etitle = elist[i].TITLE;
data[key].ecloga = elist[i].ECLOGA;
data[key].verse = elist[i].VERSE;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by verse number.
// as stored in catalog number.
return output;
}
/////////////////////////////
//
// makeRinaldoList --
//
function makeRinaldoList(rlist) {
var output = {};
var data = output;
for (var i=0; i<rlist.length; i++) {
var key = rlist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].rtitle = rlist[i].TITLE;
data[key].canto = rlist[i].CANTO;
data[key].ottava = rlist[i].OTTAVA;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by verse number.
// as stored in catalog number.
return output;
}
/////////////////////////////
//
// makeLagrimeList --
//
function makeLagrimeList(lentry) {
// var llist = [lentry];
var llist = lentry;
var output = {};
var data = output;
for (var i=0; i<llist.length; i++) {
var key = llist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].ltitle = llist[i].TITLE;
data[key].stanza = llist[i].STANZA;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by verse number.
// as stored in catalog number.
return output;
}
/////////////////////////////
//
// makeTorrisomondoList --
//
function makeTorrismondoList(lentry) {
var llist = lentry;
// var llist = [lentry];
var output = {};
var data = output;
for (var i=0; i<llist.length; i++) {
var key = llist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].ttitle = llist[i].TITLE;
data[key].act = llist[i].ACT;
data[key].scene = llist[i].SCENE;
data[key].section = llist[i].SECTION;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by verse number.
// as stored in catalog number.
return output;
}
//////////////////////////////
//
// makeAmintaVerseList --
//
function makeAmintaVerseList(amlist) {
var output = {};
var data = output;
for (var i=0; i<amlist.length; i++) {
var key = amlist[i].CATALOGNUM.replace(/[a-z]$/, "");
data[key] = {};
data[key].atitle = amlist[i].TITLE;
data[key].act = amlist[i].ACT;
data[key].scene = amlist[i].SCENE;
data[key].verse = amlist[i].VERSE;
data[key].catalogbase = key;
}
// Should already be sorted, but maybe sort here by verse number.
// as stored in catalog number.
return output;
}
//////////////////////////////
//
// continueProcessingAminta --
//
function continueProcessingAminta(element) {
var tsource = document.querySelector("#aminta-template")
.textContent;
var amintaTemplate = Handlebars.compile(tsource);
var amintalist = makeAmintaVerseList(AMINTASETTINGLIST);
element.innerHTML = amintaTemplate(amintalist);
showTab("aminta-heading");
}
//////////////////////////////
//
// continueProcessingOther --
//
function continueProcessingOther(element) {
var csource = document.querySelector("#conquistata-template").textContent;
var esource = document.querySelector("#ecloghe-template").textContent;
var rsource = document.querySelector("#rinaldo-template").textContent;
var lsource = document.querySelector("#lagrime-template").textContent;
var tsource = document.querySelector("#torrismondo-template").textContent;
var conquistataTemplate = Handlebars.compile(csource);
var eclogheTemplate = Handlebars.compile(esource);
var rinaldoTemplate = Handlebars.compile(rsource);
var lagrimeTemplate = Handlebars.compile(lsource);
var torrismondoTemplate = Handlebars.compile(tsource);
var otherlist = OTHERSETTINGLIST;
var conquistatalist = [];
var ecloghelist = [];
var rinaldolist = [];
var lagrimelist = [];
var torrismondolist = [];
for (var k=0; k<OTHERSETTINGLIST.length; k++) {
if (!OTHERSETTINGLIST[k].GROUP) {
console.log("PROBLEM WITH SETTING", OTHERSETTINGLIST[k]);
continue;
}
if (OTHERSETTINGLIST[k].GROUP.match(/conquistata/i)) {
// @GROUP: Gerusalemme conquistata
conquistatalist.push(OTHERSETTINGLIST[k]);
}
else if (OTHERSETTINGLIST[k].GROUP.match(/ecloghe/i)) {
// @GROUP: Ecloghe settings
ecloghelist.push(OTHERSETTINGLIST[k]);
}
else if (OTHERSETTINGLIST[k].GROUP.match(/rinaldo/i)) {
// @GROUP: Rinaldo settings
rinaldolist.push(OTHERSETTINGLIST[k]);
}
else if (OTHERSETTINGLIST[k].GROUP.match(/lagrime/i)) {
// @GROUP: Lagrime della Beata Vergine settings
lagrimelist.push(OTHERSETTINGLIST[k]);
}
else if (OTHERSETTINGLIST[k].GROUP.match(/torrismondo/i)) {
// @GROUP: Re Torrismondo settings
torrismondolist.push(OTHERSETTINGLIST[k]);
}
}
conquistatalist = makeConquistataList(conquistatalist);
ecloghelist = makeEclogheList(ecloghelist);
rinaldolist = makeRinaldoList(rinaldolist);
lagrimelist = makeLagrimeList(lagrimelist);
torrismondolist = makeTorrismondoList(torrismondolist);
var output = "";
output += '<div style="text-align:center; color:#bbb; font-style: italic;">';
output += 'N.B.: dark text indicates editions of one or more musical settings are now available.';
output += '</div>';
output = "";
output += "<h2 style='margin-left:100px'>Ecloghe</h2>";
output += eclogheTemplate(ecloghelist);
output += "<h2 style='margin-top:-80px; margin-left:100px'>Rinaldo</h2>";
output += rinaldoTemplate(rinaldolist);
output += "<h2 style='margin-top:-80px; margin-left:100px'>Lagrime della Beata Vergine</h2>";
output += lagrimeTemplate(lagrimelist);
output += "<h2 style='margin-top:-80px; margin-left:100px'>Re Torrismondo</h2>";
output += torrismondoTemplate(torrismondolist);
output += "<h2 style='margin-top:-80px; margin-left:100px'>Gerusalemme conquistata</h2>";
output += conquistataTemplate(conquistatalist);
element.innerHTML = output;
showTab("other-heading");
}
//////////////////////////////
//
// buildReveseWorklist --
//
function buildReverseWorklist() {
console.log("BUILDING REVERSE WORKLIST");
RWORKLIST = {};
var wl = TASSODATA.SCORES.SCOREDATA;
var rime;
for (var i in wl) {
if (!RWORKLIST[wl[i].CATALOGNUM]) {
RWORKLIST[wl[i].CATALOGNUM] = 0;
}
RWORKLIST[wl[i].CATALOGNUM] += 1;
rime = wl[i].CATALOGNUM.replace(/[a-z]+$/, "");
if (!RWORKLIST[rime]) {
RWORKLIST[rime] = 0;
}
RWORKLIST[rime] += 1;
}
}
//
// Old function used worklist.json, which is being retired:
//
function buildReverseWorklistOld() {
RWORKLIST = {};
var wl = WORKLIST[0].works;
var rime;
for (var i in wl) {
if (!RWORKLIST[wl[i].id]) {
RWORKLIST[wl[i].id] = 0;
}
RWORKLIST[wl[i].id] += 1;
rime = wl[i].id.replace(/[a-z]+$/, "");
if (!RWORKLIST[rime]) {
RWORKLIST[rime] = 0;
}
RWORKLIST[rime] += 1;
}
}
//////////////////////////////
//
// show --
//
function show(element) {
var item = element.querySelector("table");
item.style.visibility = "visible";
}
//////////////////////////////
//
// hide --
//
function hide(element) {
var item = element.querySelector("table");
item.style.visibility = "hidden";
}
//////////////////////////////
//
// sortByText --
//
function sortByText(index) {
var data = document.querySelectorAll(".data");
var datalist = [];
var i;
for (i=0; i<data.length; i++) {
datalist.push(data[i]);
}
datalist.sort(function(a, b) {
var A = a.cells[index].textContent.replace(/["']/g, "");
var B = b.cells[index].textContent.replace(/["']/g, "");
var result = A.localeCompare(B);
return result;
});
var body = document.querySelector("table.poem-list tbody");
body.innerHTML = "";
for (i=0; i<datalist.length; i++) {
body.appendChild(datalist[i]);
}
}
//////////////////////////////
//
// sortByGenre --
//
function sortByGenre(index) {
var data = document.querySelectorAll(".data");
var datalist = [];
var i;
for (i=0; i<data.length; i++) {
datalist.push(data[i]);
}
datalist.sort(function(a, b) {
var A = a.cells[index].querySelector(".genre").textContent.replace(/["']/g, "");
var B = b.cells[index].querySelector(".genre").textContent.replace(/["']/g, "");
var result = A.localeCompare(B);
return result;
});
var body = document.querySelector("table.poem-list tbody");
body.innerHTML = "";
for (i=0; i<datalist.length; i++) {
body.appendChild(datalist[i]);
}
}
//////////////////////////////
//
// sortByCantoOttava -- Used in the Gerusalemme tab
//
function sortByCantoOttava() {
var index = 0;
var data = document.querySelectorAll(".data");
var datalist = [];
var i;
for (i=0; i<data.length; i++) {
datalist.push(data[i]);
}
datalist.sort(function(a, b) {
var A = a.cells[index].textContent.trim().replace(/\s+/g, " ");
var B = b.cells[index].textContent.trim().replace(/\s+/g, " ");
var Aroman;
var Aindic;
var Broman;
var Bindic;
var matches = A.match(/^([XVI]+)\s*([\d]+)/);
if (matches) {
Aroman = convertToIndic(matches[1]);
Aindic = parseInt(matches[2]);
} else {
Aroman = 9999;
Aindic = 9999;
}
matches = B.match(/^([XVI]+)\s*([\d]+)/);
if (matches) {
Broman = convertToIndic(matches[1]);
Bindic = parseInt(matches[2]);
} else {
Broman = 9999;
Bindic = 9999;
}
if (Aroman < Broman) { return -1 }
if (Aroman > Broman) { return +1 }
if (Aindic < Bindic) { return -1 }
if (Aindic > Bindic) { return +1 }
return 0;
});
var body = document.querySelector("table.poem-list tbody");
body.innerHTML = "";
for (i=0; i<datalist.length; i++) {
body.appendChild(datalist[i]);
}
}
//////////////////////////////
//
// sortByActSceneVerse -- Used on the Aminta tab.
//
function sortByActSceneVerse() {
var index = 0;
var data = document.querySelectorAll(".data");
var datalist = [];
var i;
for (i=0; i<data.length; i++) {
datalist.push(data[i]);
}
datalist.sort(function(a, b) {
var A = a.cells[index].textContent.trim().replace(/\s+/g, " ");
var B = b.cells[index].textContent.trim().replace(/\s+/g, " ");
var Aact;
var Ascene;
var Averse;
var Bact;
var Bscene;
var Bverse;
var matches = A.match(/^([XVI]+)\s*(\d+)\s+(\d+)/);
if (matches) {
Aact = convertToIndic(matches[1]);
Ascene = parseInt(matches[2]);
Averse = parseInt(matches[3]);
} else {
Aact = 9999;
Ascene = 9999;
Averse = 9999;
}
matches = B.match(/^([XVI]+)\s*(\d+)\s+(\d+)/);
if (matches) {
Bact = convertToIndic(matches[1]);
Bscene = parseInt(matches[2]);
Bverse = parseInt(matches[3]);
} else {
Bact = 9999;
Bscene = 9999;
Bverse = 9999;
}
if (Aact < Bact) { return -1 }
if (Aact > Bact) { return +1 }
if (Ascene < Bscene) { return -1 }
if (Ascene > Bscene) { return +1 }
if (Averse < Bverse) { return -1 }
if (Averse > Bverse) { return +1 }
return 0;
});
var body = document.querySelector("table.poem-list tbody");
body.innerHTML = "";
for (i=0; i<datalist.length; i++) {
body.appendChild(datalist[i]);
}
}
//////////////////////////////
//
// convertToIndic -- Roman number to indic. Using simple algorithm for now.
// Uppercase presumed.
//
function convertToIndic(value) {
if (value === "I") { return 1; }
if (value === "II") { return 2; }
if (value === "III") { return 3; }
if (value === "IV") { return 4; }
if (value === "V") { return 5; }
if (value === "VI") { return 6; }
if (value === "VII") { return 7; }
if (value === "VIII") { return 8; }
if (value === "IX") { return 9; }
if (value === "X") { return 10; }
if (value === "XI") { return 11; }
if (value === "XII") { return 12; }
if (value === "XIII") { return 13; }
if (value === "XIV") { return 14; }
if (value === "XV") { return 15; }
if (value === "XVI") { return 16; }
if (value === "XVII") { return 17; }
if (value === "XVIII") { return 18; }
if (value === "XIX") { return 19; }
if (value === "XX") { return 20; }
}
//////////////////////////////
//
// sortByNumber --
//
function sortByNumber(index) {
console.log("SORTING BY NUMBER", index);
var data = document.querySelectorAll(".data");
var datalist = [];
var i;
for (i=0; i<data.length; i++) {
datalist.push(data[i]);
}
datalist.sort(function(a, b) {
var A = a.cells[index].textContent.replace(/[^NSM\d]/g, "");
var B = b.cells[index].textContent.replace(/[^NSM\d]/g, "");
if (A.match(/NSM/)) {
A = 99999;
} else if (!A) {
A = 0;
}
if (B.match(/NSM/)) {
B = 99999;
} else if (!B) {
B = 0;
}
A = parseInt(A);
B = parseInt(B);
if (A < B) { return -1 }
else if (A > B) { return +1 }
else { return 0 }
});
var body = document.querySelector("table.poem-list tbody");
body.innerHTML = "";
for (i=0; i<datalist.length; i++) {
body.appendChild(datalist[i]);
}
}
</script>