Skip to content

Commit

Permalink
JavaScript backbone for GABC chant display
Browse files Browse the repository at this point in the history
Enabling DivinumOfficium#1375  (GABC files are not retrieved from GregoBase though)
  • Loading branch information
FAJ-Munich committed Mar 28, 2024
1 parent 9413c42 commit 7b85cd0
Show file tree
Hide file tree
Showing 7 changed files with 10,970 additions and 145 deletions.
305 changes: 187 additions & 118 deletions web/cgi-bin/horas/horasjs.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#*** Javascript functions
# the sub is called from htmlhead
sub horasjs {

my($output);
# $caller in principle might not be defined.
my $caller_flag = $caller || 0;
Expand All @@ -16,70 +15,70 @@ sub horasjs {
var day = d.getDate();
document.forms[0].browsertime.value = (d.getMonth() + 1) + "-" + day + "-" + d.getFullYear();
if (!"$date1") {
var a = (day > $day) ? "-+" : (day < $day) ? "--" : "";
document.forms[0].date.value = document.forms[0].browsertime.value + a;
if (a) document.forms[0].submit();
}
}
var i = 1;
while (i <= $searchvalue) {
var a = (day > $day) ? "-+" : (day < $day) ? "--" : "";
document.forms[0].date.value = document.forms[0].browsertime.value + a;
if (a) document.forms[0].submit();
}
}
var i = 1;
while (i <= $searchvalue) {
a = document.getElementById('L' + i);
i++;
if (a) a.scrollIntoView();
}
}

//call a setup table
function pset(p) {
var pc = document.createElement("input");
pc.setAttribute("type", "hidden");
pc.setAttribute("name", "pcommand");
pc.setAttribute("value", "pray" + document.forms[0].command.value);
document.forms[0].appendChild(pc);
document.forms[0].command.value = "setup" + p;
document.forms[0].submit();
}

//call an individual hora
function hset(p, d) {
clearradio();

if (p != 'Laudes' && d) {
}
}
//call a setup table
function pset(p) {
var pc = document.createElement("input");
pc.setAttribute("type", "hidden");
pc.setAttribute("name", "pcommand");
pc.setAttribute("value", "pray" + document.forms[0].command.value);
document.forms[0].appendChild(pc);
document.forms[0].command.value = "setup" + p;
document.forms[0].submit();
}
//call an individual hora
function hset(p, d) {
clearradio();
if (p != 'Laudes' && d) {
document.forms[0].date.value = d;
document.forms[0].caller.value = 1;
}
if ($caller_flag) {document.forms[0].caller.value = 1;}
document.forms[0].command.value = "pray" + p;
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
document.forms[0].submit();
}

// call appendix
function appendix(a) {
document.forms[0].command.value = "Appendix " + a;
console.log(document.forms[0].command.value);
document.forms[0].submit();
}

// Jump straight to an hour of the Office for the Dead.
function defunctorum(hour) {
clearradio();

document.forms[0].caller.value = 1;
document.forms[0].votive.value = "C9";
document.forms[0].command.value = "pray" + hour;
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
document.forms[0].submit();
}

