summaryrefslogtreecommitdiff
path: root/js/query_opts.js
blob: f81ee0c7298dd03b42a98f6b2e61d17bc3bfe59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const min_width = 20;
const rpad      = 15;

const tmp  = document.getElementById('js_tmp');
const opts = new Array(document.getElementById('sect'),
                       document.getElementById('arch'));

function fix_width(e)
{
    let style   = window.getComputedStyle(e, null);
    let font_sz = parseFloat(style.getPropertyValue('font-size'));

    tmp.style.fontSize = font_sz + "px";
    tmp.innerHTML      = e.options[e.selectedIndex].text;

    let tmp_width = parseFloat(window.getComputedStyle(tmp, null).width);
    let width     = (min_width + tmp_width + (tmp_width > 0 ? rpad : 0)) + "px";

    e.style.width = width;
}

for(let i=0; i < opts.length; i++)
{
    opts[i].addEventListener("change",  (ev) => { fix_width(opts[i]); });
    fix_width(opts[i]);
}