diff options
Diffstat (limited to 'js/query_opts.js')
-rw-r--r-- | js/query_opts.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/js/query_opts.js b/js/query_opts.js new file mode 100644 index 0000000..f81ee0c --- /dev/null +++ b/js/query_opts.js @@ -0,0 +1,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]); +} + |