remove and sort order buttons
This commit is contained in:
parent
4fccb7c4ae
commit
085fe055ae
|
@ -3,6 +3,28 @@
|
|||
let v = "loading...";
|
||||
let path = "loading...";
|
||||
|
||||
function disableButtons() {
|
||||
let listbox = [...document.querySelector(".listbox").children]
|
||||
let buttonUps = document.querySelectorAll(".buttonup")
|
||||
let buttonDowns = document.querySelectorAll(".buttondown")
|
||||
|
||||
buttonUps.forEach((up)=>{
|
||||
if (listbox.indexOf(up.parentNode) == 0) {
|
||||
up.disabled = true;
|
||||
} else {
|
||||
up.disabled = false;
|
||||
}
|
||||
})
|
||||
|
||||
buttonDowns.forEach((down)=> {
|
||||
if (listbox.indexOf(down.parentNode) == (listbox.length -1)) {
|
||||
down.disabled = true;
|
||||
} else {
|
||||
down.disabled = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function generateFrontMatter(frontmatter, path, relpermalink, protocol) {
|
||||
let dvm = document.querySelector('form')
|
||||
|
||||
|
@ -23,7 +45,7 @@
|
|||
hiddenProtocol.setAttribute('name', 'protocol')
|
||||
hiddenProtocol.value = protocol
|
||||
dvm.prepend(hiddenProtocol)
|
||||
|
||||
var c = 0;
|
||||
Object.keys(frontmatter).forEach((fm)=>{
|
||||
if (Array.isArray(frontmatter[fm])) {
|
||||
console.log("Array:", frontmatter[fm])
|
||||
|
@ -36,24 +58,43 @@
|
|||
let moveUpItem = document.createElement('button')
|
||||
let moveDownItem = document.createElement('button')
|
||||
removeItem.setAttribute('type', 'button')
|
||||
removeItem.addEventListener('click', (e) => { e.target.parentNode.remove() })
|
||||
removeItem.addEventListener('click', (e) => {
|
||||
e.target.parentNode.remove()
|
||||
disableButtons()
|
||||
})
|
||||
|
||||
removeItem.textContent = "×"
|
||||
|
||||
moveUpItem.textContent = "⇑"
|
||||
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 )
|
||||
lb.insertBefore(e.currentTarget.parentNode, e.currentTarget.parentNode.previousSibling)
|
||||
disableButtons()
|
||||
})
|
||||
|
||||
moveDownItem.textContent = "⇓"
|
||||
moveDownItem.setAttribute('type', 'button')
|
||||
moveDownItem.classList.add('buttondown')
|
||||
moveDownItem.addEventListener('click', (e) => {
|
||||
e.currentTarget.disabled = false;
|
||||
let lb = document.querySelector(".listbox")
|
||||
lb.insertBefore(e.currentTarget.parentNode, e.currentTarget.parentNode.nextSibling.nextSibling )
|
||||
let lblength = lb.children.length
|
||||
lb.insertBefore(e.currentTarget.parentNode, e.currentTarget.parentNode.nextSibling.nextSibling)
|
||||
disableButtons()
|
||||
})
|
||||
|
||||
if (c==0) {
|
||||
moveDownItem.disabled = true;
|
||||
}
|
||||
|
||||
if ((c+1) == frontmatter[fm].length) {
|
||||
moveUpItem.disabled = true;
|
||||
}
|
||||
c++
|
||||
|
||||
itemLine.prepend(moveUpItem)
|
||||
itemLine.prepend(moveDownItem)
|
||||
var input = document.createElement('input')
|
||||
|
|
Loading…
Reference in New Issue