mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2025-05-28 22:38:15 +00:00
Page: Use OPTGROUP in SELECT
This commit is contained in:
parent
aee6b4665f
commit
ec3a771fdc
15
index.html
15
index.html
@ -64,19 +64,24 @@ By <a target=_blank href="mailto:inexorabletash@gmail.com">Joshua Bell</a>
|
|||||||
})
|
})
|
||||||
.then(text => {
|
.then(text => {
|
||||||
const select = document.querySelector('#lb_files');
|
const select = document.querySelector('#lb_files');
|
||||||
|
let group;
|
||||||
text.split(/\r?\n/g).forEach(line => {
|
text.split(/\r?\n/g).forEach(line => {
|
||||||
line = line.replace(/^\s+|\s+$/, '');
|
line = line.replace(/^\s+|\s+$/, '');
|
||||||
if (!line.length) return;
|
if (!line.length) return;
|
||||||
if (line.startsWith('#')) {
|
if (line.startsWith('#')) {
|
||||||
line = line.replace(/^#\s+/, '');
|
line = line.replace(/^#\s+/, '');
|
||||||
select.appendChild(Object.assign(
|
if (line.startsWith('___')) {
|
||||||
document.createElement('option'),
|
select.appendChild(document.createElement('hr'));
|
||||||
{disabled: true, innerText: line }));
|
} else {
|
||||||
|
group = Object.assign(document.createElement('optgroup'),
|
||||||
|
{label: line});
|
||||||
|
select.appendChild(group);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const match = line.match(/^(\S+)\s+(.*)$/);
|
const match = line.match(/^(\S+)\s+(.*)$/);
|
||||||
select.appendChild(Object.assign(
|
group.appendChild(Object.assign(
|
||||||
document.createElement('option'),
|
document.createElement('option'),
|
||||||
{value: match[1], innerText: '\xA0\xA0' + match[2]}));
|
{value: match[1], innerText: match[2]}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user