//calls compare
function callcompare() {
document.forms[0].action = "Cofficium.pl";
document.forms[0].target = "_self"
document.forms[0].submit();
}
}
if ($caller_flag) {document.forms[0].caller.value = 1;}
document.forms[0].command.value = "pray" + p;
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
document.forms[0].submit();
}
// call appendix
function appendix(a) {
document.forms[0].command.value = "Appendix " + a;
console.log(document.forms[0].command.value);
document.forms[0].submit();
}
// Jump straight to an hour of the Office for the Dead.
function defunctorum(hour) {
clearradio();
document.forms[0].caller.value = 1;
document.forms[0].votive.value = "C9";
document.forms[0].command.value = "pray" + hour;
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
document.forms[0].submit();
}
//calls compare
function callcompare() {
document.forms[0].action = "Cofficium.pl";
document.forms[0].target = "_self"
document.forms[0].submit();
}
PrintTag
}
$output .= << "PrintTag";
Expand All @@ -90,93 +89,163 @@ sub horasjs {
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
return;
}
// set a popup tab
function linkit(name,ind,lang) {
}
// set a popup tab
function linkit(name,ind,lang) {
document.forms[0].popup.value = name;
document.forms[0].popuplang.value=lang;
document.forms[0].expandnum.value=ind;
if (ind == 0) {
document.forms[0].action = 'popup.pl';
document.forms[0].target = '_BLANK';
} else {
var c = document.forms[0].command.value;
if (!c.match('pray')) document.forms[0].command.value = "pray" + c;
}
document.forms[0].action = 'popup.pl';
document.forms[0].target = '_BLANK';
} else {
var c = document.forms[0].command.value;
if (!c.match('pray')) document.forms[0].command.value = "pray" + c;
}
document.forms[0].submit();
}
//finishing horas back to main page
function okbutton() {
}
//finishing horas back to main page
function okbutton() {
document.forms[0].action = "$officium";
document.forms[0].target = "_self"
document.forms[0].command.value = '';
document.forms[0].submit();
}
//restart the programlet if parameter change
function parchange() {
var c = document.forms[0].command.value;
if (c && !c.match("change")) {
clearradio();
}
if (c && !c.match("pray")) document.forms[0].command.value = "pray" + c;
document.forms[0].submit();
}
//calls kalendar
function callkalendar() {
document.forms[0].action = 'kalendar.pl';
document.forms[0].target = "_self"
document.forms[0].submit();
}
// for Cofficium
function callbrevi(date) {
document.forms[0].date.value = date;
document.forms[0].action = 'officium.pl'
document.forms[0].target = "_self"
document.forms[0].submit();
}
//calls missa
function callmissa() {
document.forms[0].action = "../missa/missa.pl";
document.forms[0].target = "_self"
document.forms[0].submit();
}
function prevnext(ch) {
}
//restart the programlet if parameter change
function parchange() {
var c = document.forms[0].command.value;
if (c && !c.match("change")) {
clearradio();
}
if (c && !c.match("pray")) document.forms[0].command.value = "pray" + c;
document.forms[0].submit();
}
//calls kalendar
function callkalendar() {
document.forms[0].action = 'kalendar.pl';
document.forms[0].target = "_self"
document.forms[0].submit();
}
// for Cofficium
function callbrevi(date) {
document.forms[0].date.value = date;
document.forms[0].action = 'officium.pl'
document.forms[0].target = "_self"
document.forms[0].submit();
}
//calls missa
function callmissa() {
document.forms[0].action = "../missa/missa.pl";
document.forms[0].target = "_self"
document.forms[0].submit();
}
function prevnext(ch) {
var dat = document.forms[0].date.value;
var adat = dat.split('-');
var mtab = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var m = eval(adat[0]);
var d = eval(adat[1]);
var y = eval(adat[2]);
var c = eval(ch);
var leapyear = 0;
if ((y % 4) == 0) leapyear = 1;
if ((y % 100) == 0) leapyear = 0;
if ((y % 400) == 0) leapyear = 1;
if (leapyear) mtab[1] = 29;
d = d + c;
if (d < 1) {
m--;
if (m < 1) {y--; m = 12;}
d = mtab[m-1];
}
m--;
if (m < 1) {y--; m = 12;}
d = mtab[m-1];
}
if (d > mtab[m-1]) {
m++;
d = 1;
if (m > 12) {y++; m = 1;}
}
m++;
d = 1;
if (m > 12) {y++; m = 1;}
}
document.forms[0].date.value = m + "-" + d + "-" + y;
}
PrintTag

$output
}

#to convert gabc into chant svg
sub horasjsend {

print "\n<SCRIPT TYPE='text/JavaScript'>\n";
# $caller in principle might not be defined.
my $caller_flag = $caller || 0;

print << "PrintTag";



var ctxt = new exsurge.ChantContext();
ctxt.lyricTextFont = "'Crimson Text', serif";
ctxt.lyricTextSize *= 1.2;
ctxt.dropCapTextFont = ctxt.lyricTextFont;
ctxt.annotationTextFont = ctxt.lyricTextFont;

const scores = [];
var gabcSources = [];
var chantContainers = [];

\$('.GABC').each(function(gabcidx, gabcSource) {
gabcSources.push(gabcSource);
chantContainer = document.getElementById(gabcSource.id.replace("GABC", "GCHANT"));
chantContainers.push(chantContainer);
});

var updateChant = function() {
if (scores.length) {
for (let i = 0; i < scores.length; i++) {
exsurge.Gabc.updateMappingsFromSource(ctxt, scores[i].mappings, gabcSources[i].innerHTML);
scores[i].updateNotations(ctxt);
}
} else {
for (let i = 0; i < gabcSources.length; i++) {
header = getHeader(gabcSources[i].innerHTML);
mappings = exsurge.Gabc.createMappingsFromSource(ctxt, gabcSources[i].innerHTML);
let score = new exsurge.ChantScore(ctxt, mappings, header['initial-style']!=='0');
if(header['initial-style']!=='0' && header.annotation) {
score.annotation = new exsurge.Annotation(ctxt, header.annotation);
}
scores.push(score);
};
}
layoutChant();
};

var layoutChant = function() {
for (let i = 0; i < chantContainers.length; i++) {
// perform layout on the chant
if(scores.length) {
scores[i].performLayoutAsync(ctxt, function() {
scores[i].layoutChantLines(ctxt, chantContainers[i].clientWidth, function() {
// render the score to svg code
chantContainers[i].innerHTML = scores[i].createSvg(ctxt);
});
});
gabcSources[i].style.display = 'none';
}
}
};

updateChant();


\$("body").on("resize", layoutChant());
</SCRIPT>
PrintTag
}

1;
Loading

0 comments on commit 7b85cd0

Please sign in to comment.