X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/0de8fbee36cf18ea98dba85a7fc629db7e6ca769..9b34f6d9fa60d96025fe3835777f277b9cc002ad:/latinsample.js diff --git a/latinsample.js b/latinsample.js index c17242a..fa6b0f1 100644 --- a/latinsample.js +++ b/latinsample.js @@ -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,17 +11,42 @@ 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; + } + } + for (var col = 0; col < cols.length; col++) { + cols[col] = cols[col].innerHTML.trimRight(); + } + + // 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 += '   '; + if (col < 1) col = 27; // space + else if (cols[28] && i && col == input.charCodeAt(i - 1) - 64) { + col = 28; // repetition char + } + + if (col < cols.length) { + output += '' + (cols[col] || ' ') + ''; } else { - output += '' + cols[col].innerHTML.trimRight() + ''; + output += ' '; } } + if (cols[29] && !cols[28]) { + // circumfix sign if no repetition + output = cols[29] + output + cols[29]; + } samplecol.innerHTML = output; } };