latin: custom space glyphs in sample
[sheet.git] / latinsample.js
index c17242ab08d6c6a13656462440874b71a6a1e435..cff51e38b9e295869fca2bde87eb49b0037509df 100644 (file)
@@ -1,14 +1,7 @@
 function appendsample() {
        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;
-                       }
-               }
+               // append sample column
                var samplecol = row.getElementsByClassName('sample');
                if (samplecol.length) {
                        samplecol = samplecol[0];
@@ -18,15 +11,29 @@ function appendsample() {
                        samplecol.className = 'sample';
                }
 
+               // prepare alphabet lookup table
+               cols = [ row.cells[0] ];
+               for (var col = 1; col <= samplecol.cellIndex; col++) {
+                       var next = cols[col - 1].nextSibling;
+                       if (next == samplecol) break;
+                       cols[col] = next;
+                       for (var span = 1; span < cols[col].colSpan; span++) {
+                               var same = cols[col];
+                               cols[++col] = same;
+                       }
+               }
+
+               // copy letters into sample
                var output = '';
                var input = this.value.toUpperCase();
                for (var i = 0; i < input.length; i++) {
                        var col = input.charCodeAt(i) - 64;
-                       if (col < 1 || col > 26) {
-                               output += ' &nbsp; ';
+                       if (col < 1) col = 27; // space
+                       if (col < cols.length) {
+                               output += '<span>' + cols[col].innerHTML.trimRight() + '</span>';
                        }
                        else {
-                               output += '<span>' + cols[col].innerHTML.trimRight() + '</span>';
+                               output += ' ';
                        }
                }
                samplecol.innerHTML = output;