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 (!this.value.length) {
7 row.removeChild(samplecol[0]);
10 if (samplecol.length) {
11 samplecol = samplecol[0];
14 samplecol = row.appendChild(document.createElement('TD'));
15 samplecol.className = 'sample';
18 // prepare alphabet lookup table
19 cols = [ row.cells[0] ];
20 for (var col = 1; col <= samplecol.cellIndex; col++) {
21 var next = cols[col - 1].nextSibling;
22 if (next == samplecol) break;
24 for (var span = 1; span < cols[col].colSpan; span++) {
29 for (var col = 0; col < cols.length; col++) {
30 cols[col] = cols[col].innerHTML.trimRight();
33 // copy letters into sample
35 var input = this.value.toUpperCase();
36 for (var i = 0; i < input.length; i++) {
37 var col = input.charCodeAt(i) - 64;
38 if (col < 1) col = 27; // space
39 else if (cols[28] && i && col == input.charCodeAt(i - 1) - 64) {
40 col = 28; // repetition char
43 if (col < cols.length) {
44 output += '<span>' + (cols[col] || ' ') + '</span>';
49 if (row.parentNode.tagName == 'THEAD') {
50 output += col < 26 ? ' ' : 'ยท '; // number separator
53 if (cols[29] && !cols[28]) {
54 // circumfix sign if no repetition
55 output = cols[29] + output + cols[29];
57 samplecol.innerHTML = output;
61 function getrequest(name) {
62 // find GET variable in page request
63 var match = new RegExp('[?&]'+name+'=([^&]*)');
64 var param = match.exec(window.location.search);
65 return param ? decodeURIComponent(param[1]) : '';
68 function prependinput(target) {
69 var form = document.createElement('FORM');
71 form.className = 'aside';
72 form.onsubmit = function () { return false };
74 var input = document.createElement('INPUT');
75 input.oninput = appendsample;
76 input.placeholder = 'Sample';
77 input.type = 'search';
79 if (input.value = getrequest('q')) {
83 form.appendChild(input);
84 target.parentNode.insertBefore(form, target);