From 82e429689acbc9e9b1f7ad2976b99c7eef2c3a2a Mon Sep 17 00:00:00 2001 From: Marcell Mars Date: Tue, 13 Apr 2021 01:46:33 +0200 Subject: [PATCH] initial select-options setup... --- src/App.svelte | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 261f2f9..1ef6339 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -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)