initial select-options setup...

This commit is contained in:
Marcell Mars 2021-04-13 01:46:33 +02:00
parent 085fe055ae
commit 82e429689a
1 changed files with 23 additions and 5 deletions

View File

@ -25,7 +25,16 @@
})
}
function generateFrontMatter(frontmatter, path, relpermalink, protocol) {
function couldHave(i, couldhave) {
couldhave.push(i)
let select = document.querySelector('select')
select.innerHTML = ""
couldhave.forEach((c)=> {
select.options[select.options.length] = new Option(c,c)
})
}
function generateFrontMatter(frontmatter, path, relpermalink, protocol, couldhave) {
let dvm = document.querySelector('form')
var hiddenRelPath = document.createElement('input')
@ -60,6 +69,7 @@
removeItem.setAttribute('type', 'button')
removeItem.addEventListener('click', (e) => {
e.target.parentNode.remove()
couldHave(e.target.parentNode.querySelector("input").value, couldhave)
disableButtons()
})
@ -69,7 +79,6 @@
moveUpItem.setAttribute('type', 'button')
moveUpItem.classList.add('buttonup')
moveUpItem.addEventListener('click', (e) => {
e.currentTarget.disabled = false;
let lb = document.querySelector(".listbox")
lb.insertBefore(e.currentTarget.parentNode, e.currentTarget.parentNode.previousSibling)
disableButtons()
@ -79,7 +88,6 @@
moveDownItem.setAttribute('type', 'button')
moveDownItem.classList.add('buttondown')
moveDownItem.addEventListener('click', (e) => {
e.currentTarget.disabled = false;
let lb = document.querySelector(".listbox")
let lblength = lb.children.length
lb.insertBefore(e.currentTarget.parentNode, e.currentTarget.parentNode.nextSibling.nextSibling)
@ -103,11 +111,21 @@
input.classList.add("hasinput")
input.title = "[remove on click]"
input.value = i
// input.addEventListener('focus', (e) => { e.target.parentNode.removeChild(e.target) })
let r = couldhave.indexOf(i)
if (r != -1) {
couldhave.splice(r, 1)
}
itemLine.prepend(input)
itemLine.prepend(removeItem)
listBox.prepend(itemLine)
})
let select = document.createElement('select')
couldhave.forEach((c)=> {
select.options[select.options.length] = new Option(c,c)
})
listBox.append(select)
dvm.prepend(listBox)
let label = document.createElement('label')
label.setAttribute('for', `${fm}[]`)
@ -148,7 +166,7 @@
}
path = repo.path;
console.log(JSON.stringify(repo))
generateFrontMatter(repo.frontmatter, path, repo.relpermalink, document.location.protocol.substring(0,4))
generateFrontMatter(repo.frontmatter, path, repo.relpermalink, document.location.protocol.substring(0,4), repo.couldhave)
}
el.src = `../js/repo/${location.hash.substring(1)}.js`
document.body.appendChild(el)