1 function appendsample() {
2 var rows = document.getElementsByClassName('glyphs')[0].rows;
3 for (var row of rows) {
4 // append sample column
5 var samplecol = row.getElementsByClassName('sample');
6 if (samplecol.length) {
7 samplecol = samplecol[0];
10 samplecol = row.appendChild(document.createElement('TD'));
11 samplecol.className = 'sample';
14 // prepare alphabet lookup table
15 cols = [ row.cells[0] ];
16 for (var col = 1; col <= samplecol.cellIndex; col++) {
17 var next = cols[col - 1].nextSibling;
18 if (next == samplecol) break;
20 for (var span = 1; span < cols[col].colSpan; span++) {
25 for (var col = 0; col < cols.length; col++) {
26 cols[col] = cols[col].innerHTML.trimRight();
29 // copy letters into sample
31 var input = this.value.toUpperCase();
32 for (var i = 0; i < input.length; i++) {
33 var col = input.charCodeAt(i) - 64;
34 if (col < 1) col = 27; // space
35 else if (cols[28] && i && col == input.charCodeAt(i - 1) - 64) {
36 col = 28; // repetition char
39 if (col < cols.length) {
40 output += '<span>' + (cols[col] || ' ') + '</span>';
46 if (cols[29] && !cols[28]) {
47 // circumfix sign if no repetition
48 output = cols[29] + output + cols[29];
50 samplecol.innerHTML = output;
54 function getrequest(name) {
55 // find GET variable in page request
56 var match = new RegExp('[?&]'+name+'=([^&]*)');
57 var param = match.exec(window.location.search);
58 return param ? decodeURIComponent(param[1]) : '';
61 function prependinput(target) {
62 var form = document.createElement('FORM');
64 form.className = 'aside';
65 form.onsubmit = function () { return false };
67 var input = document.createElement('INPUT');
68 input.oninput = appendsample;
69 input.placeholder = 'Sample';
70 input.type = 'search';
72 if (input.value = getrequest('q')) {
76 form.appendChild(input);
77 target.parentNode.insertBefore(form, target);