latin: dynamic sample of user input
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 2 Apr 2017 23:21:54 +0000 (01:21 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 23:51:40 +0000 (01:51 +0200)
Experimental feature to concatenate given letters in all rows.
Rough comparison of actual usage (though without any specific script
features, kerning, or other exceptions).

latin.plp

index 70c9635..a801e68 100644 (file)
--- a/latin.plp
+++ b/latin.plp
@@ -34,7 +34,7 @@ Html({
                stroke-linecap: round;
                stroke-linejoin: round;
        }
-       #code-39 {
+       td {
                white-space: nowrap;
        }
 
@@ -94,3 +94,45 @@ else {
 
 :></div>
 
+<script>
+var inputel = document.createElement('INPUT');
+inputel.oninput = function () {
+       var rows = document.getElementsByClassName('glyphs')[0].rows;
+       for (var row of rows) {
+               cols = [ row.cells[0] ];
+               for (var col = 1; col <= 26; col++) {
+                       cols[col] = cols[ col - 1 ].nextSibling;
+                       for (var span = 1; span < cols[col].colSpan; span++) {
+                               var same = cols[col];
+                               cols[++col] = same;
+                       }
+               }
+               var samplecol = row.getElementsByClassName('sample');
+               if (samplecol.length) {
+                       samplecol = samplecol[0];
+               }
+               else {
+                       samplecol = row.appendChild(document.createElement('TD'));
+                       samplecol.className = 'sample';
+               }
+
+               var output = '';
+               var input = inputel.value.toUpperCase();
+               for (var i = 0; i < input.length; i++) {
+                       var col = input.charCodeAt(i) - 64;
+                       if (col < 1 || col > 26) {
+                               output += ' &nbsp; ';
+                       }
+                       else {
+                               output += cols[col].innerHTML.trimRight();
+                       }
+               }
+               samplecol.innerHTML = output;
+       }
+};
+
+var container = document.createElement('P');
+container.appendChild(inputel);
+document.body.appendChild(container);
+
+</script>