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