From ec3a771fdcdffec0f30d1970be536cf89e145ed1 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 21 Sep 2023 21:39:20 -0700 Subject: [PATCH] Page: Use OPTGROUP in SELECT --- index.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index d24f345..cdc602f 100644 --- a/index.html +++ b/index.html @@ -64,19 +64,24 @@ By Joshua Bell }) .then(text => { const select = document.querySelector('#lb_files'); + let group; text.split(/\r?\n/g).forEach(line => { line = line.replace(/^\s+|\s+$/, ''); if (!line.length) return; if (line.startsWith('#')) { line = line.replace(/^#\s+/, ''); - select.appendChild(Object.assign( - document.createElement('option'), - {disabled: true, innerText: line })); + if (line.startsWith('___')) { + select.appendChild(document.createElement('hr')); + } else { + group = Object.assign(document.createElement('optgroup'), + {label: line}); + select.appendChild(group); + } } else { const match = line.match(/^(\S+)\s+(.*)$/); - select.appendChild(Object.assign( + group.appendChild(Object.assign( document.createElement('option'), - {value: match[1], innerText: '\xA0\xA0' + match[2]})); + {value: match[1], innerText: match[2]})); } }); });